Is there a specific "campaign duration" rule where you must select a date between the first and last day of the month? If you choose a date outside of this range, such as a date from the next month, the Backend API will return an "Input param error."
Currently, when selecting the last date within the date selector (the 30th day of the month), the Backend API returns an "Input param error." This indicates that it counts the 30th day as the 1st day of the following month. I need to adjust the date selection to be one day less.
The question is, where in the code should I subtract one day from the "endDate" property?
This is the HTML snippet for the modal containing the date picker: (You can see the endDate there, I want to subtract one day from that endDate)
<!-- startDate/endDate -->
<div class="nano-f-r nano-f">
<nano-date-picker [(startDate)]="campaignDto.dtoData.startDate"
[(endDate)]="campaignDto.dtoData.endDate"
[intervalMode]="campaignDto.id === 'new' ? dpIntervalFuture : dpIntervalBoth"
[maxIntervalDurationInMonths]="2"
style="height: 30px"></nano-date-picker>
</div>
nano-date-picker component:
public isDaySelected(day: MonthDay): boolean {
return this.isDateRange === true
? day.startDate === this.datePicker.startDate || day.endDate === this.datePicker.endDate
: day.startDate === this.datePicker.startDate;
}
public ngOnChanges(): void {
const startDate = this.startDate ? moment(this.startDate).format() : moment().startOf('day').format();
const endDate = this.endDate ? moment(this.endDate).format() : moment(startDate).endOf('day').format();
this.datePicker = new DatePicker(startDate, endDate);
this.setDatePicker();
if (this.continiousDatesValue !== null) {
this.continiousDatesValueMoment = moment(this.continiousDatesValue);
}
if (this.previousDatesValue !== null) {
this.previousDatesValueMoment = moment(this.previousDatesValue);
}
}
private onDatesChange(): void {
this.startDateChange.emit(this.datePicker.startDate);
this.endDateChange.emit(this.datePicker.endDate);
this.startEndDateChange.emit({startDate: this.datePicker.startDate, endDate: this.datePicker.endDate});
this.isOpen = false;
}
public setRange(day: MonthDay): void {
if (this.isDateRange === true) {
this.datePicker.setRange(day, () => this.onDatesChange())
} else {
this.datePicker.setSingleDate(day, () => this.onDatesChange())
}
}
Here is how the date picker looks like: