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

Possibility to use end date now #356

Open
wants to merge 4 commits 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 20 additions & 2 deletions src/daterangepicker/daterangepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down