From e227344647501e02bb3ed56da2e239e5c9e2a06a Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Fri, 24 Jan 2020 12:24:45 +0100 Subject: [PATCH] :zap: manage interval of date with date objects --- src/app/pages/dates/dates.component.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/app/pages/dates/dates.component.ts b/src/app/pages/dates/dates.component.ts index a3a5ad23..25aa8676 100644 --- a/src/app/pages/dates/dates.component.ts +++ b/src/app/pages/dates/dates.component.ts @@ -46,7 +46,8 @@ export class DatesComponent extends BaseComponent implements OnInit { this.config.dateList.push({ literal: '', date_object: new Date(), - timeList: []}); + timeList: [] + }); let selector = '[ng-reflect-name="dateChoices_' + (this.config.dateList.length - 1) + '"]'; this.cd.detectChanges(); const elem = this.document.querySelector(selector); @@ -59,7 +60,13 @@ export class DatesComponent extends BaseComponent implements OnInit { * change time spans */ addTime() { - this.config.timeList.push({literal: '', timeList: []}); + this.config.timeList.push( + { + literal: '', + timeList: [], + date_object: new Date() + } + ); } removeAllTimes() { @@ -103,6 +110,7 @@ export class DatesComponent extends BaseComponent implements OnInit { emptyAll() { this.config.dateList.forEach(element => { element.literal = ''; + element.date_object = new Date(); element.timeList = ['', '', '']; }); this.config.timeList.forEach(element => { @@ -110,6 +118,7 @@ export class DatesComponent extends BaseComponent implements OnInit { }); } + /** * add all the dates between the start and end dates in the interval section */ @@ -118,7 +127,11 @@ export class DatesComponent extends BaseComponent implements OnInit { const converted = []; newIntervalArray.forEach(element => { - converted.push({literal: element, timeList: []}); + converted.push({ + literal: element.literal, + date_object: element.date_object, + timeList: [] + }); }); this.config.dateList = [...new Set(converted)]; // add only dates that are not already present with a Set of unique items this.showDateInterval = false; @@ -142,10 +155,13 @@ export class DatesComponent extends BaseComponent implements OnInit { d2 = new Date(d2); const dates = []; while (+d1 < +d2) { - dates.push(this.formateDate(d1)); + dates.push({ + literal: this.formateDate(d1), + date_object: d1 + }); d1.setDate(d1.getDate() + interval) } - return dates.slice(0) + return dates.slice(0); } /**