felixge/node-dateformat

Week number is not always right

Olafxso opened this issue · 2 comments

Hi,

The week number is not always correct. Check this:

  console.log("2022-01-04 = week: " + dateFormat(new Date("2022-01-04"), "W")); // 4 january must be week 1, this is correct
  console.log("2022-01-10 = week: " + dateFormat(new Date("2022-01-10"), "W")); // monday next week
  console.log("2022-01-17 = week: " + dateFormat(new Date("2022-01-17"), "W"));
  console.log("2022-01-24 = week: " + dateFormat(new Date("2022-01-24"), "W"));

When I set my timezone to Fuji (UTC+12:00) it prints out:

2022-01-04 = week: 1
2022-01-10 = week: 2
2022-01-17 = week: 2
2022-01-24 = week: 3

It prints two times week 2. This is not correct.
Can you fix this? Or am I wrong?

Thanks!
Olaf

I guess it's a problem of new Date(string), not dateformat.

MDN says:

Parsing of date strings with the Date constructor (and Date.parse(), which works the same way) is strongly discouraged

in Date() constructor - JavaScript | MDN.

How about new Date(2022, 0, 10)?

Closing due to inactivity.