fix util.secondsToHClock when hmsFormat is true (#5640)

This commit is contained in:
Robert
2019-11-26 13:28:11 +01:00
committed by poire-z
parent d93206a841
commit 2161a76ea8
2 changed files with 21 additions and 1 deletions

View File

@@ -156,7 +156,11 @@ function util.secondsToHClock(seconds, withoutSeconds, hmsFormat)
if withoutSeconds then
if hours == "0" then
mins = string.format("%.f", round(seconds / 60))
return mins .. "'"
if hmsFormat then
return T(_("%1m"), mins)
else
return mins .. "'"
end
end
-- @translators This is the 'h' for hour, like in 1h30. This is a duration.
return T(_("%1h%2"), hours, mins)

View File

@@ -430,6 +430,22 @@ describe("util module", function()
assert.is_equal("10h01",
util.secondsToHClock(36060, true))
end)
it("should round seconds to minutes in 0h00m format", function()
assert.is_equal("1m",
util.secondsToHClock(89, true, true))
assert.is_equal("2m",
util.secondsToHClock(90, true, true))
assert.is_equal("2m",
util.secondsToHClock(110, true, true))
assert.is_equal("1h00",
util.secondsToHClock(3600, true, true))
assert.is_equal("1h00",
util.secondsToHClock(3599, true, true))
assert.is_equal("59m",
util.secondsToHClock(3569, true, true))
assert.is_equal("10h01",
util.secondsToHClock(36060, true, true))
end)
it("should convert seconds to 0h00'00'' format", function()
assert.is_equal("0''",
util.secondsToHClock(0))