Fix: wrong calculation of time spans

This commit is contained in:
2026-03-12 15:18:10 +01:00
parent 237ea05a45
commit 49aa8bc413
+11 -3
View File
@@ -120,15 +120,23 @@ export function millisFromNow(value: string | Date): number {
}
export function minutesFromNow(value: string | Date): number {
return Math.round(millisFromNow(value) / (1000 * 60))
const mins = millisFromNow(value) / (1000 * 60);
return Math.sign(mins) * Math.floor(Math.abs(mins));
}
export function hoursFromNow(value: string | Date): number {
return Math.round(millisFromNow(value) / (1000 * 60 * 60))
const hrs = millisFromNow(value) / (1000 * 60 * 60);
return Math.sign(hrs) * Math.floor(Math.abs(hrs));
}
export function daysFromNow(value: string | Date): number {
return Math.round(millisFromNow(value) / (1000 * 60 * 60 * 24))
const date = (typeof value === 'string') ? new Date(value) : value;
const today = new Date();
const utcDate = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
const utcToday = Date.UTC(today.getFullYear(), today.getMonth(), today.getDate());
return Math.round((utcDate - utcToday) / (1000 * 60 * 60 * 24));
}
export function isThisHour(value: Date | string): boolean {