Skip to content

Commit 2bca6f1

Browse files
fix(ui5-daterange-picker): date selection is now correct in all timez… (#2203)
* fix(ui5-daterange-picker): date selection is now correct in all timezones * removed unused reference * lint fix
1 parent bfb9999 commit 2bca6f1

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

packages/main/src/DatePicker.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ class DatePicker extends UI5Element {
481481
_getTimeStampFromString(value) {
482482
const jsDate = this.getFormat().parse(value);
483483
if (jsDate) {
484-
const jsDateTimeNow = new Date(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate());
485-
const oCalDate = CalendarDate.fromTimestamp(jsDateTimeNow.getTime(), this._primaryCalendarType);
486-
return oCalDate.valueOf();
484+
const jsDateTimeNow = Date.UTC(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate());
485+
const calDate = CalendarDate.fromTimestamp(jsDateTimeNow, this._primaryCalendarType);
486+
return calDate.valueOf();
487487
}
488488
return undefined;
489489
}

packages/main/src/DateRangePicker.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ class DateRangePicker extends DatePicker {
191191
}
192192
this.valueState = ValueState.None;
193193

194-
this._firstDateTimestamp = this.getFormat().parse(dates[0]).getTime() / 1000;
195-
this._lastDateTimestamp = this.getFormat().parse(dates[1]).getTime() / 1000;
194+
const firstDate = this.getFormat().parse(dates[0]);
195+
const secondDate = this.getFormat().parse(dates[1]);
196+
197+
this._firstDateTimestamp = Date.UTC(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate(), firstDate.getHours()) / 1000;
198+
this._lastDateTimestamp = Date.UTC(secondDate.getFullYear(), secondDate.getMonth(), secondDate.getDate(), secondDate.getHours()) / 1000;
199+
196200

197201
if (this._firstDateTimestamp > this._lastDateTimestamp) {
198202
const temp = this._firstDateTimestamp;
@@ -325,8 +329,7 @@ class DateRangePicker extends DatePicker {
325329

326330
dateIntervalArrayBuilder(firstTimestamp, lastTimestamp) {
327331
const datesTimestamps = [],
328-
jsDate = new Date(firstTimestamp),
329-
tempCalendarDate = new CalendarDate(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate());
332+
tempCalendarDate = CalendarDate.fromTimestamp(firstTimestamp);
330333

331334
while (tempCalendarDate.valueOf() < lastTimestamp) {
332335
datesTimestamps.push(tempCalendarDate.valueOf() / 1000);
@@ -340,7 +343,6 @@ class DateRangePicker extends DatePicker {
340343

341344
_handleCalendarChange(event) {
342345
const newValue = event.detail.dates && event.detail.dates[0];
343-
344346
this._oneTimeStampSelected = false;
345347
if (this.isFirstDatePick) {
346348
this.isFirstDatePick = false;
@@ -373,7 +375,7 @@ class DateRangePicker extends DatePicker {
373375
this._cleanHoveredAttributeFromVisibleItems();
374376

375377
this._calendar.timestamp = this._firstDateTimestamp;
376-
this._calendar.selectedDates = this.dateIntervalArrayBuilder(this._firstDateTimestamp, this._lastDateTimestamp);
378+
this._calendar.selectedDates = this.dateIntervalArrayBuilder(this._firstDateTimestamp * 1000, this._lastDateTimestamp * 1000);
377379
this._focusInputAfterClose = true;
378380

379381
if (this.isInValidRange(this.value)) {
@@ -408,8 +410,10 @@ class DateRangePicker extends DatePicker {
408410
let value = "";
409411
const delimiter = this.delimiter,
410412
format = this.getFormat(),
411-
firstDateString = format.format(new Date(firstDateValue * 1000)),
412-
lastDateString = format.format(new Date(lastDateValue * 1000));
413+
firstDate = new Date(firstDateValue * 1000),
414+
lastDate = new Date(lastDateValue * 1000),
415+
firstDateString = format.format(new Date(firstDate.getUTCFullYear(), firstDate.getUTCMonth(), firstDate.getUTCDate(), firstDate.getUTCHours())),
416+
lastDateString = format.format(new Date(lastDate.getUTCFullYear(), lastDate.getUTCMonth(), lastDate.getUTCDate(), lastDate.getUTCHours()));
413417

414418
if (firstDateValue) {
415419
if (delimiter && delimiter !== "" && lastDateString) {

0 commit comments

Comments
 (0)