Skip to content

Commit

Permalink
fix(ui5-daterange-picker): fix firstDate/lastDate getters values (#2277)
Browse files Browse the repository at this point in the history
Fix the return values of first and last date  public getters, previously returning wrong values.

Fixes #2221
  • Loading branch information
tsanislavgatev authored and ilhan007 committed Nov 5, 2020
1 parent 6a5e495 commit d2df83f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions packages/main/src/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class DateRangePicker extends DatePicker {
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;
this._firstDateTimestamp = this._lastDateTimestamp;
Expand Down Expand Up @@ -257,7 +256,7 @@ class DateRangePicker extends DatePicker {
*/
get firstDateValue() {
const dateValue = new Date(this._firstDateTimestamp * 1000);
return new Date(Date.UTC(dateValue.getFullYear(), dateValue.getMonth(), dateValue.getDate()));
return new Date(dateValue.getUTCFullYear(), dateValue.getUTCMonth(), dateValue.getUTCDate(), dateValue.getUTCHours());
}

/**
Expand All @@ -269,7 +268,7 @@ class DateRangePicker extends DatePicker {
*/
get lastDateValue() {
const dateValue = new Date(this._lastDateTimestamp * 1000);
return new Date(Date.UTC(dateValue.getFullYear(), dateValue.getMonth(), dateValue.getDate()));
return new Date(dateValue.getUTCFullYear(), dateValue.getUTCMonth(), dateValue.getUTCDate(), dateValue.getUTCHours());
}

get _placeholder() {
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class DayPicker extends UI5Element {
lastWeekNumber = -1,
isDaySelected = false,
todayIndex = 0;

const _aVisibleDays = this._getVisibleDays(this._calendarDate);
this._weeks = [];
let week = [];
Expand Down
6 changes: 3 additions & 3 deletions packages/main/test/specs/DateRangePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("DateRangePicker general interaction", () => {

daterangepicker.click();
daterangepicker.keys("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
daterangepicker.keys("09/09/2019 - 10/10/2019");
daterangepicker.keys("27/09/2019 - 10/10/2019");
daterangepicker.keys("Enter");

const res = browser.execute(() => {
Expand All @@ -54,8 +54,8 @@ describe("DateRangePicker general interaction", () => {
return {firstDateValue, lastDateValue};
});

assert.strictEqual(res.firstDateValue, "2019-09-09T00:00:00.000Z", "The first date is in JS Date format");
assert.strictEqual(res.lastDateValue, "2019-10-10T00:00:00.000Z", "The last date is JS Date format");
assert.deepEqual(new Date(res.firstDateValue), new Date(2019, 8, 27), "The first date is in JS Date format");
assert.deepEqual(new Date(res.lastDateValue), new Date(2019, 9, 10), "The last date is JS Date format");
});

it("Initially setting the same date as first & last is possible", () => {
Expand Down

0 comments on commit d2df83f

Please sign in to comment.