Skip to content

Commit 4e18756

Browse files
fix(ui5-calendar): use global configuration for first day of week (#12665)
fixes: #12426
1 parent 8821858 commit 4e18756

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

packages/main/cypress/specs/Calendar.cy.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import YearRangePicker from "../../src/YearRangePicker.js";
66
import YearPicker from "../../src/YearPicker.js";
77
import "@ui5/webcomponents-localization/dist/features/calendar/Islamic.js";
88
import "@ui5/webcomponents-localization/dist/features/calendar/Gregorian.js";
9+
import { resetConfiguration } from "@ui5/webcomponents-base/dist/InitialConfiguration.js";
10+
import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSettings.js";
911

1012
const getDefaultCalendar = (date: Date) => {
1113
const calDate = new Date(date);
@@ -1434,3 +1436,40 @@ describe("Day Picker Tests", () => {
14341436
});
14351437
});
14361438
});
1439+
1440+
describe("Calendar Global Configuration", () => {
1441+
it("Should respect firstDayOfWeek from global formatSettings configuration", () => {
1442+
const configurationObject = {
1443+
"formatSettings": {
1444+
"firstDayOfWeek": 6 // Saturday
1445+
}
1446+
};
1447+
1448+
cy.window()
1449+
.then($el => {
1450+
const scriptElement = $el.document.createElement("script");
1451+
scriptElement.type = "application/json";
1452+
scriptElement.setAttribute("data-ui5-config", "true");
1453+
scriptElement.innerHTML = JSON.stringify(configurationObject);
1454+
$el.document.head.appendChild(scriptElement);
1455+
});
1456+
1457+
cy.wrap({ resetConfiguration })
1458+
.invoke("resetConfiguration", true);
1459+
1460+
cy.wrap({ getFirstDayOfWeek })
1461+
.invoke("getFirstDayOfWeek")
1462+
.should("equal", 6);
1463+
1464+
const date = new Date(Date.UTC(2023, 0, 1, 0, 0, 0)); // January 1, 2023
1465+
cy.mount(<Calendar id="calendar1" timestamp={date.valueOf() / 1000} calendarWeekNumbering="Default" />);
1466+
1467+
cy.get<Calendar>("#calendar1")
1468+
.shadow()
1469+
.find("[ui5-daypicker]")
1470+
.shadow()
1471+
.find(".ui5-dp-firstday")
1472+
.first()
1473+
.should("have.text", "Sat");
1474+
});
1475+
});

packages/main/src/DayPicker.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
isPageDownAlt,
3232
isPageDownShiftCtrl,
3333
} from "@ui5/webcomponents-base/dist/Keys.js";
34+
import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSettings.js";
3435
import CalendarDate from "@ui5/webcomponents-localization/dist/dates/CalendarDate.js";
3536
import CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
3637
import UI5Date from "@ui5/webcomponents-localization/dist/dates/UI5Date.js";
@@ -853,10 +854,23 @@ class DayPicker extends CalendarPart implements ICalendarPicker {
853854
}
854855

855856
_getFirstDayOfWeek(): number {
857+
const localeData = getCachedLocaleDataInstance(getLocale());
858+
let firstDayOfWeek;
859+
const configurationFirstDayOfWeek = getFirstDayOfWeek();
860+
861+
if (configurationFirstDayOfWeek !== undefined) {
862+
firstDayOfWeek = configurationFirstDayOfWeek;
863+
} else {
864+
firstDayOfWeek = localeData.getFirstDayOfWeek();
865+
}
866+
856867
const result = CalendarUtils.getWeekConfigurationValues(this.calendarWeekNumbering);
857868

858-
const localeData = getCachedLocaleDataInstance(getLocale());
859-
return result?.firstDayOfWeek ? result.firstDayOfWeek : localeData.getFirstDayOfWeek();
869+
if (result?.firstDayOfWeek !== undefined && this.calendarWeekNumbering !== "Default") {
870+
return result.firstDayOfWeek;
871+
}
872+
873+
return firstDayOfWeek;
860874
}
861875

862876
get styles() {

packages/main/test/pages/Calendar.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010
// delete Document.prototype.adoptedStyleSheets;
1111
</script>
1212

13-
<script data-ui5-config type="application/json">
13+
<!-- <script data-ui5-config type="application/json">
1414
{
1515
"language": "EN"
1616
}
17+
</script> -->
18+
<script data-id="sap-ui-config" type="application/json">
19+
{
20+
"rtl": false,
21+
"formatSettings": {
22+
"firstDayOfWeek": 0
23+
}
24+
}
1725
</script>
1826

1927
<script src="%VITE_BUNDLE_PATH%" type="module"></script>

0 commit comments

Comments
 (0)