Closed
Description
Using Sunday-based week and day-of-week numbers, the format and parse methods treat week zero inconsistently. This can cause round-tripping of a date to fail. Based on the documentation, my understanding is that week one commences with the first Sunday of the year, and days prior to that lie in week zero. If so, it looks like the format method is buggy.
d3.timeFormat('%Y %U %w')(new Date(2012, 0, 1)) // "2012 00 0" -> should be "2012 01 0"?
d3.timeParse('%Y %U %w')('2012 00 0').toLocaleString() // "12/25/2011, 12:00:00 AM"
d3.timeParse('%Y %U %w')('2012 01 0').toLocaleString() // "1/1/2012, 12:00:00 AM"
d3.utcFormat('%Y %U %w')(new Date(Date.UTC(2012, 0, 1))) // "2012 00 0"
d3.utcParse('%Y %U %w')('2012 00 0').toUTCString() // "Sun, 25 Dec 2011 00:00:00 GMT"
Using Monday-based week and day-of-week numbers exhibits the same problem:
d3.timeFormat('%Y %W %u')(new Date(2018, 0, 1)) // "2018 00 1" -> should be "2018 01 1"?
d3.timeParse('%Y %W %u')('2018 00 1').toLocaleString() // "12/25/2017, 12:00:00 AM"
d3.timeParse('%Y %W %u')('2018 01 1').toLocaleString() // "1/1/2018, 12:00:00 AM"
d3.utcFormat('%Y %W %u')(new Date(Date.UTC(2018, 0, 1))) // "2018 00 1"
d3.utcParse('%Y %W %u')('2018 00 1').toUTCString() // "Mon, 25 Dec 2017 00:00:00 GMT"
Metadata
Metadata
Assignees
Labels
No labels