feat: add getLocalDateKey, formatDayHeader, formatTimeOnly date helpers
Made-with: Cursor
This commit is contained in:
@@ -56,3 +56,44 @@ export function isSunday(sqliteTimestamp) {
|
|||||||
return parseUTCTimestamp(sqliteTimestamp).getDay() === 0;
|
return parseUTCTimestamp(sqliteTimestamp).getDay() === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a locale-independent date key for grouping sessions by local calendar day
|
||||||
|
* @param {string} sqliteTimestamp
|
||||||
|
* @returns {string} - e.g., "2026-03-23"
|
||||||
|
*/
|
||||||
|
export function getLocalDateKey(sqliteTimestamp) {
|
||||||
|
const d = parseUTCTimestamp(sqliteTimestamp);
|
||||||
|
const year = d.getFullYear();
|
||||||
|
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(d.getDate()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a SQLite timestamp as a day header string (e.g., "Sunday, Mar 23, 2026")
|
||||||
|
* @param {string} sqliteTimestamp
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function formatDayHeader(sqliteTimestamp) {
|
||||||
|
const d = parseUTCTimestamp(sqliteTimestamp);
|
||||||
|
return d.toLocaleDateString(undefined, {
|
||||||
|
weekday: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a SQLite timestamp as a time-only string (e.g., "7:30 PM")
|
||||||
|
* @param {string} sqliteTimestamp
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function formatTimeOnly(sqliteTimestamp) {
|
||||||
|
const d = parseUTCTimestamp(sqliteTimestamp);
|
||||||
|
return d.toLocaleTimeString(undefined, {
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: '2-digit',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user