feat: add toGregorianDateLabel function and update date displays across multiple pages

This commit is contained in:
estifanos
2026-07-31 10:37:04 +00:00
parent 48bc31d321
commit f736e4ddac
5 changed files with 31 additions and 24 deletions

View File

@@ -59,22 +59,23 @@ const ETH_FORMATTERS = {
formatMonthDropdown: (month: Date) => ethMonthName(month),
};
// Local-date parse/format for the "YYYY-MM-DD" wire format (matches native
// <input type="date"> semantics). Deliberately NOT `new Date(iso)` (parses as
// UTC midnight, off-by-one in negative-offset zones) and NOT
// `.toISOString()` (shifts by the local offset when formatting) — same class
// of bug the UTC-noon workaround above already had to fix once in this file.
// Wire format is a full ISO-8601 instant string (e.g.
// "2026-07-31T00:00:00.000Z"), what the backend expects for date fields.
// The picker only selects a calendar day, so the time is pinned to UTC
// midnight — reading back with getUTC*() (not local get*()) keeps the
// calendar day stable regardless of the runtime's timezone, avoiding the
// same off-by-one class of bug the UTC-noon workaround above exists for.
function parseISO(value?: string | null): Date | null {
if (!value) return null;
const [y, m, d] = value.split('-').map(Number);
return y && m && d ? new Date(y, m - 1, d) : null;
const d = new Date(value);
if (isNaN(d.getTime())) return null;
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
}
function formatISO(date: Date): string {
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, '0');
const d = String(date.getDate()).padStart(2, '0');
return `${y}-${m}-${d}`;
return new Date(
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()),
).toISOString();
}
export function toEthiopicDateLabel(date: Date | string): string {
@@ -88,6 +89,12 @@ export function toEthiopicDateLabel(date: Date | string): string {
}
}
export function toGregorianDateLabel(date: Date | string): string {
const d = typeof date === 'string' ? parseISO(date) : date;
if (!d) return '';
return d.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
}
const YEAR_DROPDOWN_END = new Date(new Date().getFullYear() + 50, 11, 31);
export interface AmharicDatePickerProps {