From d819ff093d8386f39cc9e3c85ff4a2bcfa9af331 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 18 May 2021 10:59:48 +0200 Subject: [PATCH] Fix date rendering with 12h format in flatpickr inputs --- www/admin/inner.js | 4 ++++ www/lib/calendar/date-picker.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/www/admin/inner.js b/www/admin/inner.js index 8e3ed16d2..527b081c5 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -1314,19 +1314,23 @@ define([ var $start = $(start); var $end = $(end); var is24h = false; + var dateFormat = "Y-m-d H:i"; try { is24h = !new Intl.DateTimeFormat(navigator.language, { hour: 'numeric' }).format(0).match(/AM/); } catch (e) {} + if (!is24h) { dateFormat = "Y-m-d h:i K"; } var endPickr = Flatpickr(end, { enableTime: true, time_24hr: is24h, + dateFormat: dateFormat, minDate: new Date() }); Flatpickr(start, { enableTime: true, time_24hr: is24h, minDate: new Date(), + dateFormat: dateFormat, onChange: function () { endPickr.set('minDate', new Date($start.val())); } diff --git a/www/lib/calendar/date-picker.js b/www/lib/calendar/date-picker.js index bc42dbbeb..d66e98c3d 100644 --- a/www/lib/calendar/date-picker.js +++ b/www/lib/calendar/date-picker.js @@ -9,14 +9,17 @@ define([ var end = cfg.endpicker; var is24h = false + var dateFormat = "Y-m-d H:i"; try { is24h = !new Intl.DateTimeFormat(navigator.language, { hour: 'numeric' }).format(0).match(/AM/); } catch (e) {} + if (!is24h) { dateFormat = "Y-m-d h:i K"; } var e = $(end.input)[0]; var endPickr = Flatpickr(e, { enableTime: true, time_24hr: is24h, + dateFormat: dateFormat, minDate: start.date }); endPickr.setDate(end.date); @@ -25,6 +28,7 @@ define([ var startPickr = Flatpickr(s, { enableTime: true, time_24hr: is24h, + dateFormat: dateFormat, onChange: function () { endPickr.set('minDate', startPickr.parseDate(s.value)); }