fixes #13558: toDateTime buggy on 29th, 30th and 31th of each month; breaking change: do not use now to compute result, was undocumented and non-sensical (#13565)

This commit is contained in:
Timothee Cour 2020-03-11 01:47:34 -07:00 • committed by GitHub
commit 281e02fc79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 13 deletions

View file

@ -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: