feat : first commit
This commit is contained in:
7
frontend/utils/api.ts
Normal file
7
frontend/utils/api.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export type HydraCollection<T> = {
|
||||
'hydra:member'?: T[]
|
||||
}
|
||||
|
||||
export const extractItems = <T>(data: HydraCollection<T> | T[]): T[] => {
|
||||
return Array.isArray(data) ? data : data['hydra:member'] ?? []
|
||||
}
|
||||
22
frontend/utils/date.ts
Normal file
22
frontend/utils/date.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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()]
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user