Skip to content

Commit

Permalink
fix(ui5-daterange-picker): date selection is now correct in all timez… (
Browse files Browse the repository at this point in the history
#2203)

* fix(ui5-daterange-picker): date selection is now correct in all timezones

* removed unused reference

* lint fix
  • Loading branch information
tsanislavgatev authored Sep 10, 2020
1 parent bfb9999 commit 2bca6f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/main/src/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ class DatePicker extends UI5Element {
_getTimeStampFromString(value) {
const jsDate = this.getFormat().parse(value);
if (jsDate) {
const jsDateTimeNow = new Date(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate());
const oCalDate = CalendarDate.fromTimestamp(jsDateTimeNow.getTime(), this._primaryCalendarType);
return oCalDate.valueOf();
const jsDateTimeNow = Date.UTC(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate());
const calDate = CalendarDate.fromTimestamp(jsDateTimeNow, this._primaryCalendarType);
return calDate.valueOf();
}
return undefined;
}
Expand Down
20 changes: 12 additions & 8 deletions packages/main/src/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ class DateRangePicker extends DatePicker {
}
this.valueState = ValueState.None;

this._firstDateTimestamp = this.getFormat().parse(dates[0]).getTime() / 1000;
this._lastDateTimestamp = this.getFormat().parse(dates[1]).getTime() / 1000;
const firstDate = this.getFormat().parse(dates[0]);
const secondDate = this.getFormat().parse(dates[1]);

this._firstDateTimestamp = Date.UTC(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate(), firstDate.getHours()) / 1000;
this._lastDateTimestamp = Date.UTC(secondDate.getFullYear(), secondDate.getMonth(), secondDate.getDate(), secondDate.getHours()) / 1000;


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

dateIntervalArrayBuilder(firstTimestamp, lastTimestamp) {
const datesTimestamps = [],
jsDate = new Date(firstTimestamp),
tempCalendarDate = new CalendarDate(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate());
tempCalendarDate = CalendarDate.fromTimestamp(firstTimestamp);

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

_handleCalendarChange(event) {
const newValue = event.detail.dates && event.detail.dates[0];

this._oneTimeStampSelected = false;
if (this.isFirstDatePick) {
this.isFirstDatePick = false;
Expand Down Expand Up @@ -373,7 +375,7 @@ class DateRangePicker extends DatePicker {
this._cleanHoveredAttributeFromVisibleItems();

this._calendar.timestamp = this._firstDateTimestamp;
this._calendar.selectedDates = this.dateIntervalArrayBuilder(this._firstDateTimestamp, this._lastDateTimestamp);
this._calendar.selectedDates = this.dateIntervalArrayBuilder(this._firstDateTimestamp * 1000, this._lastDateTimestamp * 1000);
this._focusInputAfterClose = true;

if (this.isInValidRange(this.value)) {
Expand Down Expand Up @@ -408,8 +410,10 @@ class DateRangePicker extends DatePicker {
let value = "";
const delimiter = this.delimiter,
format = this.getFormat(),
firstDateString = format.format(new Date(firstDateValue * 1000)),
lastDateString = format.format(new Date(lastDateValue * 1000));
firstDate = new Date(firstDateValue * 1000),
lastDate = new Date(lastDateValue * 1000),
firstDateString = format.format(new Date(firstDate.getUTCFullYear(), firstDate.getUTCMonth(), firstDate.getUTCDate(), firstDate.getUTCHours())),
lastDateString = format.format(new Date(lastDate.getUTCFullYear(), lastDate.getUTCMonth(), lastDate.getUTCDate(), lastDate.getUTCHours()));

if (firstDateValue) {
if (delimiter && delimiter !== "" && lastDateString) {
Expand Down

0 comments on commit 2bca6f1

Please sign in to comment.