new design and added class function
This commit is contained in:
34
utils.js
Normal file
34
utils.js
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user