mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 23:54:19 +00:00
Merge pull request #5009 from flyx/timezonefix2
Fixed timezone sign error
This commit is contained in:
@@ -732,6 +732,7 @@ const
|
||||
secondsInMin = 60
|
||||
secondsInHour = 60*60
|
||||
secondsInDay = 60*60*24
|
||||
minutesInHour = 60
|
||||
epochStartYear = 1970
|
||||
|
||||
proc formatToken(info: TimeInfo, token: string, buf: var string) =
|
||||
@@ -824,21 +825,21 @@ proc formatToken(info: TimeInfo, token: string, buf: var string) =
|
||||
buf.add(fyear)
|
||||
of "z":
|
||||
let hours = abs(info.timezone) div secondsInHour
|
||||
if info.timezone < 0: buf.add('-')
|
||||
else: buf.add('+')
|
||||
if info.timezone <= 0: buf.add('+')
|
||||
else: buf.add('-')
|
||||
buf.add($hours)
|
||||
of "zz":
|
||||
let hours = abs(info.timezone) div secondsInHour
|
||||
if info.timezone < 0: buf.add('-')
|
||||
else: buf.add('+')
|
||||
if info.timezone <= 0: buf.add('+')
|
||||
else: buf.add('-')
|
||||
if hours < 10: buf.add('0')
|
||||
buf.add($hours)
|
||||
of "zzz":
|
||||
let
|
||||
hours = abs(info.timezone) div secondsInHour
|
||||
minutes = abs(info.timezone) mod 60
|
||||
if info.timezone < 0: buf.add('-')
|
||||
else: buf.add('+')
|
||||
minutes = (abs(info.timezone) div secondsInMin) mod minutesInHour
|
||||
if info.timezone <= 0: buf.add('+')
|
||||
else: buf.add('-')
|
||||
if hours < 10: buf.add('0')
|
||||
buf.add($hours)
|
||||
buf.add(':')
|
||||
|
||||
@@ -190,3 +190,15 @@ doAssert cmpTimeNoSideEffect(0.fromSeconds, 0.fromSeconds)
|
||||
let seqA: seq[Time] = @[]
|
||||
let seqB: seq[Time] = @[]
|
||||
doAssert seqA == seqB
|
||||
|
||||
for tz in [
|
||||
(0, "+0", "+00", "+00:00"), # UTC
|
||||
(-3600, "+1", "+01", "+01:00"), # CET
|
||||
(-39600, "+11", "+11", "+11:00"), # two digits
|
||||
(-1800, "+0", "+00", "+00:30"), # half an hour
|
||||
(7200, "-2", "-02", "-02:00"), # positive
|
||||
(38700, "-10", "-10", "-10:45")]: # positive with three quaters hour
|
||||
let ti = TimeInfo(monthday: 1, timezone: tz[0])
|
||||
doAssert ti.format("z") == tz[1]
|
||||
doAssert ti.format("zz") == tz[2]
|
||||
doAssert ti.format("zzz") == tz[3]
|
||||
Reference in New Issue
Block a user