Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsSame example is not equivalent #103

Open
Eonasdan opened this issue Jan 12, 2021 · 0 comments
Open

IsSame example is not equivalent #103

Eonasdan opened this issue Jan 12, 2021 · 0 comments

Comments

@Eonasdan
Copy link

Hello, thanks for this great resource. I'm working on a new version of my date picker and I'm looking to remove momentjs. I was able to use some of the info here to whittle down the functions I needed. You are welcome to look at the full example on stackblitz as make use of what's there.

One thing I noticed is that your IsSame example with a granularity is not equivalent:
new Date(2010, 9, 20).toDateString().substring(4, 7) === new Date(2010, 9, 21).toDateString().substring(4, 7);

While technically does verify that both dates are in Oct this is not what moment/dayjs do. Those libs use their startOf function to take the dates to the beginning of the unit passed and then compare the valueOf. (I think the comparison of dates example should use valueOf as that's a more accurate comparison anyway).

In the provide example moment and dayjs would do the following

moment('2010-10-20').isSame('2010-10-21', 'month');
thisDate = 2010-10-1 //via startOf
compareDate = 2010-10-1
thisDate.valueOf() === compareDate.valueOf() //true

moment('2010-10-20').isSame('2021-10-21', 'month');
thisDate = 2010-10-1
compareDate = 2021-10-1
thisDate.valueOf() === compareDate.valueOf() //false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant