When displaying a *date* (as opposed to a *time*), pad the hour with

blanks if necessary in order to get a consistent alignment.

Fix #7316
pull/7323/head
NiLuJe 3 years ago committed by Frans de Jonge
parent 588acfe31e
commit 572900bfff

@ -244,18 +244,33 @@ if jit.os == "Windows" then
end end
end end
else else
function util.secondsToHour(seconds, twelve_hour_clock) function util.secondsToHour(seconds, twelve_hour_clock, pad_with_spaces)
if twelve_hour_clock then if twelve_hour_clock then
if os.date("%p", seconds) == "AM" then if os.date("%p", seconds) == "AM" then
-- @translators This is the time in the morning using a 12-hour clock (%-I is the hour, %M the minute). if pad_with_spaces then
return os.date(_("%-I:%M AM"), seconds) -- @translators This is the time in the morning using a 12-hour clock (%_I is the hour, %M the minute).
return os.date(_("%_I:%M AM"), seconds)
else
-- @translators This is the time in the morning using a 12-hour clock (%-I is the hour, %M the minute).
return os.date(_("%-I:%M AM"), seconds)
end
else else
-- @translators This is the time in the afternoon using a 12-hour clock (%-I is the hour, %M the minute). if pad_with_spaces then
return os.date(_("%-I:%M PM"), seconds) -- @translators This is the time in the afternoon using a 12-hour clock (%_I is the hour, %M the minute).
return os.date(_("%_I:%M PM"), seconds)
else
-- @translators This is the time in the afternoon using a 12-hour clock (%-I is the hour, %M the minute).
return os.date(_("%-I:%M PM"), seconds)
end
end end
else else
-- @translators This is the time using a 24-hour clock (%-H is the hour, %M the minute). if pad_with_spaces then
return os.date(_("%-H:%M"), seconds) -- @translators This is the time using a 24-hour clock (%_H is the hour, %M the minute).
return os.date(_("%_H:%M"), seconds)
else
-- @translators This is the time using a 24-hour clock (%-H is the hour, %M the minute).
return os.date(_("%-H:%M"), seconds)
end
end end
end end
end end
@ -266,7 +281,8 @@ end
---- @treturn string date string ---- @treturn string date string
function util.secondsToDate(seconds, twelve_hour_clock) function util.secondsToDate(seconds, twelve_hour_clock)
local BD = require("ui/bidi") local BD = require("ui/bidi")
local time = util.secondsToHour(seconds, twelve_hour_clock) -- In order to keep stuff aligned, we'll want to *keep* the padding, but using blanks instead of zeroes.
local time = util.secondsToHour(seconds, twelve_hour_clock, true)
-- @translators This is the date (%Y is the year, %m the month, %d the day) -- @translators This is the date (%Y is the year, %m the month, %d the day)
local day = os.date(_("%Y-%m-%d"), seconds) local day = os.date(_("%Y-%m-%d"), seconds)
return BD.wrap(day) .. " " .. BD.wrap(time) return BD.wrap(day) .. " " .. BD.wrap(time)

Loading…
Cancel
Save