From 0f4aac7e81224217f6b2abd59ad726ab94977994 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 17 Nov 2021 16:52:16 +0100 Subject: [PATCH] convert to date string for inputs --- src/app/core/models/dateChoice.model.ts | 2 +- src/app/core/services/date.utilities.service.ts | 14 +++++++++----- src/app/core/services/poll.service.ts | 13 ++++++++++--- .../form/date-select/date-select.component.html | 6 +----- .../form/date/list/day/day-list.component.html | 7 ------- .../form/date/list/day/day-list.component.ts | 15 +++------------ .../steps/step-three/step-three.component.html | 1 - 7 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/app/core/models/dateChoice.model.ts b/src/app/core/models/dateChoice.model.ts index 8700cd01..8db7924c 100644 --- a/src/app/core/models/dateChoice.model.ts +++ b/src/app/core/models/dateChoice.model.ts @@ -2,7 +2,7 @@ export interface DateChoice { literal: string; timeSlices: TimeSlices[]; date_object: Date; - date_input: String; + date_input: string; } export interface TimeSlices { diff --git a/src/app/core/services/date.utilities.service.ts b/src/app/core/services/date.utilities.service.ts index 4e5da7e0..35866766 100644 --- a/src/app/core/services/date.utilities.service.ts +++ b/src/app/core/services/date.utilities.service.ts @@ -109,9 +109,9 @@ export class DateUtilitiesService { const ladate4 = this.addDaysToDate(3, today); return [ - this.convertToDateChoiceObject(ladate2), - this.convertToDateChoiceObject(ladate3), - this.convertToDateChoiceObject(ladate4), + this.convertDateToDateChoiceObject(ladate2), + this.convertDateToDateChoiceObject(ladate3), + this.convertDateToDateChoiceObject(ladate4), ]; } @@ -119,12 +119,16 @@ export class DateUtilitiesService { * convert a date to a DateChoice * @param date */ - convertToDateChoiceObject(date: Date): DateChoice { + convertDateToDateChoiceObject(date: Date): DateChoice { + let isUnder10 = date.getDate() < 10; + let day = isUnder10 ? `0${date.getDate()}` : date.getDate(); + // get month is based on 0, so yeah + let input = `${date.getFullYear()}-${date.getMonth() + 1}-${day}`; return { literal: this.formateDateToInputStringNg(date), timeSlices: Object.create(defaultTimeOfDay), date_object: date, - date_input: `${date.getFullYear()}-${date.getMonth()}-${date.getDay()}`, + date_input: input, }; } } diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index 66b92583..7864911f 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -667,7 +667,7 @@ export class PollService implements Resolve { convertCalendarToText() { let converted = []; for (let someDate of this.calendar) { - converted.push(this.DateUtilitiesService.convertToDateChoiceObject(someDate)); + converted.push(this.DateUtilitiesService.convertDateToDateChoiceObject(someDate)); } this.dateChoiceList = converted; @@ -678,11 +678,18 @@ export class PollService implements Resolve { * convert the DateChoices to an arrray of Dates for calendar picker */ convertTextToCalendar() { + console.log('convert text to calendar', this.dateChoiceList); let converted = []; for (let someDateChoice of this.dateChoiceList) { - converted.push(someDateChoice.date_object); + let dateObj = new Date(someDateChoice.date_input); + console.log('dateObj', dateObj); + // check that date is not part of the disabled dates + if (this.disabled_dates.indexOf(dateObj) === -1) { + converted.push(dateObj); + } } + console.log('converted', converted); this.calendar = converted; return; } @@ -741,7 +748,7 @@ export class PollService implements Resolve { for (let elem of this.calendar) { console.log('elem', elem); - let converted_day = this.DateUtilitiesService.convertToDateChoiceObject(elem); + let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem); newpoll.dateChoices.push(converted_day); } console.log('newpoll.dateChoices', newpoll.dateChoices); diff --git a/src/app/features/administration/form/date-select/date-select.component.html b/src/app/features/administration/form/date-select/date-select.component.html index 320263c8..00b176a2 100644 --- a/src/app/features/administration/form/date-select/date-select.component.html +++ b/src/app/features/administration/form/date-select/date-select.component.html @@ -98,11 +98,7 @@

- + diff --git a/src/app/features/administration/form/date/list/day/day-list.component.html b/src/app/features/administration/form/date/list/day/day-list.component.html index 8a4b5f1e..ad4a1229 100644 --- a/src/app/features/administration/form/date/list/day/day-list.component.html +++ b/src/app/features/administration/form/date/list/day/day-list.component.html @@ -27,18 +27,11 @@ {{ choice.date_object | date: 'E':'Europe/Paris':'fr_FR' }} - {{ choice.date_input | date }} -
-
-				{{ choice.date_object | json }}
-