Default the day of the month to 1 in strptime/1 (#3679)
A format without %d left the day of the month at 0, which mktime and todate read as the last day of the previous month, and the weekday was wrong for dates in January and February of 1900 and 2100. Start parsing from the 1st, so a format without a day now gives the first of the month, and a time-only format no longer outputs the 8 and 367 placeholders for the weekday and day of the year. This also fixes the weekday of dates in January and February of 1900 and 2100.
This commit is contained in:
1 parent
864d769d88
commit
ac35c7dcbb
2 files changed
+22
-8
No files matched your search
@@ -1988,6 +1988,15 @@ try strflocaltime("%c" * 10) catch .
|
||||
"2015-03-05T23:51:47Z"
|
||||
[[2015,2,5,23,51,47,4,63],1425599507]
|
||||
|
||||
# a format without a day of the month gives the first of the month
|
||||
[("2024-06" | strptime("%Y-%m")), ("2024" | strptime("%Y")) | ., todate]
|
||||
null
|
||||
[[2024,5,1,0,0,0,6,152],"2024-06-01T00:00:00Z",[2024,0,1,0,0,0,1,0],"2024-01-01T00:00:00Z"]
|
||||
|
||||
"10:15" | strptime("%H:%M")
|
||||
null
|
||||
[1900,0,1,10,15,0,1,0]
|
||||
|
||||
# Check day-of-week and day of year computations
|
||||
# (should trip an assert if this fails)
|
||||
last(range(365 * 67)|("1970-03-01T01:02:03Z"|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime) + (86400 * .)|strftime("%Y-%m-%dT%H:%M:%SZ")|strptime("%Y-%m-%dT%H:%M:%SZ"))
|
||||
|
||||
Reference in new issue
Block a user