Skip to content

Fix update of min/max attributes when only the hours/minutes/seconds have changed #398

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions projects/datetime-picker/src/lib/core/date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export abstract class NgxMatDateAdapter<D> extends DateAdapter<D> {

/**
* Copy time from a date to a another date
* @param toDate
* @param fromDate
* @param toDate
* @param fromDate
*/
copyTime(toDate: D, fromDate: D) {
this.setHour(toDate, this.getHour(fromDate));
Expand All @@ -83,6 +83,16 @@ export abstract class NgxMatDateAdapter<D> extends DateAdapter<D> {
return res;
}

/**
* Compares two dates and returns whether they are the same or not.
* @param first The first date to compare.
* @param second The second date to compare.
* @returns true if the dates are equal, false if they are not equal
*/
sameDateWithTime(first: D, second: D): boolean {
return this.compareDateWithTime(first, second, true) === 0;
}

/**
* Set time by using default values
* @param defaultTime List default values [hour, minute, second]
Expand Down
4 changes: 2 additions & 2 deletions projects/datetime-picker/src/lib/date-range-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class NgxMatDateRangeInput<D>
set min(value: D | null) {
const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));

if (!this._dateAdapter.sameDate(validValue, this._min)) {
if (!this._dateAdapter.sameDateWithTime(validValue, this._min)) {
this._min = validValue;
this._revalidate();
}
Expand All @@ -180,7 +180,7 @@ export class NgxMatDateRangeInput<D>
set max(value: D | null) {
const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));

if (!this._dateAdapter.sameDate(validValue, this._max)) {
if (!this._dateAdapter.sameDateWithTime(validValue, this._max)) {
this._max = validValue;
this._revalidate();
}
Expand Down
4 changes: 2 additions & 2 deletions projects/datetime-picker/src/lib/datepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class NgxMatDatepickerInput<D>
set min(value: D | null) {
const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));

if (!this._dateAdapter.sameDate(validValue, this._min)) {
if (!this._dateAdapter.sameDateWithTime(validValue, this._min)) {
this._min = validValue;
this._validatorOnChange();
}
Expand All @@ -90,7 +90,7 @@ export class NgxMatDatepickerInput<D>
set max(value: D | null) {
const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));

if (!this._dateAdapter.sameDate(validValue, this._max)) {
if (!this._dateAdapter.sameDateWithTime(validValue, this._max)) {
this._max = validValue;
this._validatorOnChange();
}
Expand Down