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-date-picker): fixing the min and max date in timezones half hour difference #2544

Merged
Merged
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
19 changes: 2 additions & 17 deletions packages/main/src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,6 @@ class DayPicker extends UI5Element {
let weekday;
const _monthsNameWide = localeData.getMonths("wide", this._calendarDate._oUDate.sCalendarType);

this._minDateObject = new Date(this._minDate);
this._maxDateObject = new Date(this._maxDate);

const visualizedSelectedDates = this._getVisualizedSelectedDates();

/* eslint-disable no-loop-func */
Expand Down Expand Up @@ -340,7 +337,7 @@ class DayPicker extends UI5Element {
if (this._isWeekend(oCalDate)) {
day.classes += " ui5-dp-item--weeekend";
}
if ((this.minDate || this.maxDate) && this._isOutOfSelectableRange(oCalDate)) {
if (this._isOutOfSelectableRange(oCalDate)) {
day.classes += " ui5-dp-item--disabled";
day.disabled = true;
}
Expand Down Expand Up @@ -863,19 +860,7 @@ class DayPicker extends UI5Element {
}

_isOutOfSelectableRange(date) {
const currentDate = date._oUDate ? date.toLocalJSDate() : CalendarDate.fromTimestamp(date).toLocalJSDate();
const minDate = this._minDateObject;
const maxDate = this._maxDateObject;

currentDate.setHours(0);
if (minDate) {
minDate.setHours(0);
}
if (maxDate) {
maxDate.setHours(0);
}

return currentDate > maxDate || currentDate < minDate;
return date.valueOf() < this._minDate || date.valueOf() > this._maxDate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not against this simplification, but just to confirm:
Is it possible for "this._minDate" or "this._maxDate" to be undefined and would the check still work in such case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it is not possible for those values to be undefined. There are default min and max values if users haven't set such as attributes. The default values would be from 0001.0.1 as minimum date to 9999.11.31 as maximum date. Those dates are also properly converted for the different calendar types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible based on this implementation because the getters _min/maxDate are requesting the min/max dates set by the developer and if there is not a explicitly set min or max date, it calls the _getMaxCalendarDate(Or min) which are the 1st calendar date(1/1/0001) or the last possible date in the calendar(31/12/9999) supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the clarification, I approve the PR then.

}

get _maxDate() {
Expand Down