iamkun / iamkun/dayjs

Calendar format returns wrong date

Open
#1,226 7 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

Hello!

I have the following snippet:

```ts
import calendar from 'dayjs/plugin/calendar';
dayjs.extend(calendar);

return dayjs().calendar(dayjs(date), {
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'DD/MM/YYYY',
});
```

The problems , in my opinion, are :
- if the date falls under the sameElse category i get the date of today ( since today is 16/11/2020, i get 16/11/2020 for all dates that fall under sameElse)
- all dates under next and last are inverted - meaning if i choose 17/11/2020, i get yesterday, and i if choose 15/11/2020, i get tomorrow
- also, for dates such as 18/11/2020,19/11/2020 i get last Monday instead of Wednesday or Thursday, and for dates such as 14/11/2020 i get Monday instead of last Sunday

If I'm missing something from the documentation, please let me know, but in my opinion this isn't the right behaviour for this function.

Thank you for your time!

Contributor guide

Open the contributing guide

Research direction

Start with the calendar plugin and reproduce the provided TypeScript snippet using dates around 14–19/11/2020. Check the sameElse, next, and last calendar categories against the reported results, then verify that the output uses the selected date rather than today and the correct weekday labels.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.