* First work on better timezones * Update tests to new api. Removed tests for checking that `isDst` was included when formatting, since `isDst` no longer affects utc offset (the entire utc offset is stored directly in `utcOffset` instead). * Deprecate getLocaltime & getGmTime * Add `now()` as a shorthand for GetTIme().inZone(Local) * Add FedericoCeratto's timezone tests (#6548) * Run more tests in all timezones * Make month enum start at 1 instead of 0 * Deprecate getDayOfWeekJulian * Fix issues with gc safety * Rename TimeInfo => DateTime * Fixes #6465 * Improve isLeapYear * FIx handling negative adjTime * Cleanup: - deprecated toSeconds and fromSeconds, added fromUnix and toUnix instead (that returns int64 instead of float) - added missing doc comments - removed some unnecessary JS specific implementations * Fix misstake in JS `-` for Time * Update usage of TimeEffect * Removed unecessary use of `difftime` * JS fix for local tz * Fix subtraction of months * Fix `days` field in `toTimeInterval` * Style and docs * Fix getDayOfYear for real this time... * Fix handling of adding/subtracting time across dst transitions * Fix some bad usage of the times module in the stdlib * Revert to use proper time resoultion for seeding in random.nim * Move deprecated procs to bottom of file * Always use `epochTime` in `randomize` * Remove TimeInterval normalization * Fixes #6905 * Fix getDayOfWeek for year < 1 * Export toEpochDay/fromEpochDay and change year/month/monthday order * Add asserts for checking that the monthday is valid * Fix some remaining ambiguous references to `Time` * Fix ambiguous reference to Time
44 lines
No EOL
1.2 KiB
Nim
44 lines
No EOL
1.2 KiB
Nim
discard """
|
|
action: run
|
|
"""
|
|
|
|
import times
|
|
|
|
# $ date --date='@2147483647'
|
|
# Tue 19 Jan 03:14:07 GMT 2038
|
|
|
|
block yeardayTest:
|
|
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" |