diff options
author | Felix Krause <contact@flyx.org> | 2016-11-10 22:22:48 +0100 |
---|---|---|
committer | Felix Krause <contact@flyx.org> | 2016-11-14 18:28:55 +0100 |
commit | 544a2cfe1a9c4805568f6dd781cd85fa4537cb73 (patch) | |
tree | 930e83c5e4ab199d0f9e65e7a19d6bfba8cc283b /tests/stdlib | |
parent | 4a4a3cdf67d3bd80d18ebe01132d67a5b6400b3a (diff) | |
download | Nim-544a2cfe1a9c4805568f6dd781cd85fa4537cb73.tar.gz |
Fixed daylight saving time
* When formatting timezone, substract 1 hour from timezone when isDST * Do not depend DST in current timezone when parsing arbitrary date because formatted timestamps are never in DST. * On the way, removed an unnecessary line in parsing code which could cause bugs. * Added DST tests
Diffstat (limited to 'tests/stdlib')
-rw-r--r-- | tests/stdlib/ttime.nim | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/stdlib/ttime.nim b/tests/stdlib/ttime.nim index c1559ec7a..6d3d7c93a 100644 --- a/tests/stdlib/ttime.nim +++ b/tests/stdlib/ttime.nim @@ -201,4 +201,25 @@ for tz in [ 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 + doAssert ti.format("zzz") == tz[3] + +block dstTest: + let nonDst = TimeInfo(year: 2015, month: mJan, monthday: 01, yearday: 0, + weekday: dThu, hour: 00, minute: 00, second: 00, isDST: false, timezone: 0) + var dst = nonDst + dst.isDst = true + # note that both isDST == true and isDST == false are valid here because + # DST is in effect on January 1st in some southern parts of Australia. + + doAssert nonDst.toTime() - dst.toTime() == 3600 + doAssert nonDst.format("z") == "+0" + doAssert dst.format("z") == "+1" + + # parsing will set isDST in relation to the local time. We take a date in + # January and one in July to maximize the probability to hit one date with DST + # and one without on the local machine. However, this is not guaranteed. + let + parsedJul = parse("2016-07-01 04:00:00+01:00", "yyyy-MM-dd HH:mm:sszzz") + parsedJan = parse("2016-01-05 04:00:00+01:00", "yyyy-MM-ss HH:mm:sszzz") + doAssert toTime(parsedJan) == fromSeconds(1452394800) + doAssert toTime(parsedJul) == fromSeconds(1467342000) |