iamkun / iamkun/dayjs

callback pattern of `calendar` formats not actually formatting

Open
#2,664 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

### Expected

Using the custom formatting feature of the `calendar` plugin should format according to the returned formatting string.

As per [docs](https://day.js.org/docs/en/customization/calendar):

> Each of the Locale#calendar keys can also be a callback function with the scope of the current Day.js object and first argument a Day.js object that depicts now. It should return a formatting string.

For example:

```js
return dayjs('someDateStr').calendar(null, {
nextWeek: () => {
return 'dddd [at] LT'
}
})
```

This should format according to the formatting string.

### Actual

In reality, it just returns the formatting string itself. The output is `dddd [at] LT`.

This is clear from the source, where it is invoking and returning the result of the function, rather than using the result of the function to `.format()`:

https://github.com/iamkun/dayjs/blob/4fbe94aaba8c815a42cf4d23dabac918ec50e68c/src/plugin/calendar/index.js#L27-L29

**Information**
- Day.js Version 1.11.11

Contributor guide

Open the contributing guide

Research direction

Start in src/plugin/calendar/index.js at the implementation linked in the issue, then reproduce the documented calendar callback example from the issue. Confirm that the callback's returned formatting string is applied to the current date rather than returned literally; done means the example produces formatted output such as a weekday and time.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.