like moment.js
moment().isSame(date, "day")
dayjs().diff(date, 'day') === 0dayjs().format('YYYYMMDD') === dayjs(date).format('YYYYMMDD')How to make an elegant comparison
dayjs().isSame(date, 'day')
It seems that second parameters are not supported?
After digging a bit in the code, as the docs point that isSame() can receive only one argument but is not really that descriptive; I found out that it checks the Unix Timestamp of the dates compared by using .valueOf(); so unless you are that precise with the comparison, it will always be false.
In terms of elegance, the first one looks nicer; but I am using the second one as I came across a small issue with a false positive when using the full timestamp because it seems that .diff(date, 'day') checks that it's within the 24 hour range (not that I checked thoroughly, just hit that brickroad and added formatting).
It would be nice to expand a bit the isSame() method to help in this cases.
@maeriens thx you comment 馃槝. I used it back moment.js, Avoid these problems 馃槥
Agreed, second argument should be supported to more closely conform to moment's api.
I found out that it checks the Unix Timestamp of the dates
That's pretty different than what the documentation suggests:
https://github.com/iamkun/dayjs/blob/master/docs/en/API-reference.md#is-same-issamecompared-dayjs
Returns a boolean indicating whether the Dayjs's date is the same as the other supplied Dayjs's.
It seems that it should just be comparing the month day and year.
Please check ongoing discussion on Pull Request https://github.com/iamkun/dayjs/pull/404
:tada: This is included in version 1.8.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Most helpful comment
:tada: This is included in version 1.8.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: