Skip to content

Commit

Permalink
Do not include timezone in datepickers only displaying date
Browse files Browse the repository at this point in the history
We must not include timezone information when storing date
columns. It would lead to wrongly stored dates otherwise.

(cherry picked from commit 3575840)
  • Loading branch information
tvdeyen committed Mar 5, 2024
1 parent 2685296 commit 4b13bf5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/javascript/alchemy_admin/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ export default function Datepicker(scope = document) {
// Initializes the datepickers
datepickerInputs.forEach((input) => {
const type = input.dataset.datepickerType
const enableTime = /time/.test(type)

const options = {
// alchemy_i18n supports `zh_CN` etc., but flatpickr only has two-letter codes (`zh`)
locale: Alchemy.locale.slice(0, 2),
altInput: true,
altFormat: Alchemy.t(`formats.${type}`),
altInputClass: "flatpickr-input",
dateFormat: "Z",
enableTime: /time/.test(type),
enableTime,
noCalendar: type === "time",
time_24hr: Alchemy.t("formats.time_24hr"),
onValueUpdate(_selectedDates, _dateStr, instance) {
Expand All @@ -28,6 +30,11 @@ export default function Datepicker(scope = document) {
)
}
}

if (enableTime) {
options.dateFormat = "Z"
}

flatpickr(input, options)
})
}

0 comments on commit 4b13bf5

Please sign in to comment.