feat(pres_mgmt): replace time_hours/time_format/datetime_format with single use_12h toggle
Three redundant store fields encoding the same AM/PM choice replaced with a single `use_12h: boolean` in PresMgmtLocState. iso_datetime_formatter gains a third param (use_12h: boolean | null = null) that auto-resolves 24h↔12h format name variants via a symmetric FORMAT_PAIRS lookup — null default leaves all ~100 existing call sites intact. Toggle surfaces in three places: Clock icon in session time chip (hidden button, same visual), event Options modal Display section, and session Options modal Display section. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,33 @@
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
// Format pairs: [24h base, 12h variant]. Only formats with both variants are listed.
|
||||
// Formats without a counterpart (ISO, date-only, week, etc.) are intentionally omitted —
|
||||
// iso_datetime_formatter passes those through unchanged regardless of use_12h.
|
||||
const FORMAT_PAIRS: [string, string][] = [
|
||||
['datetime_iso_no_seconds', 'datetime_iso_12_no_seconds'],
|
||||
['datetime_short', 'datetime_12_short'],
|
||||
['datetime_medium', 'datetime_12_medium'],
|
||||
['datetime_long', 'datetime_12_long'],
|
||||
['datetime_medium_sec', 'datetime_12_medium_sec'],
|
||||
['time_long', 'time_12_long'],
|
||||
['time_short', 'time_12_short'],
|
||||
['time_short_no_leading', 'time_12_short_no_leading'],
|
||||
];
|
||||
|
||||
// Build lookup maps from the pairs above. Both directions are derived from the same source.
|
||||
const TO_12H: Record<string, string> = Object.fromEntries(
|
||||
FORMAT_PAIRS.map(([h24, h12]) => [h24, h12])
|
||||
);
|
||||
const TO_24H: Record<string, string> = Object.fromEntries(
|
||||
FORMAT_PAIRS.map(([h24, h12]) => [h12, h24])
|
||||
);
|
||||
|
||||
export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
raw_datetime: null | string | Date = null,
|
||||
named_format: string = 'datetime_iso_no_seconds', // date_iso, datetime_iso_no_seconds
|
||||
time_24_hours: boolean = false
|
||||
// Pass true/false to resolve to the correct 12h or 24h variant automatically.
|
||||
// null (default) leaves named_format unchanged — all existing call sites unaffected.
|
||||
use_12h: boolean | null = null
|
||||
) {
|
||||
// console.log('*** iso_datetime_formatter() ***');
|
||||
|
||||
@@ -50,6 +74,12 @@ export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
raw_datetime = new Date(); // Get the current datetime if one was not passed.
|
||||
}
|
||||
|
||||
if (use_12h !== null) {
|
||||
named_format = use_12h
|
||||
? (TO_12H[named_format] ?? named_format)
|
||||
: (TO_24H[named_format] ?? named_format);
|
||||
}
|
||||
|
||||
let datetime_string = null;
|
||||
|
||||
switch (named_format) {
|
||||
|
||||
Reference in New Issue
Block a user