Home > Mobile >  date-fns isSameWeek not working as expected
date-fns isSameWeek not working as expected

Time:12-06

I'm new with date-fns but intuitively, I would expect this to be true:

isSameWeek(new Date(2021, 11, 11), new Date(2021, 11, 12))

But it actually is false

I must be missing something?

It looks like Thursday seems to be the start of the week because this is true:

isSameWeek(new Date(2021, 11, 12), new Date(2021, 11, 18))

EDIT: When I do this

isSameWeek(new Date(2021, 11, 11), new Date(2021, 11, 12), {weekStartsOn: 1})

It now is true... I'm confused.

CodePudding user response:

The months start at 0 being January.

So 11 is December.

December 11 is a Saturday, the 12th is Sunday (start of the next week). So they are not in the same week.

December 12 is Sunday, December 18th is the Saturday of the same week. So they are in the same week.

  • Related