Improvements todo created and small bugfixes
This commit is contained in:
@@ -22,6 +22,16 @@ export function formatMinutesAfter(minutes: number | null, reference: string = "
|
||||
return `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust minutes by the local timezone offset
|
||||
* @param utcMinutes - minutes from UTC midnight
|
||||
* @returns adjusted minutes for local time
|
||||
*/
|
||||
export function adjustForTimezone(utcMinutes: number): number {
|
||||
const offsetInMinutes = new Date().getTimezoneOffset();
|
||||
return utcMinutes - offsetInMinutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Date to datetime-local input value format (local time)
|
||||
* @param date - Date object
|
||||
@@ -111,6 +121,17 @@ export function timeToMinutes(timeStr: string): number {
|
||||
return hours * 60 + minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the offset from a reference time in local minutes
|
||||
* @param utcMinutesFromMidnight - minutes from UTC midnight
|
||||
* @param referenceHHMM - reference time as HH:MM string
|
||||
* @returns local offset from reference in minutes
|
||||
*/
|
||||
export function getLocalOffsetFromReference(utcMinutesFromMidnight: number, referenceHHMM: string): number {
|
||||
const localMinsFromMidnight = adjustForTimezone(utcMinutesFromMidnight);
|
||||
return localMinsFromMidnight - timeToMinutes(referenceHHMM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert total minutes to a human-readable string (e.g., "1h 30m" or "45m")
|
||||
* @param totalMinutes - Total number of minutes
|
||||
|
||||
Reference in New Issue
Block a user