diff options
Diffstat (limited to 'tests/js/ttimes.nim')
-rw-r--r-- | tests/js/ttimes.nim | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/tests/js/ttimes.nim b/tests/js/ttimes.nim index 2868c6d0f..63a4bb04f 100644 --- a/tests/js/ttimes.nim +++ b/tests/js/ttimes.nim @@ -1,4 +1,3 @@ -# test times module with js discard """ action: run """ @@ -9,21 +8,37 @@ import times # Tue 19 Jan 03:14:07 GMT 2038 block yeardayTest: - # check if yearday attribute is properly set on TimeInfo creation - doAssert fromSeconds(2147483647).getGMTime().yearday == 18 - -block localTimezoneTest: - # check if timezone is properly set during Time to TimeInfo conversion - doAssert fromSeconds(2147483647).getLocalTime().timezone == getTimezone() - -block timestampPersistenceTest: - # check if timestamp persists during TimeInfo to Time conversion - const - timeString = "2017-03-21T12:34:56+03:00" - timeStringGmt = "2017-03-21T09:34:56+00:00" - timeStringGmt2 = "2017-03-21T08:34:56+00:00" - fmt = "yyyy-MM-dd'T'HH:mm:sszzz" - # XXX Check which one is the right solution here: - - let x = $timeString.parse(fmt).toTime().getGMTime() - doAssert x == timeStringGmt or x == timeStringGmt2 + doAssert fromUnix(2147483647).utc.yearday == 18 + +block localTime: + var local = now() + let utc = local.utc + doAssert local.toTime == utc.toTime + +let a = fromUnix(1_000_000_000) +let b = fromUnix(1_500_000_000) +doAssert b - a == 500_000_000 + +# Because we can't change the timezone JS uses, we define a simple static timezone for testing. + +proc staticZoneInfoFromUtc(time: Time): ZonedTime = + result.utcOffset = -7200 + result.isDst = false + result.adjTime = (time.toUnix + 7200).Time + +proc staticZoneInfoFromTz(adjTime: Time): ZonedTIme = + result.utcOffset = -7200 + result.isDst = false + result.adjTime = adjTime + +let utcPlus2 = Timezone(zoneInfoFromUtc: staticZoneInfoFromUtc, zoneInfoFromTz: staticZoneInfoFromTz, name: "") + +block timezoneTests: + let dt = initDateTime(01, mJan, 2017, 12, 00, 00, utcPlus2) + doAssert $dt == "2017-01-01T12:00:00+02:00" + doAssert $dt.utc == "2017-01-01T10:00:00+00:00" + doAssert $dt.utc.inZone(utcPlus2) == $dt + +doAssert $initDateTime(01, mJan, 1911, 12, 00, 00, utc()) == "1911-01-01T12:00:00+00:00" +# See #6752 +# doAssert $initDateTime(01, mJan, 1900, 12, 00, 00, utc()) == "0023-01-01T12:00:00+00:00" \ No newline at end of file |