date-io
date-io copied to clipboard
Inconsistent getWeekdays between dayjs and other libs
In @date-io/date-fns getWeekdays returns an array of weekdays with respect to user locale:
https://github.com/dmtrKovalenko/date-io/blob/master/packages/date-fns/src/date-fns-utils.ts#L227
In @date-io/dayjs getWeekdays returns an array of weekdays always starting with sunday.
https://github.com/dmtrKovalenko/date-io/blob/master/packages/dayjs/src/dayjs-utils.ts#L209
This happens, because in dayjs `set('day', 0) always yields sunday (source: dayjs docs)
Possible solution to this is to use dayjs().startOf('week'), which results in correct week start for the given locale
Here's an example getWeekdays implementation that works correctly with ru locale
public getWeekdays() {
const start = this.dayjs().startOf("week");
return [0, 1, 2, 3, 4, 5, 6].map(diff =>
this.format(this.dayjs(start).add(diff, "day"), "dd")
);
}