From 6610a015e19aabc5dd6e0297c9aab768786d88e1 Mon Sep 17 00:00:00 2001 From: Anvay Date: Thu, 20 Nov 2025 01:47:31 +0530 Subject: [PATCH] WEB-389: Fix date formatting issue when editing and creating holidays - Changed edit-holiday component to use formatDateAsString with proper instanceof checks - Changed create-holiday component to use formatDateAsString - Fixed bug where incorrect date checks were being performed - formatDateAsString uses moment.format() which correctly handles Date objects - Resolves date format problems when editing existing holidays --- .../create-holiday.component.ts | 9 +++++--- .../edit-holiday/edit-holiday.component.ts | 21 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/app/organization/holidays/create-holiday/create-holiday.component.ts b/src/app/organization/holidays/create-holiday/create-holiday.component.ts index 4ce0073ad..692674059 100644 --- a/src/app/organization/holidays/create-holiday/create-holiday.component.ts +++ b/src/app/organization/holidays/create-holiday/create-holiday.component.ts @@ -332,11 +332,14 @@ export class CreateHolidayComponent implements OnInit { const locale = this.settings.language.code; const prevFromDate: Date = this.holidayForm.value.fromDate; const prevToDate: Date = this.holidayForm.value.toDate; - holidayFormData.fromDate = this.dateUtils.formatDate(prevFromDate, dateFormat); - holidayFormData.toDate = this.dateUtils.formatDate(prevToDate, dateFormat); + holidayFormData.fromDate = this.dateUtils.formatDateAsString(prevFromDate, dateFormat); + holidayFormData.toDate = this.dateUtils.formatDateAsString(prevToDate, dateFormat); if (this.holidayForm.contains('repaymentsRescheduledTo')) { const prevRepaymentsRescheduledTo: Date = this.holidayForm.value.repaymentsRescheduledTo; - holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDate(prevRepaymentsRescheduledTo, dateFormat); + holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDateAsString( + prevRepaymentsRescheduledTo, + dateFormat + ); } const offices = this.holidayForm.value.offices.map((office: string) => { return { officeId: Number.parseInt(office, 10) }; diff --git a/src/app/organization/holidays/edit-holiday/edit-holiday.component.ts b/src/app/organization/holidays/edit-holiday/edit-holiday.component.ts index bfedf3165..9bb4f1cc7 100644 --- a/src/app/organization/holidays/edit-holiday/edit-holiday.component.ts +++ b/src/app/organization/holidays/edit-holiday/edit-holiday.component.ts @@ -134,17 +134,20 @@ export class EditHolidayComponent implements OnInit { const locale = this.settingsService.language.code; const dateFormat = this.settingsService.dateFormat; if (!this.isActiveHoliday) { - if (holidayFormData.fromDate instanceof Date) { - holidayFormData.fromDate = this.dateUtils.formatDate(holidayFormData.fromDate, dateFormat); + const prevFromDate = this.holidayForm.value.fromDate; + const prevToDate = this.holidayForm.value.toDate; + + if (prevFromDate instanceof Date) { + holidayFormData.fromDate = this.dateUtils.formatDateAsString(prevFromDate, dateFormat); } - if (holidayFormData.toDate instanceof Date) { - holidayFormData.toDate = this.dateUtils.formatDate(holidayFormData.toDate, dateFormat); + if (prevToDate instanceof Date) { + holidayFormData.toDate = this.dateUtils.formatDateAsString(prevToDate, dateFormat); } - if (this.reSchedulingType === 2 && holidayFormData.repaymentsRescheduledTo instanceof Date) { - holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDate( - holidayFormData.repaymentsRescheduledTo, - dateFormat - ); + if (this.reSchedulingType === 2) { + const repaymentScheduledTo = this.holidayForm.value.repaymentsRescheduledTo; + if (repaymentScheduledTo instanceof Date) { + holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDateAsString(repaymentScheduledTo, dateFormat); + } } } const data = {