Skip to content

Commit

Permalink
IBX-1090: Fixed calculations and displaying of ezdate FT, as it shoul…
Browse files Browse the repository at this point in the history
…d always be represented in UTC (#2033)
  • Loading branch information
ViniTou authored Feb 16, 2022
1 parent bc114dc commit 0a6e5e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/bundle/Resources/public/js/scripts/fieldType/ezdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@
return;
}

const selectedDateWithUserTimezone = eZ.helpers.timezone.convertDateToTimezone(date[0], eZ.adminUiConfig.timezone, true);
date = new Date(date[0]);
date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));

sourceInput.value = Math.floor(selectedDateWithUserTimezone.valueOf() / 1000);
sourceInput.value = Math.floor(date.valueOf() / 1000);
sourceInput.dispatchEvent(event);
};
const clearValue = (sourceInput, flatpickrInstance, event) => {
Expand All @@ -99,7 +100,15 @@
if (actionType === 'create') {
defaultDate.setTime(new Date().getTime());
} else if (actionType === 'edit') {
defaultDate.setTime(defaultDate.getTime());
defaultDate = new Date(
defaultDate.getUTCFullYear(),
defaultDate.getUTCMonth(),
defaultDate.getUTCDate(),
0,
0,
0,
0
);
}

updateInputValue(sourceInput, [defaultDate]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
{% block ezdate_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% set field_value = field.value.date|ez_full_date %}
{% set field_value = field.value.date|ez_full_date('UTC') %}
{{ block( 'simple_block_field' ) }}
{% endif %}
{% endapply %}
Expand Down

0 comments on commit 0a6e5e4

Please sign in to comment.