fix(shifts): changed date format to UTC

This commit is contained in:
Matthieu Haineault 2025-11-04 14:50:07 -05:00
parent 457757a066
commit 0a3d4e2960

View File

@ -71,7 +71,7 @@ export class ShiftsUpsertService {
const regroup_by_date = new Map<string, number[]>();
ok_items.forEach(({ index, normed, timesheet_id }) => {
const day = new Date(normed.date.getFullYear(), normed.date.getMonth(), normed.date.getDate()).getTime();
const day = new Date(normed.date.getUTCFullYear(), normed.date.getUTCMonth(), normed.date.getUTCDate()).getTime();
const key = `${timesheet_id}|${day}`;
if (!regroup_by_date.has(key)) regroup_by_date.set(key, []);
regroup_by_date.get(key)!.push(index);
@ -150,7 +150,7 @@ export class ShiftsUpsertService {
for (const item of ok_items) {
const { index, dto, normed, timesheet_id } = item;
const day_key = new Date(normed.date.getFullYear(), normed.date.getMonth(), normed.date.getDate()).getTime();
const day_key = new Date(normed.date.getUTCFullYear(), normed.date.getUTCMonth(), normed.date.getUTCDate()).getTime();
const map_key = `${timesheet_id}|${day_key}`;
let existing = existing_map.get(map_key);
if (!existing) {
@ -293,7 +293,7 @@ export class ShiftsUpsertService {
const groups = new Map<string, { existing: { start: Date; end: Date; id: number }[], incoming: typeof planned_updates }>();
function key(timesheet: number, d: Date) {
const day_date = new Date(d.getFullYear(), d.getMonth(), d.getDate());
const day_date = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
return `${timesheet}|${day_date.getTime()}`;
}
@ -304,7 +304,7 @@ export class ShiftsUpsertService {
}
for (const group of unique_pairs.values()) {
const day_date = new Date(group.date.getFullYear(), group.date.getMonth(), group.date.getDate());
const day_date = new Date(group.date.getUTCFullYear(), group.date.getUTCMonth(), group.date.getUTCDate());
const existing = await tx.shifts.findMany({
where: { timesheet_id: group.timesheet_id, date: day_date },
select: { id: true, start_time: true, end_time: true },