Fix date rendering with 12h format in flatpickr inputs

pull/1/head
yflory 4 years ago
parent f5c029e937
commit d819ff093d

@ -1314,19 +1314,23 @@ define([
var $start = $(start); var $start = $(start);
var $end = $(end); var $end = $(end);
var is24h = false; var is24h = false;
var dateFormat = "Y-m-d H:i";
try { try {
is24h = !new Intl.DateTimeFormat(navigator.language, { hour: 'numeric' }).format(0).match(/AM/); is24h = !new Intl.DateTimeFormat(navigator.language, { hour: 'numeric' }).format(0).match(/AM/);
} catch (e) {} } catch (e) {}
if (!is24h) { dateFormat = "Y-m-d h:i K"; }
var endPickr = Flatpickr(end, { var endPickr = Flatpickr(end, {
enableTime: true, enableTime: true,
time_24hr: is24h, time_24hr: is24h,
dateFormat: dateFormat,
minDate: new Date() minDate: new Date()
}); });
Flatpickr(start, { Flatpickr(start, {
enableTime: true, enableTime: true,
time_24hr: is24h, time_24hr: is24h,
minDate: new Date(), minDate: new Date(),
dateFormat: dateFormat,
onChange: function () { onChange: function () {
endPickr.set('minDate', new Date($start.val())); endPickr.set('minDate', new Date($start.val()));
} }

@ -9,14 +9,17 @@ define([
var end = cfg.endpicker; var end = cfg.endpicker;
var is24h = false var is24h = false
var dateFormat = "Y-m-d H:i";
try { try {
is24h = !new Intl.DateTimeFormat(navigator.language, { hour: 'numeric' }).format(0).match(/AM/); is24h = !new Intl.DateTimeFormat(navigator.language, { hour: 'numeric' }).format(0).match(/AM/);
} catch (e) {} } catch (e) {}
if (!is24h) { dateFormat = "Y-m-d h:i K"; }
var e = $(end.input)[0]; var e = $(end.input)[0];
var endPickr = Flatpickr(e, { var endPickr = Flatpickr(e, {
enableTime: true, enableTime: true,
time_24hr: is24h, time_24hr: is24h,
dateFormat: dateFormat,
minDate: start.date minDate: start.date
}); });
endPickr.setDate(end.date); endPickr.setDate(end.date);
@ -25,6 +28,7 @@ define([
var startPickr = Flatpickr(s, { var startPickr = Flatpickr(s, {
enableTime: true, enableTime: true,
time_24hr: is24h, time_24hr: is24h,
dateFormat: dateFormat,
onChange: function () { onChange: function () {
endPickr.set('minDate', startPickr.parseDate(s.value)); endPickr.set('minDate', startPickr.parseDate(s.value));
} }

Loading…
Cancel
Save