fix(badges): display print timestamps in local browser time instead of UTC
The backend returns naive UTC datetime strings (no Z suffix). dayjs was treating them as local time, so staff in ET saw UTC times. Added treat_as_utc param to iso_datetime_formatter (default false, zero breakage to existing call sites) that appends Z before parsing so dayjs converts to browser-local time on display. Applied to all print timestamp call sites in badge list (first/last print visible row + debug row) and to created_on/updated_on in the debug row. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,11 @@ export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
named_format: string = 'datetime_iso_no_seconds', // date_iso, datetime_iso_no_seconds
|
||||
// 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
|
||||
use_12h: boolean | null = null,
|
||||
// When true, treats a naive datetime string (no Z / offset) as UTC so dayjs
|
||||
// converts it to local browser time on display. Use for timestamps stored as
|
||||
// UTC in the DB but returned without a timezone indicator.
|
||||
treat_as_utc: boolean = false
|
||||
) {
|
||||
// console.log('*** iso_datetime_formatter() ***');
|
||||
|
||||
@@ -74,6 +78,12 @@ export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
raw_datetime = new Date(); // Get the current datetime if one was not passed.
|
||||
}
|
||||
|
||||
// Append 'Z' to naive UTC strings so dayjs converts to local browser time.
|
||||
// Guards against double-appending if the backend ever adds timezone info.
|
||||
if (treat_as_utc && typeof raw_datetime === 'string' && !raw_datetime.match(/Z$|[+-]\d{2}:?\d{2}$/)) {
|
||||
raw_datetime = raw_datetime + 'Z';
|
||||
}
|
||||
|
||||
if (use_12h !== null) {
|
||||
named_format = use_12h
|
||||
? (TO_12H[named_format] ?? named_format)
|
||||
|
||||
Reference in New Issue
Block a user