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