Handle GUI timezone vs backend timezone in interface historical data

This commit is contained in:
Alfredo Cardigliano 2020-02-24 16:55:18 +01:00
parent e6d615ed91
commit 703b96cf8f
5 changed files with 25 additions and 9 deletions

View file

@ -179,24 +179,27 @@ function format_utils.bitsToSize(bits)
return(bitsToSizeMultiplier(bits, 1000))
end
function format_utils.formatEpoch(epoch)
-- format an epoch
-- timezone is the frontend timezone offset in seconds (optional)
function format_utils.formatEpoch(epoch, timezone)
if epoch == 0 then
return("")
else
return(os.date("%d/%m/%Y %X", epoch))
return(os.date("%d/%m/%Y %X", epoch + getFrontendTzDeltaSeconds(timezone)))
end
end
-- shorten an epoch when there is a well defined interval
function format_utils.formatEpochShort(epoch_begin, epoch_end, epoch)
local begin_day = os.date("%d", epoch_begin)
local end_day = os.date("%d", epoch_end)
-- timezone is the frontend timezone offset in seconds (optional)
function format_utils.formatEpochShort(epoch_begin, epoch_end, epoch, timezone)
local begin_day = os.date("%d", epoch_begin + getFrontendTzDeltaSeconds(timezone))
local end_day = os.date("%d", epoch_end + getFrontendTzDeltaSeconds(timezone))
if begin_day == end_day then
return os.date("%X", epoch)
return os.date("%X", epoch + getFrontendTzDeltaSeconds(timezone))
end
return format_utils.formatEpoch(epoch)
return format_utils.formatEpoch(epoch, timezone)
end
function format_utils.formatPastEpochShort(epoch)

View file

@ -2621,6 +2621,7 @@ end
-- ####################################################
-- Get the local (backend) timezone offset in seconds
function getTzOffsetSeconds()
local now = os.time()
local local_t = os.date("*t", now)
@ -2645,6 +2646,17 @@ end
-- ####################################################
-- Get the delta between the frontend local time and the backend local time in seconds
function getFrontendTzDeltaSeconds(frontend_tz_offset)
if frontend_tz_offset == nil then
return 0
end
return frontend_tz_offset - getTzOffsetSeconds()
end
-- ####################################################
-- Converts a string (with the timezone offset) into an epoch
function makeTimeStamp(d, tzoffset)
-- tzoffset is the timezone difference between UTC and Local Time in the browser
local pattern = "(%d+)%/(%d+)%/(%d+) (%d+):(%d+):(%d+)"