23 lines
710 B
TypeScript
23 lines
710 B
TypeScript
export const toYmd = (year: number, month: number, day: number) => {
|
|
const mm = String(month + 1).padStart(2, '0')
|
|
const dd = String(day).padStart(2, '0')
|
|
return `${year}-${mm}-${dd}`
|
|
}
|
|
|
|
export const normalizeDate = (value: string) => value.slice(0, 10)
|
|
|
|
export const getDaysInMonth = (year: number, month: number) => {
|
|
const total = new Date(year, month + 1, 0).getDate()
|
|
const weekdays = ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam']
|
|
|
|
return Array.from({ length: total }, (_, index) => {
|
|
const day = index + 1
|
|
const dateObj = new Date(year, month, day)
|
|
return {
|
|
date: toYmd(year, month, day),
|
|
label: String(day),
|
|
weekday: weekdays[dateObj.getDay()]
|
|
}
|
|
})
|
|
}
|