fix #17072: add times.dateTime with ISO 8601 order (#18590)

* fix #17072: add times.dateTime with ISO 8601 order

* address comments
This commit is contained in:
Timothee Cour 2021-07-27 21:38:19 -07:00 • committed by GitHub
commit 4c1202972a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 12 deletions

View file

@ -331,9 +331,12 @@
- Added `htmlgen.portal` for [making "SPA style" pages using HTML only](https://web.dev/hands-on-portals). - Added `htmlgen.portal` for [making "SPA style" pages using HTML only](https://web.dev/hands-on-portals).
- Added `ZZZ` and `ZZZZ` patterns to `times.nim` `DateTime` parsing, to match time - `std/times`:
Added `ZZZ` and `ZZZZ` patterns to `times.nim` `DateTime` parsing, to match time
zone offsets without colons, e.g. `UTC+7 -> +0700`. zone offsets without colons, e.g. `UTC+7 -> +0700`.
Added `dateTime` and deprecated `initDateTime`.
- Added `jsconsole.dir`, `jsconsole.dirxml`, `jsconsole.timeStamp`. - Added `jsconsole.dir`, `jsconsole.dirxml`, `jsconsole.timeStamp`.
- Added dollar `$` and `len` for `jsre.RegExp`. - Added dollar `$` and `len` for `jsre.RegExp`.
@ -357,6 +360,7 @@
- Added `dom.setInterval`, `dom.clearInterval` overloads. - Added `dom.setInterval`, `dom.clearInterval` overloads.
- Deprecated `sequtils.delete` and added an overload taking a `Slice` that raises a defect - Deprecated `sequtils.delete` and added an overload taking a `Slice` that raises a defect
if the slice is out of bounds, likewise with `strutils.delete`. if the slice is out of bounds, likewise with `strutils.delete`.

View file

@ -1333,14 +1333,13 @@ proc now*(): DateTime {.tags: [TimeEffect], benign.} =
## `cpuTime` instead, depending on the use case. ## `cpuTime` instead, depending on the use case.
getTime().local getTime().local
proc initDateTime*(monthday: MonthdayRange, month: Month, year: int, proc dateTime*(year: int, month: Month, monthday: MonthdayRange,
hour: HourRange, minute: MinuteRange, second: SecondRange, hour: HourRange = 0, minute: MinuteRange = 0, second: SecondRange = 0,
nanosecond: NanosecondRange, nanosecond: NanosecondRange = 0,
zone: Timezone = local()): DateTime = zone: Timezone = local()): DateTime =
## Create a new `DateTime <#DateTime>`_ in the specified timezone. ## Create a new `DateTime <#DateTime>`_ in the specified timezone.
runnableExamples: runnableExamples:
let dt1 = initDateTime(30, mMar, 2017, 00, 00, 00, 00, utc()) assert $dateTime(2017, mMar, 30, zone = utc()) == "2017-03-30T00:00:00Z"
doAssert $dt1 == "2017-03-30T00:00:00Z"
assertValidDate monthday, month, year assertValidDate monthday, month, year
let dt = DateTime( let dt = DateTime(
@ -1356,12 +1355,20 @@ proc initDateTime*(monthday: MonthdayRange, month: Month, year: int,
proc initDateTime*(monthday: MonthdayRange, month: Month, year: int, proc initDateTime*(monthday: MonthdayRange, month: Month, year: int,
hour: HourRange, minute: MinuteRange, second: SecondRange, hour: HourRange, minute: MinuteRange, second: SecondRange,
zone: Timezone = local()): DateTime = nanosecond: NanosecondRange,
zone: Timezone = local()): DateTime {.deprecated: "use `dateTime`".} =
## Create a new `DateTime <#DateTime>`_ in the specified timezone. ## Create a new `DateTime <#DateTime>`_ in the specified timezone.
runnableExamples: runnableExamples("--warning:deprecated:off"):
let dt1 = initDateTime(30, mMar, 2017, 00, 00, 00, utc()) assert $initDateTime(30, mMar, 2017, 00, 00, 00, 00, utc()) == "2017-03-30T00:00:00Z"
doAssert $dt1 == "2017-03-30T00:00:00Z" dateTime(year, month, monthday, hour, minute, second, nanosecond, zone)
initDateTime(monthday, month, year, hour, minute, second, 0, zone)
proc initDateTime*(monthday: MonthdayRange, month: Month, year: int,
hour: HourRange, minute: MinuteRange, second: SecondRange,
zone: Timezone = local()): DateTime {.deprecated: "use `dateTime`".} =
## Create a new `DateTime <#DateTime>`_ in the specified timezone.
runnableExamples("--warning:deprecated:off"):
assert $initDateTime(30, mMar, 2017, 00, 00, 00, utc()) == "2017-03-30T00:00:00Z"
dateTime(year, month, monthday, hour, minute, second, 0, zone)
proc `+`*(dt: DateTime, dur: Duration): DateTime = proc `+`*(dt: DateTime, dur: Duration): DateTime =
runnableExamples: runnableExamples: