new design and added class function

This commit is contained in:
2025-01-28 06:19:12 +01:00
parent b3d6c7c75b
commit 8e0d7c9e8d
5 changed files with 255 additions and 100 deletions

34
utils.js Normal file
View File

@@ -0,0 +1,34 @@
export function getWeekdaysForLocale(localeName = 'en-GB', weekday = 'long', firstDayInWeek = 'Sunday') {
const {format} = new Intl.DateTimeFormat(localeName, {weekday})
const year = firstDayInWeek === 'Sunday' ? 2023 : firstDayInWeek === 'Monday' ? 2022 : 2023
const month = firstDayInWeek === 'Sunday' ? 4 : firstDayInWeek === 'Monday' ? 1 : 4
return [...Array(7).keys()]
.map((day) => format(new Date(Date.UTC(year, month, day))))
}
export function getFirstDayInMonth(month = 0, year = 2025) {
if (month === -1) {
month = 11
year--
}
if (month === 12) {
month = 0
year++
}
return new Date(year, month, 1).getDay()
}
export function getDaysInMonth(month = 0, year = 2025) {
month++
if (month === -1) {
month = 11
year--
}
if (month === 12) {
month = 0
year++
}
return new Date(year, month, 0).getDate()
}