diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-11-14 16:44:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-14 16:44:01 +0100 |
commit | 4a4a3cdf67d3bd80d18ebe01132d67a5b6400b3a (patch) | |
tree | 6fb5ad808569e14f66ef43847b777ce080f37a35 | |
parent | a29387424a1395052c6da164ebe0168698eae21e (diff) | |
parent | 91a067496119ce1b3b6b5401e029e7d6c6ed4c9f (diff) | |
download | Nim-4a4a3cdf67d3bd80d18ebe01132d67a5b6400b3a.tar.gz |
Merge pull request #5009 from flyx/timezonefix2
Fixed timezone sign error
-rw-r--r-- | lib/pure/times.nim | 15 | ||||
-rw-r--r-- | tests/stdlib/ttime.nim | 12 |
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 1e869d301..f74003820 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -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(':') diff --git a/tests/stdlib/ttime.nim b/tests/stdlib/ttime.nim index 5d3c8325e..c1559ec7a 100644 --- a/tests/stdlib/ttime.nim +++ b/tests/stdlib/ttime.nim @@ -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] \ No newline at end of file |