diff --git a/README.md b/README.md index 9164c98b..aec5637d 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,10 @@ You can use the component directly in your templates, which will set its `inline >To set max number of the date we can choose +### endDateShouldBeNow + +>set endDate to now + ### locale >the locale options is an object with: diff --git a/src/daterangepicker/daterangepicker.component.ts b/src/daterangepicker/daterangepicker.component.ts index 98d6f641..43096a94 100644 --- a/src/daterangepicker/daterangepicker.component.ts +++ b/src/daterangepicker/daterangepicker.component.ts @@ -91,6 +91,8 @@ export class DaterangepickerComponent implements OnInit { firstDayOfNextMonthClass: string = null; @Input() lastDayOfPreviousMonthClass: string = null; + @Input() + endDateShouldBeNow: Boolean = false; _locale: LocaleConfig = {}; @Input() set locale(value) { @@ -239,7 +241,14 @@ export class DaterangepickerComponent implements OnInit { this.showCalInRanges = (!this.rangesArray.length) || this.alwaysShowCalendars; if (!this.timePicker) { this.startDate = this.startDate.startOf('day'); - this.endDate = this.endDate.endOf('day'); + if(this.endDateShouldBeNow) { + this.endDate = this.endDate; + if (moment().diff(this.startDate, "days") === 1) { // if yesterday is selected: time should be end of day + this.endDate.endOf('day'); + } + } else { + this.endDate = this.endDate.endOf('day'); + } } } @@ -998,7 +1007,16 @@ export class DaterangepickerComponent implements OnInit { if (!this.timePicker) { this.startDate.startOf('day'); - this.endDate.endOf('day'); + if (this.endDateShouldBeNow) { + this.endDate; // other chosedLabels => Today, Last 7 Days: endDate should be now (moment()) + + if (moment().diff(this.startDate, "days") === 1) { // if yesterday is selected: time should be end of day + this.endDate.endOf('day'); + } + } else { + this.endDate.endOf('day'); + } + } if (!this.alwaysShowCalendars) {