Skip to content

A self-hosted media server and file management system

fix: Datepicker is not timezone agnostic Fixes #300

aminnausin00bec3240bbb
diff --git a/resources/js/service/util.ts b/resources/js/service/util.ts
index a2527ee7..ac489bca 100644
--- a/resources/js/service/util.ts
+++ b/resources/js/service/util.ts
@@ -115,10 +115,14 @@ export function formatInteger(integer: number, minimumDigits = 2) {
export function toCalendarFormattedDate(date?: string, format?: Intl.DateTimeFormatOptions) {
if (!date) return null;
- const rawDate = new Date(date);
+ // force local time parsing in all browsers
+ // new Date("YYYY-MM-DD") is treated as UTC midnight
+ // which shifts the date back a day in negative-offset timezones like EST
+ // TODO: instead of parsing the date here, datepicker should store a raw db compatible date without a timezone component internally, and have formatted display output separately
+ const localDate = new Date(date.replace(/-/g, '/'));
const defaultDateFormat = { month: 'long', day: '2-digit', year: 'numeric' } satisfies Intl.DateTimeFormatOptions;
- return rawDate.toLocaleDateString('en-CA', format ?? defaultDateFormat).replaceAll('.', '');
+ return localDate.toLocaleDateString('en-CA', format ?? defaultDateFormat).replaceAll('.', '');
}
/**