From 0ab8588d2ec80965c93bb1a9c95b878cf0f09fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Ho=CC=88rantner?= Date: Tue, 22 Dec 2020 13:58:54 +0100 Subject: [PATCH 1/4] ADD posibilty to use endDate as now --- .../daterangepicker.component.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/daterangepicker/daterangepicker.component.ts b/src/daterangepicker/daterangepicker.component.ts index 98d6f641..f15ca5c1 100644 --- a/src/daterangepicker/daterangepicker.component.ts +++ b/src/daterangepicker/daterangepicker.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectorRef, Component, ElementRef, EventEmitter, forwardRef, Input, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms'; +import { TranslateService } from '@ngx-translate/core'; import * as _moment from 'moment'; import { LocaleConfig } from './daterangepicker.config'; import { LocaleService } from './locale.service'; @@ -36,7 +37,7 @@ export class DaterangepickerComponent implements OnInit { @Input() startDate = moment().startOf('day'); @Input() - endDate = moment().endOf('day'); + endDate = moment(); @Input() dateLimit: number = null; @@ -91,6 +92,8 @@ export class DaterangepickerComponent implements OnInit { firstDayOfNextMonthClass: string = null; @Input() lastDayOfPreviousMonthClass: string = null; + @Input() + endDateShouldBeNow: Boolean = false; _locale: LocaleConfig = {}; @Input() set locale(value) { @@ -200,6 +203,7 @@ export class DaterangepickerComponent implements OnInit { } if (typeof this.ranges[range][1] === 'string') { end = moment(this.ranges[range][1], this.locale.format); + } else { end = moment(this.ranges[range][1]); } @@ -239,7 +243,7 @@ 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'); + this.endDate = this.endDate; } } @@ -998,7 +1002,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) { From e65c7efe871ae70654dfebc118e1b13bb99bbbdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Ho=CC=88rantner?= Date: Tue, 22 Dec 2020 15:32:30 +0100 Subject: [PATCH 2/4] CRC --- src/daterangepicker/daterangepicker.component.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/daterangepicker/daterangepicker.component.ts b/src/daterangepicker/daterangepicker.component.ts index f15ca5c1..9b4ff1e7 100644 --- a/src/daterangepicker/daterangepicker.component.ts +++ b/src/daterangepicker/daterangepicker.component.ts @@ -203,7 +203,6 @@ export class DaterangepickerComponent implements OnInit { } if (typeof this.ranges[range][1] === 'string') { end = moment(this.ranges[range][1], this.locale.format); - } else { end = moment(this.ranges[range][1]); } @@ -243,7 +242,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; + 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'); + } } } From 4a2583e12479391727c0200d48c760fee383f205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Ho=CC=88rantner?= Date: Wed, 23 Dec 2020 08:29:58 +0100 Subject: [PATCH 3/4] ADD README --- README.md | 4 ++++ src/daterangepicker/daterangepicker.component.ts | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9164c98b..25a0dfb6 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,10 @@ You can use the component directly in your templates, which will set its `inline ### locale >the locale options is an object with: + +### endDateShouldBeNow + +>set endDate to now ```javascript { format: 'MM/DD/YYYY', // could be 'YYYY-MM-DDTHH:mm:ss.SSSSZ' diff --git a/src/daterangepicker/daterangepicker.component.ts b/src/daterangepicker/daterangepicker.component.ts index 9b4ff1e7..43096a94 100644 --- a/src/daterangepicker/daterangepicker.component.ts +++ b/src/daterangepicker/daterangepicker.component.ts @@ -1,6 +1,5 @@ import { ChangeDetectorRef, Component, ElementRef, EventEmitter, forwardRef, Input, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms'; -import { TranslateService } from '@ngx-translate/core'; import * as _moment from 'moment'; import { LocaleConfig } from './daterangepicker.config'; import { LocaleService } from './locale.service'; @@ -37,7 +36,7 @@ export class DaterangepickerComponent implements OnInit { @Input() startDate = moment().startOf('day'); @Input() - endDate = moment(); + endDate = moment().endOf('day'); @Input() dateLimit: number = null; From dbfa570d1fba1397a00c0942b62322887857072a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Ho=CC=88rantner?= Date: Wed, 23 Dec 2020 08:32:08 +0100 Subject: [PATCH 4/4] CRC --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 25a0dfb6..aec5637d 100644 --- a/README.md +++ b/README.md @@ -116,13 +116,13 @@ You can use the component directly in your templates, which will set its `inline >To set max number of the date we can choose -### locale - ->the locale options is an object with: - ### endDateShouldBeNow >set endDate to now + +### locale + +>the locale options is an object with: ```javascript { format: 'MM/DD/YYYY', // could be 'YYYY-MM-DDTHH:mm:ss.SSSSZ'