From db369a807ef7ff1d95db3fae261947aa268dc2cb Mon Sep 17 00:00:00 2001 From: cottongin Date: Mon, 23 Mar 2026 11:31:35 -0400 Subject: [PATCH] feat: add getLocalDateKey, formatDayHeader, formatTimeOnly date helpers Made-with: Cursor --- frontend/src/utils/dateUtils.js | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/frontend/src/utils/dateUtils.js b/frontend/src/utils/dateUtils.js index 9d4f131..a16f0fb 100644 --- a/frontend/src/utils/dateUtils.js +++ b/frontend/src/utils/dateUtils.js @@ -56,3 +56,44 @@ export function isSunday(sqliteTimestamp) { 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', + }); +} +