Drying out
This commit is contained in:
@@ -62,6 +62,45 @@ export function formatElapsedTime(utcTimestamp: string): string {
|
||||
return `${mins}m`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a Date or ISO string to a human-readable datetime string (YYYY-MM-DD HH:mm)
|
||||
* @param date - Date object or ISO string
|
||||
* @returns formatted datetime string
|
||||
*/
|
||||
export function formatDateTime(date: Date | string): string {
|
||||
const d = typeof date === 'string' ? new Date(date) : date;
|
||||
return d.toLocaleString('sv-SE', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false
|
||||
}).replace(',', ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a datetime-local input value to an ISO UTC string
|
||||
* @param inputValue - datetime-local string (YYYY-MM-DDTHH:mm)
|
||||
* @returns ISO UTC string
|
||||
*/
|
||||
export function toUTCFromLocalInput(inputValue: string): string {
|
||||
const d = new Date(inputValue);
|
||||
return d.toISOString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate duration in minutes between two dates or ISO strings
|
||||
* @param start - Start date object or ISO string
|
||||
* @param end - End date object or ISO string
|
||||
* @returns duration in minutes
|
||||
*/
|
||||
export function getDurationMinutes(start: Date | string, end: Date | string): number {
|
||||
const startDate = typeof start === 'string' ? new Date(start) : start;
|
||||
const endDate = typeof end === 'string' ? new Date(end) : end;
|
||||
return Math.round((endDate.getTime() - startDate.getTime()) / 60000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp a date to day boundaries (start or end of day)
|
||||
* @param date - Date to clamp
|
||||
|
||||
Reference in New Issue
Block a user