Cleanup format_utils.formatPastEpochShort

This commit is contained in:
Alfredo Cardigliano 2022-03-09 10:24:53 +01:00
parent 0fd90864bf
commit 5cc5ee1665
2 changed files with 9 additions and 12 deletions

View file

@ -245,22 +245,19 @@ function format_utils.formatEpoch(epoch, full_time)
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 or os.time()) + getFrontendTzSeconds())
local end_day = os.date("!%d", (epoch_end or os.time()) + getFrontendTzSeconds())
function format_utils.formatPastEpochShort(input_epoch)
local epoch_now = os.time()
local epoch = input_epoch or epoch_now
local day = os.date("!%d", epoch + getFrontendTzSeconds())
local day_now = os.date("!%d", epoch_now + getFrontendTzSeconds())
if begin_day == end_day then
return os.date("!%X", (epoch or os.time()) + getFrontendTzSeconds())
if day == day_now then
return os.date("!%X", epoch + getFrontendTzSeconds())
end
return format_utils.formatEpoch(epoch)
end
function format_utils.formatPastEpochShort(epoch)
return format_utils.formatEpochShort(epoch, os.time(), epoch)
end
-- See also format_utils.msToTime
function format_utils.formatMillis(x)
if(x == 0) then return 0 end