dayjs
dayjs copied to clipboard
callback pattern of `calendar` formats not actually formatting
Expected
Using the custom formatting feature of the calendar plugin should format according to the returned formatting string.
As per docs:
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:
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