1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 19:20:29 +00:00

Fix time formatting (#527)

Fixes #525.

Co-authored-by: R93950X <R93950X@users.noreply.github.com>
This commit is contained in:
R93950X 2020-08-22 07:17:12 -07:00 committed by GitHub
parent 0faf76e4bd
commit d5de39ebd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -77,7 +77,7 @@ function formatTime(nTime, bTwentyFourHour)
local nHour = math.floor(nTime)
local nMinute = math.floor((nTime - nHour) * 60)
if sTOD then
return string.format("%d:%02d %s", nHour, nMinute, sTOD)
return string.format("%d:%02d %s", nHour == 0 and 12 or nHour, nMinute, sTOD)
else
return string.format("%d:%02d", nHour, nMinute)
end

View File

@ -12,6 +12,14 @@ describe("The textutils library", function()
expect.error(textutils.formatTime, nil):eq("bad argument #1 (expected number, got nil)")
expect.error(textutils.formatTime, 1, 1):eq("bad argument #2 (expected boolean, got number)")
end)
it("correctly formats 12 o'clock", function()
expect(textutils.formatTime(0, false)):eq("12:00 AM")
expect(textutils.formatTime(0.1, false)):eq("12:06 AM")
expect(textutils.formatTime(0, true)):eq("0:00")
expect(textutils.formatTime(0.1, true)):eq("0:06")
end)
end)
describe("textutils.pagedPrint", function()
@ -49,7 +57,7 @@ describe("The textutils library", function()
describe("textutils.empty_json_array", function()
it("is immutable", function()
expect.error(function() textutils.empty_json_array[1] = true end)
:str_match("^[^:]+:51: attempt to mutate textutils.empty_json_array$")
:str_match("^[^:]+:%d+: attempt to mutate textutils.empty_json_array$")
end)
end)