ReaderFooter: Don't duplicate a 12h clock time format option (#6973)

* ReaderFooter:
	* Honor the global twelve_hour_clock setting, instead of
	  duplicating a local one.
	  (Re #6969)

* os.date is a thin wrapper around strftime, so we might be able to get
away with some not-quite-standard extensions...

These are *definitely* supported on Linux, but are *NOT* the glibc
extension (that'd be e.g., %-I), so, hopefully, they're somewhat
portable...

They are also supported on BSD/macOS.
They are *not* supported by the MS UCRT. That means MinGW-w64, too.
This *appears* to be supported on current Bionic (it might even support
said glibc format altering extensions).

* And of course, Windows is terrible, so, make this terribly ugly to not
break it there...

* Turns out BSD also supports the dash trim format extension, so, leave
the trimming to the libc, and handle the special-casing in a way that
doesn't create stupid locals.

* Random unrelated cleanup ^^.

(https://gitter.im/koreader/koreader?at=5fd24be492aa1c4ef5d11f31)

* Update the testsuite

(Because the default used to be 24h clock).

Changed the default to 24h clock ;p.

* Explain why we don't try to fix it in Lua
This commit is contained in:
NiLuJe
2020-12-12 10:44:35 +01:00
committed by GitHub
parent 3142f98e20
commit 32bf53cfdf
6 changed files with 36 additions and 73 deletions

View File

@@ -224,21 +224,40 @@ end
---- @int seconds number of seconds
---- @bool twelve_hour_clock
---- @treturn string hour string
function util.secondsToHour(seconds, twelve_hour_clock)
local time
if twelve_hour_clock then
if os.date("%p", seconds) == "AM" then
-- @translators This is the time in the morning in the 12-hour clock (%I is the hour, %M the minute).
time = os.date(_("%I:%M AM"), seconds)
--- @note: The MS CRT doesn't support either %l & %k, or the - format modifier (as they're not technically C99 or POSIX).
--- They are otherwise supported on Linux, BSD & Bionic, so, just special-case Windows...
--- We *could* arguably feed the os.date output to gsub("^0(%d)(.*)$", "%1%2"), but, while unlikely,
--- it's conceivable that a translator would put something other that the hour at the front of the string ;).
if jit.os == "Windows" then
function util.secondsToHour(seconds, twelve_hour_clock)
if twelve_hour_clock 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).
return os.date(_("%I:%M AM"), 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
else
-- @translators This is the time in the afternoon in the 12-hour clock (%I is the hour, %M the minute).
time = os.date(_("%I:%M PM"), seconds)
-- @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
else
function util.secondsToHour(seconds, twelve_hour_clock)
if twelve_hour_clock 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).
return os.date(_("%-I:%M AM"), 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
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
else
-- @translators This is the time in the 24-hour clock (%H is the hour, %M the minute).
time = os.date(_("%H:%M"), seconds)
end
return time
end
--- Converts timestamp to a date string