Not sure what happened here...
This commit is contained in:
@@ -19,6 +19,15 @@ export function formatMinutesAfter(minutes, reference = "04:00") {
|
||||
const mins = normalizedMinutes % 60;
|
||||
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) {
|
||||
const offsetInMinutes = new Date().getTimezoneOffset();
|
||||
return utcMinutes - offsetInMinutes;
|
||||
}
|
||||
/**
|
||||
* Convert a Date to datetime-local input value format (local time)
|
||||
* @param date - Date object
|
||||
@@ -99,9 +108,20 @@ export function getToday() {
|
||||
* @returns total minutes
|
||||
*/
|
||||
export function timeToMinutes(timeStr) {
|
||||
if (!timeStr || typeof timeStr !== 'string') return 0;
|
||||
const [hours, minutes] = timeStr.split(":").map(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, referenceHHMM) {
|
||||
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