Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-daterange-picker): date selection is now correct in all timez… #2203

Merged
merged 3 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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