Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #13558: toDateTime was buggy on 29th, 30th and 31th of each month (and had other quirks) #13565

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
and shouldn't be conflated with `"."`; use -d:nimOldRelativePathBehavior to restore the old
behavior
- `joinPath(a,b)` now honors trailing slashes in `b` (or `a` if `b` = "")
- `times.parse` now only uses input to compute its result, and not `now`:
`parse("2020", "YYYY", utc())` is now `2020-01-01T00:00:00Z` instead of
`2020-03-02T00:00:00Z` if run on 03-02; it also doesn't crash anymore when
used on 29th, 30th, 31st of each month.

### Breaking changes in the compiler

Expand Down
16 changes: 3 additions & 13 deletions lib/pure/times.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2248,19 +2248,9 @@ proc parsePattern(input: string, pattern: FormatPattern, i: var int,

proc toDateTime(p: ParsedTime, zone: Timezone, f: TimeFormat,
input: string): DateTime =
var month = mJan
var year: int
var monthday: int
# `now()` is an expensive call, so we avoid it when possible
(year, month, monthday) =
if p.year.isNone or p.month.isNone or p.monthday.isNone:
let n = now()
(p.year.get(n.year),
p.month.get(n.month.int).Month,
p.monthday.get(n.monthday))
else:
(p.year.get(), p.month.get().Month, p.monthday.get())

var year = p.year.get(0)
var month = p.month.get(1).Month
var monthday = p.monthday.get(1)
year =
case p.era
of eraUnknown:
Expand Down