diff --git a/resources/js/lib/utils.ts b/resources/js/lib/utils.ts index 09d8a2c..5bd5038 100644 --- a/resources/js/lib/utils.ts +++ b/resources/js/lib/utils.ts @@ -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 {