fixed date issue v1
This commit is contained in:
@@ -84,13 +84,23 @@ export function formatLocalDate(input?: string | Date): string {
|
||||
if (input instanceof Date) {
|
||||
if (isNaN(input.getTime())) return "";
|
||||
|
||||
// ALWAYS use the local calendar fields for Date objects.
|
||||
// This avoids day-flips when a Date was constructed from an ISO instant
|
||||
// and the browser's timezone would otherwise show a different calendar day.
|
||||
const y = input.getFullYear();
|
||||
const m = `${input.getMonth() + 1}`.padStart(2, "0");
|
||||
const d = `${input.getDate()}`.padStart(2, "0");
|
||||
return `${y}-${m}-${d}`;
|
||||
// HYBRID LOGIC:
|
||||
// - If this Date was likely created from an ISO instant at UTC midnight
|
||||
// (e.g. "2025-10-15T00:00:00Z"), then getUTCHours() === 0 but getHours()
|
||||
// will be non-zero in most non-UTC timezones. In that case use UTC date
|
||||
// parts to preserve the original calendar day.
|
||||
// - Otherwise use the local calendar fields (safe for local-midnight Dates).
|
||||
const utcHours = input.getUTCHours();
|
||||
const localHours = input.getHours();
|
||||
const useUTC = utcHours === 0 && localHours !== 0;
|
||||
|
||||
const year = useUTC ? input.getUTCFullYear() : input.getFullYear();
|
||||
const month = useUTC ? input.getUTCMonth() + 1 : input.getMonth() + 1;
|
||||
const day = useUTC ? input.getUTCDate() : input.getDate();
|
||||
|
||||
const m = `${month}`.padStart(2, "0");
|
||||
const d = `${day}`.padStart(2, "0");
|
||||
return `${year}-${m}-${d}`;
|
||||
}
|
||||
|
||||
return "";
|
||||
@@ -166,7 +176,6 @@ export function formatDateToHumanReadable(dateInput?: string | Date): string {
|
||||
return "Invalid Date";
|
||||
}
|
||||
|
||||
|
||||
// ---------------- OCR Date helper --------------------------
|
||||
/**
|
||||
* Convert any OCR numeric-ish value into a number.
|
||||
|
||||
Reference in New Issue
Block a user