Skip to content

Commit 1ae8916

Browse files
committed
fix timezones
1 parent ef13b4f commit 1ae8916

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/bundle/Resources/public/js/scripts/core/date.time.range.single.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { formatShortDateTime } from '../helpers/timezone.helper';
1+
import { getAdminUiConfig } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper';
2+
import { convertDateToTimezone, formatShortDateTime, getBrowserTimezone } from '../helpers/timezone.helper';
23
import { setInstance } from '../helpers/object.instances';
34

45
const { ibexa, document } = window;
@@ -29,7 +30,11 @@ class DateTimeRangeSingle {
2930
}
3031

3132
getUnixTimestampUTC(dateObject) {
32-
return Math.floor(dateObject.getTime() / 1000);
33+
const { timezone } = getAdminUiConfig();
34+
const selectedDateWithUserTimezone = convertDateToTimezone(dateObject, timezone, true);
35+
const timestamp = Math.floor(selectedDateWithUserTimezone.valueOf() / 1000);
36+
37+
return timestamp;
3338
}
3439

3540
setDates(dates) {
@@ -82,7 +87,18 @@ class DateTimeRangeSingle {
8287

8388
init() {
8489
const { start, end } = this.container.dataset;
85-
const defaultDate = start && end ? [start, end] : [];
90+
let defaultDate = [];
91+
92+
if (start && end) {
93+
const defaultStartDateWithUserTimezone = convertDateToTimezone(start * 1000);
94+
const defaultEndDateWithUserTimezone = convertDateToTimezone(end * 1000);
95+
const browserTimezone = getBrowserTimezone();
96+
97+
defaultDate = [
98+
new Date(convertDateToTimezone(defaultStartDateWithUserTimezone, browserTimezone, true)),
99+
new Date(convertDateToTimezone(defaultEndDateWithUserTimezone, browserTimezone, true)),
100+
];
101+
}
86102

87103
this.dateTimePickerWidget = new ibexa.core.DateTimePicker({
88104
container: this.dateTimePickerInputWrapper,

src/bundle/Resources/views/themes/admin/ui/component/date_time_range_single/date_time_range_single.twig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
'data-period-selector': period_input_selector,
88
'data-start-selector': start_input_selector,
99
'data-end-selector': end_input_selector,
10-
'data-start': start_date is defined and start_date is not null
11-
? start_date|date('Y-m-d H:i:s') : '',
12-
'data-end': end_date is defined and end_date is not null
13-
? end_date|date('Y-m-d H:i:s') : '',
10+
'data-start': start_date|default(''),
11+
'data-end': end_date|default(''),
1412
}) %}
1513

1614
{% set picker_wrapper_attr = picker_wrapper_attr|default({})|merge({

0 commit comments

Comments
 (0)