dayjs / dayjs-website

⏰Day.js website repo
http://day.js.org/
MIT License
66 stars 227 forks source link

calendar giving wrong descriptions #4

Closed sharifmacky closed 2 years ago

sharifmacky commented 4 years ago

If you follow the documentation and pass a date to the calendar method, then the relative description for yesterday is incorrect: Consider: dayjs() => Fri Mar 06 2020 14:05:09 GMT+0000 (Greenwich Mean Time)

dayjs().calendar(dayjs('2020-03-06')) => "Today at 2:05 PM" // correct dayjs().calendar(dayjs('2020-03-05')) => "Tomorrow at 2:05 PM" // wrong 05 should be yesterday

The same issue is present in the extended syntax: `dayjs().calendar(dayjs('2020-03-05'), {...props}) => "Tomorrow at 2:05 PM" // wrong 05 should be yesterday``

If you pass a date to the dayjs constructor it seems to work fine. dayjs(dayjs('2020-03-06')).calendar() => "Today at 12:00 AM" // correct dayjs(dayjs('2020-03-05')).calendar() => "Yesterday at 12:00 AM" // correct

Similarly: dayjs(dayjs('2020-03-05')).calendar(null, {...props}) => "Yesterday at 12:00 AM" // correct

It seems this is not limited to just 'yesterday' but other descriptions for days of week etc.

iamkun commented 4 years ago

Calendar time displays time relative to a given reference time (defaults to now), but does so slightly differently than dayjs#fromNow.

https://runkit.com/embed/nffxk3wiv5th

Screen Shot 2020-03-08 at 10 42 57 PM