feat: Ajout des composants modal, accordeon, datetime avec selecteur d'heure à la molette (#56)
Release / release (push) Successful in 2m38s
Release / release (push) Successful in 2m38s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié --------- Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-authored-by: matthieu <matthieu@yuno.malio.fr> Reviewed-on: #56 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #56.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export interface TimeParts {
|
||||
hours: number
|
||||
minutes: number
|
||||
}
|
||||
|
||||
export function clampHours(value: number): number {
|
||||
if (Number.isNaN(value)) return 0
|
||||
return Math.min(23, Math.max(0, Math.trunc(value)))
|
||||
}
|
||||
|
||||
export function clampMinutes(value: number): number {
|
||||
if (Number.isNaN(value)) return 0
|
||||
return Math.min(59, Math.max(0, Math.trunc(value)))
|
||||
}
|
||||
|
||||
export function padSegment(value: number): string {
|
||||
return value.toString().padStart(2, '0')
|
||||
}
|
||||
|
||||
export function parseTime(value: string | null | undefined): TimeParts | null {
|
||||
if (!value) return null
|
||||
const match = /^(\d{1,2}):(\d{1,2})$/.exec(value.trim())
|
||||
if (!match) return null
|
||||
return {
|
||||
hours: clampHours(Number.parseInt(match[1], 10)),
|
||||
minutes: clampMinutes(Number.parseInt(match[2], 10)),
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTime(hours: number, minutes: number): string {
|
||||
return `${padSegment(clampHours(hours))}:${padSegment(clampMinutes(minutes))}`
|
||||
}
|
||||
Reference in New Issue
Block a user