Skip to content

Commit

Permalink
fix(i18n): allow weeks to start on Saturday (#7965)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored Dec 6, 2024
1 parent ccee1f4 commit 59deb00
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/sanity/src/core/i18n/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ export interface Locale {
*/
export interface LocaleWeekInfo {
/**
* An integer indicating the first day of the week for the locale. Can be either 1 (Monday) or 7 (Sunday).
* An integer indicating the first day of the week for the locale.
* Can be either 1 (Monday), 6 (Saturday) or 7 (Sunday).
*/
firstDay: 1 | 7
firstDay: 1 | 6 | 7

/**
* An array of integers indicating the weekend days for the locale, where 1 is Monday and 7 is Sunday.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const WEEK_DAY_NAME_KEYS = {
// Monday is start of the week
1: SHORT_WEEK_DAY_KEYS,

// Saturday is start of week
6: [...SHORT_WEEK_DAY_KEYS.slice(5), ...SHORT_WEEK_DAY_KEYS.slice(0, 5)],

// Sunday is start of the week
7: [SHORT_WEEK_DAY_KEYS[6], ...SHORT_WEEK_DAY_KEYS.slice(0, 6)],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface CalendarContextValue {

/**
* An integer indicating the first day of the week.
* Can be either 1 (Monday) or 7 (Sunday).
* Can be either 1 (Monday), 6 (Saturday) or 7 (Sunday).
*/
firstWeekDay: 1 | 7
firstWeekDay: 1 | 6 | 7
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ export function CalendarMonth(props: CalendarMonthProps) {
weekInfo: {firstDay: weekStartDay},
} = useCurrentLocale()

const weekDayNames =
weekStartDay === 1
? props.weekDayNames
: [props.weekDayNames[6], ...props.weekDayNames.slice(0, 6)]
let weekDayNames: Array<string> = props.weekDayNames
if (weekStartDay === 7) {
weekDayNames = [props.weekDayNames[6], ...props.weekDayNames.slice(0, 6)]
} else if (weekStartDay === 6) {
weekDayNames = [...props.weekDayNames.slice(5), ...props.weekDayNames.slice(0, 5)]
}

return (
<Box aria-hidden={props.hidden || false} data-ui="CalendarMonth">
Expand Down

0 comments on commit 59deb00

Please sign in to comment.