mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-14 11:12:16 +01:00
fix DST boundary issue in timesheets
This commit is contained in:
@@ -26,6 +26,15 @@ interface Interval {
|
|||||||
end: Dayjs;
|
end: Dayjs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function localDayBounds(date: string, tz: string): { dayStart: Dayjs; dayEnd: Dayjs } {
|
||||||
|
const dayjs = getDayJsInstance();
|
||||||
|
const localDayStart = dayjs.tz(`${date} 00:00:00`, tz);
|
||||||
|
return {
|
||||||
|
dayStart: localDayStart.utc(),
|
||||||
|
dayEnd: localDayStart.add(1, 'day').utc(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect entries that intersect the day `[dayStart, dayEnd)`, clipped
|
* Collect entries that intersect the day `[dayStart, dayEnd)`, clipped
|
||||||
* to those bounds. Running entries use `nowDayjs` as their end.
|
* to those bounds. Running entries use `nowDayjs` as their end.
|
||||||
@@ -76,8 +85,7 @@ export function findFreeWindowOnDay(
|
|||||||
if (requiredSeconds <= 0) return null;
|
if (requiredSeconds <= 0) return null;
|
||||||
|
|
||||||
const dayjs = getDayJsInstance();
|
const dayjs = getDayJsInstance();
|
||||||
const dayStart = dayjs.tz(`${date} 00:00:00`, tz).utc();
|
const { dayStart, dayEnd } = localDayBounds(date, tz);
|
||||||
const dayEnd = dayStart.add(1, 'day');
|
|
||||||
|
|
||||||
if (requiredSeconds > dayEnd.diff(dayStart, 'second')) return null;
|
if (requiredSeconds > dayEnd.diff(dayStart, 'second')) return null;
|
||||||
|
|
||||||
@@ -149,8 +157,7 @@ export function freeGapSecondsAfter(
|
|||||||
now?: string | Dayjs
|
now?: string | Dayjs
|
||||||
): number {
|
): number {
|
||||||
const dayjs = getDayJsInstance();
|
const dayjs = getDayJsInstance();
|
||||||
const dayStart = dayjs.tz(`${date} 00:00:00`, tz).utc();
|
const { dayStart, dayEnd } = localDayBounds(date, tz);
|
||||||
const dayEnd = dayStart.add(1, 'day');
|
|
||||||
const cursorDjs = dayjs.utc(cursor);
|
const cursorDjs = dayjs.utc(cursor);
|
||||||
|
|
||||||
if (cursorDjs.isSameOrAfter(dayEnd)) return 0;
|
if (cursorDjs.isSameOrAfter(dayEnd)) return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user