Skip to content

Commit

Permalink
fix nim-lang#13558: toDateTime buggy on 29th, 30th and 31th of each m…
Browse files Browse the repository at this point in the history
…onth; breaking change: do not use `now` to compute result, was undocumented and non-sensical
  • Loading branch information
timotheecour committed Mar 3, 2020
1 parent b03e9d9 commit c890820
Showing 1 changed file with 3 additions and 13 deletions.
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

0 comments on commit c890820

Please sign in to comment.