35 lines
943 B
JavaScript
35 lines
943 B
JavaScript
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()
|
|
}
|