zag
zag copied to clipboard
date-utils: getWeekDays has incoherent behavior when both locale and startOfWeekProp are set
🐛 Bug report
The function getWeekDays exported in @zag-js/date-utils does not respect startOfWeekProp argument in some locales (ex. "fr").
💥 Steps to reproduce
import { CalendarDate } from "@internationalized/date";
import { getWeekDays } from "@zag-js/date-utils";
function test(locale, weekStartDay) {
const today = new CalendarDate(2024, 8, 21);
const days = getWeekDays(today, weekStartDay, "UTC", locale);
return days[0].value.day;
}
console.log(test("fr", 1));
Outputs:
20
Which is a Tuesday (August 20, 2024).
💻 Link to reproduction
CodeSandbox reproduction: https://codesandbox.io/p/devbox/naughty-wood-6qnkw4
🧐 Expected behavior
test("fr", 1) should return 19 (week starts on Monday):
-
test("fr", undefined)returns19as expected (Monday being the default for"fr"locale); -
test("en", 1)also returns19as expected (asking explicitely to start week on Monday); - but passing the two options returns
20.
🧭 Possible Solution
The bugs comes from getStartOfWeek private function; I believe that if firstDayOfWeek is provided, then the locale should not matter.
🌍 System information
| Software | Version(s) |
|---|---|
| Zag Version | 0.65.1 |
| Browser | N/A |
| Operating System | N/A |
📝 Additional information
N/A