Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-5688: Fixed flatpicker wrong convert on init #792

Merged
merged 7 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);