Skip to content

Commit

Permalink
IBX-5688: Fixed flatpicker wrong convert on init (#792)
Browse files Browse the repository at this point in the history
* IBX-5688: Fixed flatpicker wrong convert on init

* using moment instead of Date

* fix convert date to user timezone

* adding helper for guessing user timezone

* remove moment from admin.picker

* renamed helper to browserTimezone

* renamed local timezone method
  • Loading branch information
Gengar-i authored May 23, 2023
1 parent 8ea8f81 commit df9c7a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/bundle/Resources/public/js/scripts/admin.picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const SELECTOR_PICKER_INPUT = '.ibexa-date-time-picker__input';
const SELECTOR_FORM_INPUT = '.ibexa-picker__form-input';
const pickers = doc.querySelectorAll(SELECTOR_PICKER);
const { formatShortDateTime } = ibexa.helpers.timezone;
const { formatShortDateTime, convertDateToTimezone, getBrowserTimezone } = ibexa.helpers.timezone;
const userTimezone = ibexa.adminUiConfig.timezone;
const pickerConfig = {
enableTime: true,
time_24hr: true,
Expand All @@ -23,7 +24,12 @@
let defaultDate;

if (formInput.value) {
defaultDate = new Date(formInput.value * 1000);
const date = new Date(formInput.value * 1000);
const dateWithUserTimezone = convertDateToTimezone(date, userTimezone);
const localTimezone = getBrowserTimezone();
const convertedDate = convertDateToTimezone(dateWithUserTimezone, localTimezone, true).format();

defaultDate = convertedDate;
}

const dateTimePickerWidget = new ibexa.core.DateTimePicker({
Expand All @@ -40,4 +46,4 @@
};

pickers.forEach(initFlatPickr);
})(window, window.document, window.ibexa, window.flatpickr);
})(window, window.document, window.ibexa);
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
const formatShortDateTime = (date, timezone = userPreferredTimezone, format = userPreferredShortDateTimeFormat) => {
return formatDate(date, timezone, format);
};
const getBrowserTimezone = () => {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
};

ibexa.addConfig('helpers.timezone', {
convertDateToTimezone,
formatFullDateTime,
formatShortDateTime,
getBrowserTimezone,
});
})(window, window.document, window.ibexa, window.moment);

0 comments on commit df9c7a8

Please sign in to comment.