Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: consolidate client local date helpers (#4920)

[._.]/ Adam Eivy9c9db195f373
diff --git a/client/src/components/brain/tabs/DailyLogTab.jsx b/client/src/components/brain/tabs/DailyLogTab.jsx
index 33298d1652..1bfa5de2f3 100644
--- a/client/src/components/brain/tabs/DailyLogTab.jsx
+++ b/client/src/components/brain/tabs/DailyLogTab.jsx
@@ -11,7 +11,7 @@ import { onVoiceEvent, sendText, setDictation as setVoiceDictation } from '../..
import BrailleSpinner from '../../BrailleSpinner';
import useMounted from '../../../hooks/useMounted';
import { useVisibilityEvent } from '../../../hooks/useVisibilityEvent';
-import { formatDateFull } from '../../../utils/formatters';
+import { formatDateFull, localDateKey, shiftISODate } from '../../../utils/formatters';
// Autosave cadence. The debounce keeps us from PUTting on every keystroke;
// the max-wait ceiling exists because a pure debounce never fires at all
@@ -42,21 +42,6 @@ const upsertHistory = (prev, entry) => {
// value before the backend responds with its canonical "today" (which honors
// the user's configured timezone, so remote/VPN access doesn't desync the
// day). Replaced on mount via a GET /daily-log/today.
-const localToday = () => {
- const d = new Date();
- const y = d.getFullYear();
- const m = String(d.getMonth() + 1).padStart(2, '0');
- const day = String(d.getDate()).padStart(2, '0');
- return `${y}-${m}-${day}`;
-};
-
-const shiftDate = (iso, days) => {
- const [y, m, d] = iso.split('-').map(Number);
- const date = new Date(Date.UTC(y, m - 1, d));
- date.setUTCDate(date.getUTCDate() + days);
- return date.toISOString().slice(0, 10);
-};
-
// Append a dictated/typed segment to free-form journal text. Idempotent when
// the segment text is already present (socket replay / double-fire). Shared by
// the live socket path and the 409-retry merge so both stay byte-identical.
@@ -92,11 +77,11 @@ export const mergeMissingVoiceSegments = (localContent, serverEntry) => {
const STALE_JOURNAL_MAX_ATTEMPTS = 3;
export default function DailyLogTab() {
- const [date, setDate] = useState(localToday());
+ const [date, setDate] = useState(localDateKey());
// Backend today — resolved via GET /daily-log/today on mount so the
// "Today" button, disabled-forward-nav check, and isToday chip all match
- // the server's timezone. Falls back to localToday() until fetched.
- const [serverToday, setServerToday] = useState(localToday());
+ // the server's timezone. Falls back to localDateKey() until fetched.
+ const [serverToday, setServerToday] = useState(localDateKey());
const [entry, setEntry] = useState(null);
const [content, setContent] = useState('');
const [loading, setLoading] = useState(true);
@@ -202,7 +187,7 @@ export default function DailyLogTab() {
if (cancelled || !res?.date) return;
setServerToday(res.date);
// If we initialized with a wrong local date, hop to the real one.
- if (date === localToday() && res.date !== date) setDate(res.date);
+ if (date === localDateKey() && res.date !== date) setDate(res.date);
}).catch(() => null);
return () => { cancelled = true; };
// Only on mount — we intentionally don't re-run when date changes.
@@ -780,7 +765,7 @@ export default function DailyLogTab() {
<Menu size={16} />
</button>
<button
- onClick={() => setDate(shiftDate(date, -1))}
+ onClick={() => setDate(shiftISODate(date, -1))}
className="min-h-[44px] min-w-[44px] sm:min-h-[40px] sm:min-w-[40px] flex items-center justify-center rounded hover:bg-port-card text-gray-400 hover:text-white"
title="Previous day" aria-label="Previous day"
>
@@ -794,7 +779,7 @@ export default function DailyLogTab() {
className="min-w-0 bg-port-bg border border-port-border rounded px-2 min-h-[44px] sm:min-h-[40px] text-sm text-white"
/>
<button
- onClick={() => setDate(shiftDate(date, 1))}
+ onClick={() => setDate(shiftISODate(date, 1))}
disabled={date >= serverToday}
className="min-h-[44px] min-w-[44px] sm:min-h-[40px] sm:min-w-[40px] flex items-center justify-center rounded hover:bg-port-card text-gray-400 hover:text-white disabled:opacity-30"
title="Next day" aria-label="Next day"
diff --git a/client/src/components/meatspace/AlcoholChart.jsx b/client/src/components/meatspace/AlcoholChart.jsx
index ada8590444..3e52574a36 100644
--- a/client/src/components/meatspace/AlcoholChart.jsx
+++ b/client/src/components/meatspace/AlcoholChart.jsx
@@ -5,7 +5,7 @@ import {
import * as api from '../../services/api';
import BrailleSpinner from '../BrailleSpinner';
import useChartColors from '../../hooks/useChartColors.js';
-import { localDateStr } from './constants';
+import { localDateKey } from '../../utils/formatters';
const VIEWS = [
{ id: '7d', label: '7 Days', days: 7 },
@@ -28,8 +28,8 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey, onViewChange
const days = VIEWS.find(v => v.id === view)?.days || 30;
const from = new Date();
from.setDate(from.getDate() - days);
- const fromStr = localDateStr(from);
- const toStr = localDateStr();
+ const fromStr = localDateKey(from);
+ const toStr = localDateKey();
const entries = await api.getDailyAlcohol(fromStr, toStr).catch(() => []);
@@ -41,7 +41,7 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey, onViewChange
}
const cursor = new Date(from);
- let dateStr = localDateStr(cursor);
+ let dateStr = localDateKey(cursor);
while (dateStr <= toStr) {
const drinks = dateMap[dateStr] || 0;
chartData.push({
@@ -51,7 +51,7 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey, onViewChange
grams: Math.round(drinks * GRAMS_PER_STD_DRINK * 100) / 100
});
cursor.setDate(cursor.getDate() + 1);
- dateStr = localDateStr(cursor);
+ dateStr = localDateKey(cursor);
}
setData(chartData);
diff --git a/client/src/components/meatspace/NicotineChart.jsx b/client/src/components/meatspace/NicotineChart.jsx
index b1ea87a023..151df2faeb 100644
--- a/client/src/components/meatspace/NicotineChart.jsx
+++ b/client/src/components/meatspace/NicotineChart.jsx
@@ -5,7 +5,7 @@ import {
import * as api from '../../services/api';
import BrailleSpinner from '../BrailleSpinner';
import useChartColors from '../../hooks/useChartColors.js';
-import { localDateStr } from './constants';
+import { localDateKey } from '../../utils/formatters';
const VIEWS = [
{ id: '7d', label: '7 Days', days: 7 },
@@ -36,8 +36,8 @@ export default function NicotineChart({ onRefreshKey, onViewChange }) {
const days = VIEWS.find(v => v.id === view)?.days || 30;
const from = new Date();
from.setDate(from.getDate() - days);
- const fromStr = localDateStr(from);
- const toStr = localDateStr();
+ const fromStr = localDateKey(from);
+ const toStr = localDateKey();
const entries = await api.getDailyNicotine(fromStr, toStr).catch(() => []);
@@ -48,7 +48,7 @@ export default function NicotineChart({ onRefreshKey, onViewChange }) {
}
const cursor = new Date(from);
- let dateStr = localDateStr(cursor);
+ let dateStr = localDateKey(cursor);
while (dateStr <= toStr) {
const mg = dateMap[dateStr] || 0;
chartData.push({
@@ -57,7 +57,7 @@ export default function NicotineChart({ onRefreshKey, onViewChange }) {
mg
});
cursor.setDate(cursor.getDate() + 1);
- dateStr = localDateStr(cursor);
+ dateStr = localDateKey(cursor);
}
setData(chartData);
diff --git a/client/src/components/meatspace/constants.js b/client/src/components/meatspace/constants.js
index df0f692848..7652e0378b 100644
--- a/client/src/components/meatspace/constants.js
+++ b/client/src/components/meatspace/constants.js
@@ -109,10 +109,9 @@ export const STATUS_COLORS = {
unknown: 'text-gray-500'
};
-// Local date string (YYYY-MM-DD) — avoids UTC timezone shift from toISOString()
-export function localDateStr(d = new Date()) {
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
-}
+// Compatibility name for date-oriented MeatSpace consumers. The implementation
+// is canonical in utils/formatters so other client areas no longer duplicate it.
+export { localDateKey as localDateStr } from '../../utils/formatters';
// Shared day-of-week helpers (used by AlcoholTab, NicotineTab, etc.)
export const DAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
diff --git a/client/src/components/meatspace/tabs/AlcoholTab.jsx b/client/src/components/meatspace/tabs/AlcoholTab.jsx
index 08f8493bf2..4c0cc868f9 100644
--- a/client/src/components/meatspace/tabs/AlcoholTab.jsx
+++ b/client/src/components/meatspace/tabs/AlcoholTab.jsx
@@ -9,7 +9,8 @@ import { useConfirmDelete } from '../../../hooks/useConfirmDelete';
import AlcoholChart from '../AlcoholChart';
import AlcoholHrvCorrelation from '../AlcoholHrvCorrelation';
import StandardDrinkCalculator from '../StandardDrinkCalculator';
-import { dayOfWeek, localDateStr } from '../constants';
+import { dayOfWeek } from '../constants';
+import { localDateKey } from '../../../utils/formatters';
const ML_PER_OZ = 29.5735;
@@ -63,7 +64,7 @@ export default function AlcoholTab() {
const [oz, setOz] = useState('');
const [abv, setAbv] = useState('');
const [count, setCount] = useState(1);
- const [date, setDate] = useState(localDateStr());
+ const [date, setDate] = useState(localDateKey());
const [volumeUnit, setVolumeUnit] = useState('oz');
// Inline edit state
@@ -107,7 +108,7 @@ export default function AlcoholTab() {
const days = { '7d': 7, '30d': 30, '90d': 90 }[chartView] || 30;
const d = new Date();
d.setDate(d.getDate() - days);
- return { correlationFrom: localDateStr(d), correlationTo: localDateStr() };
+ return { correlationFrom: localDateKey(d), correlationTo: localDateKey() };
}, [chartView]);
useEffect(() => {
diff --git a/client/src/components/meatspace/tabs/NicotineTab.jsx b/client/src/components/meatspace/tabs/NicotineTab.jsx
index f82436b277..ebb0290339 100644
--- a/client/src/components/meatspace/tabs/NicotineTab.jsx
+++ b/client/src/components/meatspace/tabs/NicotineTab.jsx
@@ -8,7 +8,8 @@ import { FormField } from '../../ui/FormField';
import { useConfirmDelete } from '../../../hooks/useConfirmDelete';
import NicotineChart from '../NicotineChart';
import NicotineHealthCorrelation from '../NicotineHealthCorrelation';
-import { dayOfWeek, localDateStr } from '../constants';
+import { dayOfWeek } from '../constants';
+import { localDateKey } from '../../../utils/formatters';
const DAYS_PER_PAGE = 50;
@@ -28,7 +29,7 @@ export default function NicotineTab() {
const [buttonForm, setButtonForm] = useState({ name: '', mgPerUnit: '' });
// Form state
- const today = useMemo(() => localDateStr(), []);
+ const today = useMemo(() => localDateKey(), []);
const [product, setProduct] = useState('');
const [mgPerUnit, setMgPerUnit] = useState('');
const [count, setCount] = useState(1);
@@ -71,7 +72,7 @@ export default function NicotineTab() {
const days = { '7d': 7, '30d': 30, '90d': 90 }[chartView] || 30;
const d = new Date();
d.setDate(d.getDate() - days);
- return { correlationFrom: localDateStr(d), correlationTo: localDateStr() };
+ return { correlationFrom: localDateKey(d), correlationTo: localDateKey() };
}, [chartView]);
useEffect(() => {
diff --git a/client/src/pages/Timeline.jsx b/client/src/pages/Timeline.jsx
index 8e8402e41d..72de0cfa69 100644
--- a/client/src/pages/Timeline.jsx
+++ b/client/src/pages/Timeline.jsx
@@ -9,24 +9,7 @@ import PageHeader from '../components/PageHeader';
import TimelineImportPanels, { IMPORT_SOURCE_COUNT } from '../components/timeline/TimelineImportPanels';
import * as api from '../services/api';
import toast from '../components/ui/Toast';
-import { formatClockTime, formatDurationSec, formatWeekdayDate } from '../utils/formatters';
-
-// Local (browser-tz) YYYY-MM-DD for a Date — matches the server's local-day math
-// closely enough for defaulting the URL; the server is the source of truth for
-// which UTC instants fall in the day it returns.
-function localDateStr(d) {
- const y = d.getFullYear();
- const m = String(d.getMonth() + 1).padStart(2, '0');
- const day = String(d.getDate()).padStart(2, '0');
- return `${y}-${m}-${day}`;
-}
-
-function shiftDate(dateStr, days) {
- const [y, m, d] = dateStr.split('-').map(Number);
- const dt = new Date(y, m - 1, d);
- dt.setDate(dt.getDate() + days);
- return localDateStr(dt);
-}
+import { formatClockTime, formatDurationSec, formatWeekdayDate, localDateKey, shiftISODate } from '../utils/formatters';
const SOURCE_ICON = {
gmail: Mail,
@@ -172,7 +155,7 @@ export default function Timeline() {
// Browser-local fallbacks cover only the loading/error window before the
// server response supplies the authoritative `date` and `today`.
- const today = day?.today || localDateStr(new Date());
+ const today = day?.today || localDateKey();
const date = day?.date || urlDate || today;
const goto = (target) => navigate(target === today ? '/timeline' : `/timeline/${target}`);
@@ -200,7 +183,7 @@ export default function Timeline() {
<div className="flex items-center gap-2">
<button
type="button"
- onClick={() => goto(shiftDate(date, -1))}
+ onClick={() => goto(shiftISODate(date, -1))}
className="rounded border border-port-border bg-port-card p-2 hover:border-port-accent"
aria-label="Previous day"
>
@@ -216,7 +199,7 @@ export default function Timeline() {
/>
<button
type="button"
- onClick={() => goto(shiftDate(date, 1))}
+ onClick={() => goto(shiftISODate(date, 1))}
disabled={date >= today}
className="rounded border border-port-border bg-port-card p-2 hover:border-port-accent disabled:cursor-not-allowed disabled:opacity-40"
aria-label="Next day"
diff --git a/client/src/utils/README.md b/client/src/utils/README.md
index 9f3ad5ed58..6ab371f4c5 100644
--- a/client/src/utils/README.md
+++ b/client/src/utils/README.md
@@ -22,7 +22,7 @@ grep -i "what you want to do" client/src/utils/README.md
| Module | Purpose |
|---|---|
-| `formatters` | Date/time/duration/byte/word formatters (`clamp`, `formatBytes`, `formatDownloadGb` (decimal-GB model download size, "~29 GB"), `formatCompactCount`, `timeAgo`, `formatAgeDays` (age in whole DAYS — "412 days ago" — where `timeAgo` would collapse to "1y ago"; model-download lists), `formatTimecode`, `formatDurationMs`, `formatDateShort`, `formatContextTokens` (suffix-less context length, "4K"), `throughputLabel` (a measured model's speed as one label — tok/s where the runtime reported token counts, `~` prefixed when frame-counted, else chars/s; never both), `parseTimeoutMs`, `formatCooldown`, `recommendedRamGb`, `nameFromImageFilename`, `formatUsd` — one USD renderer (`signed` puts the minus outside the `$`; `trimWhole` drops `.00` on a typed round price) — `formatWeight` / `formatPercent` — round unit-converted floats (`170.35000000000002` → `170.4 lbs`) so raw binary precision never reaches a tile — `middleTruncate` — clip a long string from the MIDDLE so its distinguishing tail survives, where CSS `line-clamp`/`text-overflow` always eats the end — …) plus timeout-input bounds and `getAppName`. Do not re-define formatters inside components. **Never write `new Date(x).toLocaleDateString()` inline** — pick the helper for the shape you want: `formatDateNumeric` ("3/5/2026", compact cells), `formatDateShort` ("Mar 5, 2026"), `formatDate` ("March 5, 2026"), `formatDateFull` ("Saturday, March 5, 2026"), `formatWeekdayDate` ("Monday, Mar 5", `{ weekday, year }`), `formatMonthDay` ("Mar 5"), `formatMonthYear` ("March 2026"), `formatWeekdayShort` ("Mon"), `formatWeekdayTime` ("Mon, 7:00 AM"), `formatTimeOfDay` ("1:30 PM"), `formatTimeOfDaySeconds` ("1:30:45 PM", log/queue rows), `formatClockTime` ("02:30:45 PM"; `{ seconds, hour12, timeZone }`), `formatDateTime`. All of them anchor a bare `YYYY-MM-DD` at LOCAL midnight (a naive `new Date('2026-03-05')` is UTC midnight and renders as the previous day west of Greenwich) and take a fallback instead of rendering the literal "Invalid Date". |
+| `formatters` | Date/time/duration/byte/word formatters (`clamp`, `formatBytes`, `formatDownloadGb` (decimal-GB model download size, "~29 GB"), `formatCompactCount`, `timeAgo`, `formatAgeDays` (age in whole DAYS — "412 days ago" — where `timeAgo` would collapse to "1y ago"; model-download lists), `localDateKey` (browser-local `YYYY-MM-DD`), `shiftISODate` (DST-safe calendar-day shifts), `formatTimecode`, `formatDurationMs`, `formatDateShort`, `formatContextTokens` (suffix-less context length, "4K"), `throughputLabel` (a measured model's speed as one label — tok/s where the runtime reported token counts, `~` prefixed when frame-counted, else chars/s; never both), `parseTimeoutMs`, `formatCooldown`, `recommendedRamGb`, `nameFromImageFilename`, `formatUsd` — one USD renderer (`signed` puts the minus outside the `$`; `trimWhole` drops `.00` on a typed round price) — `formatWeight` / `formatPercent` — round unit-converted floats (`170.35000000000002` → `170.4 lbs`) so raw binary precision never reaches a tile — `middleTruncate` — clip a long string from the MIDDLE so its distinguishing tail survives, where CSS `line-clamp`/`text-overflow` always eats the end — …) plus timeout-input bounds and `getAppName`. Do not re-define formatters inside components. **Never write `new Date(x).toLocaleDateString()` inline** — pick the helper for the shape you want: `formatDateNumeric` ("3/5/2026", compact cells), `formatDateShort` ("Mar 5, 2026"), `formatDate` ("March 5, 2026"), `formatDateFull` ("Saturday, March 5, 2026"), `formatWeekdayDate` ("Monday, Mar 5", `{ weekday, year }`), `formatMonthDay` ("Mar 5"), `formatMonthYear` ("March 2026"), `formatWeekdayShort` ("Mon"), `formatWeekdayTime` ("Mon, 7:00 AM"), `formatTimeOfDay` ("1:30 PM"), `formatTimeOfDaySeconds` ("1:30:45 PM", log/queue rows), `formatClockTime` ("02:30:45 PM"; `{ seconds, hour12, timeZone }`), `formatDateTime`. Date display helpers anchor a bare `YYYY-MM-DD` at LOCAL midnight (a naive `new Date('2026-03-05')` is UTC midnight and renders as the previous day west of Greenwich) and take a fallback instead of rendering the literal "Invalid Date". |
| `cronHelpers` | Cron preset list, `isCronExpression` detection, `describeCron` human-readable rendering, and `JOB_INTERVAL_OPTIONS` — the interval-mode cadences for autonomous jobs, mirroring the server's `INTERVAL_OPTIONS`. Import it rather than re-declaring the list in a scheduling component. |
| `markdownText` | `markdownToPlainText(md)` — flatten markdown source to one plain-text string for a clamped preview: strips heading/list/blockquote/fence markers, unwraps emphasis, inline code and links, images → `[alt]`, collapses blank-line runs. Use whenever a card previews arbitrary agent-authored markdown — `line-clamp-N` does not clamp a subtree of block elements, and foreign `##` headings would otherwise join the page's heading outline. Underscore emphasis is word-boundary gated and `__…__` needs interior whitespace, so stack frames and user-agent strings (`10_15_7`, `__init__`) are never silently rewritten. `dropsMarkupWhenFlattened(md)` — did the flatten lose actual markup, as opposed to only normalizing whitespace? Gates a "Show more" disclosure so a short-but-lossy body stays reachable without putting a toggle on every body that merely lost a trailing newline. |
| `timeWindow` | Time-of-day window math (`isInTimeWindow`, `timeStringToMinutes`) and morning-layout auto-switch helpers (`pickActiveLayoutId`, `recordManualLayoutPick`). |
diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.js
index 017789a63f..2e439324a9 100644
--- a/client/src/utils/formatters.js
+++ b/client/src/utils/formatters.js
@@ -23,6 +23,31 @@ export function formatTime(timestamp) {
const DATE_ONLY_RE = /^\d{4}-\d{2}-\d{2}$/;
+/**
+ * Format a Date as a browser-local YYYY-MM-DD calendar key.
+ * Unlike `toISOString()`, this preserves the user's local day near UTC boundaries.
+ * @param {Date} date
+ * @returns {string}
+ */
+export function localDateKey(date = new Date()) {
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const day = String(date.getDate()).padStart(2, '0');
+ return `${year}-${month}-${day}`;
+}
+
+/**
+ * Shift a YYYY-MM-DD calendar key by whole days without local-time/DST drift.
+ * @param {string} dateKey
+ * @param {number} days
+ * @returns {string}
+ */
+export function shiftISODate(dateKey, days) {
+ const [year, month, day] = dateKey.split('-').map(Number);
+ const shifted = new Date(Date.UTC(year, month - 1, day + days));
+ return shifted.toISOString().slice(0, 10);
+}
+
/**
* Coerce a Date / ISO timestamp / epoch ms into a Date for display.
*
@@ -763,4 +788,3 @@ export function clamp(n, min, max) {
export function capitalize(s) {
return typeof s === 'string' && s.length ? s[0].toUpperCase() + s.slice(1) : s;
}
-
diff --git a/client/src/utils/formatters.test.js b/client/src/utils/formatters.test.js
index 70a78cf336..1aba612984 100644
--- a/client/src/utils/formatters.test.js
+++ b/client/src/utils/formatters.test.js
@@ -5,8 +5,26 @@ import {
formatWeight, formatPercent, formatUsd, formatBytes,
formatDateNumeric, formatTimeOfDaySeconds, formatClockTime, formatWeekdayDate,
formatMonthDay, formatMonthYear, formatWeekdayShort, formatWeekdayTime, formatDateFull, formatDateShort, formatDateTime,
+ localDateKey, shiftISODate,
} from './formatters.js';
+describe('calendar date keys', () => {
+ it('formats a Date using its local calendar fields', () => {
+ expect(localDateKey(new Date(2026, 0, 5, 23, 30))).toBe('2026-01-05');
+ });
+
+ it('shifts ISO dates across month, year, and leap-day boundaries', () => {
+ expect(shiftISODate('2025-12-31', 1)).toBe('2026-01-01');
+ expect(shiftISODate('2026-03-01', -1)).toBe('2026-02-28');
+ expect(shiftISODate('2028-02-28', 1)).toBe('2028-02-29');
+ });
+
+ it('shifts calendar days without DST-boundary drift', () => {
+ expect(shiftISODate('2026-03-08', 1)).toBe('2026-03-09');
+ expect(shiftISODate('2026-11-01', 1)).toBe('2026-11-02');
+ });
+});
+
describe('clamp', () => {
it('returns value unchanged when within [min, max]', () => {
expect(clamp(5, 0, 10)).toBe(5);
diff --git a/client/src/utils/timeWindow.js b/client/src/utils/timeWindow.js
index f968c12935..bc677896d5 100644
--- a/client/src/utils/timeWindow.js
+++ b/client/src/utils/timeWindow.js
@@ -4,6 +4,8 @@
// zero-padded `HHMM_STRICT_RE`. Keep the two literals in sync (parity-tested
// in timeWindow.test.js and timezone.test.js).
+import { localDateKey } from './formatters.js';
+
export const TIME_STRING_RE = /^([01]\d|2[0-3]):[0-5]\d$/;
export function isValidTimeString(s) {
@@ -38,12 +40,6 @@ export const MORNING_DEFAULT_WINDOW = Object.freeze({ start: '06:00', end: '11:0
// localStorage key per-day so each new day clears the user's daily lock and
// a window-layout can auto-activate again.
const USER_PICK_KEY_PREFIX = 'dashboard:userPick:';
-const localDateKey = (now = new Date()) => {
- const y = now.getFullYear();
- const m = String(now.getMonth() + 1).padStart(2, '0');
- const d = String(now.getDate()).padStart(2, '0');
- return `${y}-${m}-${d}`;
-};
const userPickKey = (now = new Date()) => `${USER_PICK_KEY_PREFIX}${localDateKey(now)}`;
// Drop stale `dashboard:userPick:*` keys older than today so the key count