From 9b2aaf0df62a7159861602ab4e0073d87d4be81d Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Tue, 8 Nov 2016 20:57:53 +0100 Subject: [PATCH 1/2] Fixed timezone sign error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * This was introduced in recent "cosmetic" fix. Not so cosmetic after all… --- lib/pure/times.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 1e869d301c..4260179ed8 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -824,21 +824,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('+') + if info.timezone < 0: buf.add('+') + else: buf.add('-') if hours < 10: buf.add('0') buf.add($hours) buf.add(':') From 91a067496119ce1b3b6b5401e029e7d6c6ed4c9f Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Thu, 10 Nov 2016 19:03:46 +0100 Subject: [PATCH 2/2] Fixed timezone rendering, added test --- lib/pure/times.nim | 9 +++++---- tests/stdlib/ttime.nim | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 4260179ed8..f740038209 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,20 +825,20 @@ 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('+') + 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('+') + 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('+') + 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) diff --git a/tests/stdlib/ttime.nim b/tests/stdlib/ttime.nim index 5d3c8325e4..c1559ec7a2 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