fix : wip
This commit is contained in:
@@ -6,6 +6,74 @@ export const toYmd = (year: number, month: number, day: number) => {
|
||||
|
||||
export const normalizeDate = (value: string) => value.slice(0, 10)
|
||||
|
||||
export const parseYmd = (value: string) => {
|
||||
const [year, month, day] = value.split('-').map(Number)
|
||||
if (!year || !month || !day) return null
|
||||
return new Date(year, month - 1, day)
|
||||
}
|
||||
|
||||
export const formatDateLongFr = (date: Date) => {
|
||||
const label = new Intl.DateTimeFormat('fr-FR', {
|
||||
weekday: 'long',
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
}).format(date)
|
||||
|
||||
return label.charAt(0).toUpperCase() + label.slice(1)
|
||||
}
|
||||
|
||||
export const formatWeekDayHeaderFr = (dateYmd: string) => {
|
||||
const parsed = parseYmd(dateYmd)
|
||||
if (!parsed) return dateYmd
|
||||
return new Intl.DateTimeFormat('fr-FR', {
|
||||
weekday: 'short',
|
||||
day: '2-digit',
|
||||
month: '2-digit'
|
||||
}).format(parsed)
|
||||
}
|
||||
|
||||
export const getWeekStartDate = (date: Date) => {
|
||||
const copy = new Date(date)
|
||||
const day = copy.getDay()
|
||||
const diff = day === 0 ? -6 : 1 - day
|
||||
copy.setDate(copy.getDate() + diff)
|
||||
copy.setHours(0, 0, 0, 0)
|
||||
return copy
|
||||
}
|
||||
|
||||
export const getTodayYmd = () => {
|
||||
const date = new Date()
|
||||
return toYmd(date.getFullYear(), date.getMonth(), date.getDate())
|
||||
}
|
||||
|
||||
export const getOffsetFromTodayYmd = (offset: number) => {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() + offset)
|
||||
return toYmd(date.getFullYear(), date.getMonth(), date.getDate())
|
||||
}
|
||||
|
||||
export const shiftYmd = (value: string, days: number) => {
|
||||
const parsed = parseYmd(value)
|
||||
if (!parsed) return null
|
||||
parsed.setDate(parsed.getDate() + days)
|
||||
return toYmd(parsed.getFullYear(), parsed.getMonth(), parsed.getDate())
|
||||
}
|
||||
|
||||
export const formatWeekRangeFr = (date: Date) => {
|
||||
const start = getWeekStartDate(date)
|
||||
const end = new Date(start)
|
||||
end.setDate(start.getDate() + 6)
|
||||
|
||||
const formatter = new Intl.DateTimeFormat('fr-FR', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
})
|
||||
|
||||
return `Semaine du ${formatter.format(start)} au ${formatter.format(end)}`
|
||||
}
|
||||
|
||||
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']
|
||||
|
||||
31
frontend/utils/employee.ts
Normal file
31
frontend/utils/employee.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Employee } from '~/services/dto/employee'
|
||||
|
||||
export const compareEmployeesInSite = (employeeA: Employee, employeeB: Employee) => {
|
||||
const orderA = employeeA.displayOrder ?? 0
|
||||
const orderB = employeeB.displayOrder ?? 0
|
||||
if (orderA !== orderB) return orderA - orderB
|
||||
|
||||
const lastNameA = employeeA.lastName ?? ''
|
||||
const lastNameB = employeeB.lastName ?? ''
|
||||
if (lastNameA !== lastNameB) return lastNameA.localeCompare(lastNameB, 'fr')
|
||||
|
||||
const firstNameA = employeeA.firstName ?? ''
|
||||
const firstNameB = employeeB.firstName ?? ''
|
||||
return firstNameA.localeCompare(firstNameB, 'fr')
|
||||
}
|
||||
|
||||
export const compareEmployeesBySiteAndOrder = (employeeA: Employee, employeeB: Employee) => {
|
||||
const siteOrderA = employeeA.site?.displayOrder ?? 0
|
||||
const siteOrderB = employeeB.site?.displayOrder ?? 0
|
||||
if (siteOrderA !== siteOrderB) return siteOrderA - siteOrderB
|
||||
|
||||
const siteNameA = employeeA.site?.name ?? ''
|
||||
const siteNameB = employeeB.site?.name ?? ''
|
||||
if (siteNameA !== siteNameB) return siteNameA.localeCompare(siteNameB, 'fr')
|
||||
|
||||
return compareEmployeesInSite(employeeA, employeeB)
|
||||
}
|
||||
|
||||
export const sortEmployeesBySiteAndOrder = (employees: Employee[]) => {
|
||||
return [...employees].sort(compareEmployeesBySiteAndOrder)
|
||||
}
|
||||
Reference in New Issue
Block a user