Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/main/cypress/specs/Calendar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import YearRangePicker from "../../src/YearRangePicker.js";
import YearPicker from "../../src/YearPicker.js";
import "@ui5/webcomponents-localization/dist/features/calendar/Islamic.js";
import "@ui5/webcomponents-localization/dist/features/calendar/Gregorian.js";
import { resetConfiguration } from "@ui5/webcomponents-base/dist/InitialConfiguration.js";
import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSettings.js";

const getDefaultCalendar = (date: Date) => {
const calDate = new Date(date);
Expand Down Expand Up @@ -1434,3 +1436,40 @@ describe("Day Picker Tests", () => {
});
});
});

describe("Calendar Global Configuration", () => {
it("Should respect firstDayOfWeek from global formatSettings configuration", () => {
const configurationObject = {
"formatSettings": {
"firstDayOfWeek": 6 // Saturday
}
};

cy.window()
.then($el => {
const scriptElement = $el.document.createElement("script");
scriptElement.type = "application/json";
scriptElement.setAttribute("data-ui5-config", "true");
scriptElement.innerHTML = JSON.stringify(configurationObject);
$el.document.head.appendChild(scriptElement);
});

cy.wrap({ resetConfiguration })
.invoke("resetConfiguration", true);

cy.wrap({ getFirstDayOfWeek })
.invoke("getFirstDayOfWeek")
.should("equal", 6);

const date = new Date(Date.UTC(2023, 0, 1, 0, 0, 0)); // January 1, 2023
cy.mount(<Calendar id="calendar1" timestamp={date.valueOf() / 1000} calendarWeekNumbering="Default" />);

cy.get<Calendar>("#calendar1")
.shadow()
.find("[ui5-daypicker]")
.shadow()
.find(".ui5-dp-firstday")
.first()
.should("have.text", "Sat");
});
});
17 changes: 15 additions & 2 deletions packages/main/src/DayPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isPageDownAlt,
isPageDownShiftCtrl,
} from "@ui5/webcomponents-base/dist/Keys.js";
import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSettings.js";
import CalendarDate from "@ui5/webcomponents-localization/dist/dates/CalendarDate.js";
import CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
import UI5Date from "@ui5/webcomponents-localization/dist/dates/UI5Date.js";
Expand Down Expand Up @@ -853,10 +854,22 @@ class DayPicker extends CalendarPart implements ICalendarPicker {
}

_getFirstDayOfWeek(): number {
const localeData = getCachedLocaleDataInstance(getLocale());
let firstDayOfWeek;

if (getFirstDayOfWeek() !== undefined) {
Copy link
Contributor

@unazko unazko Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good place for ternary operator or even:
firstDayOfWeek = getFirstDayOfWeek() || localData.getFistDayOfWeek()

firstDayOfWeek = getFirstDayOfWeek()!;
} else {
firstDayOfWeek = localeData.getFirstDayOfWeek();
}

const result = CalendarUtils.getWeekConfigurationValues(this.calendarWeekNumbering);

const localeData = getCachedLocaleDataInstance(getLocale());
return result?.firstDayOfWeek ? result.firstDayOfWeek : localeData.getFirstDayOfWeek();
if (result?.firstDayOfWeek !== undefined && this.calendarWeekNumbering !== "Default") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part could be one line ternary as well.

return result.firstDayOfWeek;
}

return firstDayOfWeek;
}

get styles() {
Expand Down
10 changes: 9 additions & 1 deletion packages/main/test/pages/Calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
// delete Document.prototype.adoptedStyleSheets;
</script>

<script data-ui5-config type="application/json">
<!-- <script data-ui5-config type="application/json">
{
"language": "EN"
}
</script> -->
<script data-id="sap-ui-config" type="application/json">
{
"rtl": false,
"formatSettings": {
"firstDayOfWeek": 1
}
}
</script>

<script src="%VITE_BUNDLE_PATH%" type="module"></script>
Expand Down
Loading