targo-backend/src/modules/shifts/helpers/shifts-date-time-helpers.ts

26 lines
820 B
TypeScript

export function timeFromHHMM(hhmm: string): Date {
const [h, m] = hhmm.split(':').map(Number);
return new Date(1970, 0, 1, h, m, 0, 0);
}
export function toDateOnly(ymd: string): Date {
const y = Number(ymd.slice(0, 4));
const m = Number(ymd.slice(5, 7)) - 1;
const d = Number(ymd.slice(8, 10));
return new Date(y, m, d, 0, 0, 0, 0);
}
export function weekStartSunday(date_local: Date): Date {
const start = new Date(date_local.getFullYear(), date_local.getMonth(), date_local.getDate());
const dow = start.getDay(); // 0 = dimanche
start.setDate(start.getDate() - dow);
start.setHours(0, 0, 0, 0);
return start;
}
export function formatHHmm(t: Date): string {
const hh = String(t.getHours()).padStart(2, '0');
const mm = String(t.getMinutes()).padStart(2, '0');
return `${hh}:${mm}`;
}