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
This commit is contained in:
Anvay
2025-11-20 01:47:31 +05:30
parent a1370e0a08
commit 6610a015e1
2 changed files with 18 additions and 12 deletions
@@ -332,11 +332,14 @@ export class CreateHolidayComponent implements OnInit {
const locale = this.settings.language.code; const locale = this.settings.language.code;
const prevFromDate: Date = this.holidayForm.value.fromDate; const prevFromDate: Date = this.holidayForm.value.fromDate;
const prevToDate: Date = this.holidayForm.value.toDate; const prevToDate: Date = this.holidayForm.value.toDate;
holidayFormData.fromDate = this.dateUtils.formatDate(prevFromDate, dateFormat); holidayFormData.fromDate = this.dateUtils.formatDateAsString(prevFromDate, dateFormat);
holidayFormData.toDate = this.dateUtils.formatDate(prevToDate, dateFormat); holidayFormData.toDate = this.dateUtils.formatDateAsString(prevToDate, dateFormat);
if (this.holidayForm.contains('repaymentsRescheduledTo')) { if (this.holidayForm.contains('repaymentsRescheduledTo')) {
const prevRepaymentsRescheduledTo: Date = this.holidayForm.value.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) => { const offices = this.holidayForm.value.offices.map((office: string) => {
return { officeId: Number.parseInt(office, 10) }; return { officeId: Number.parseInt(office, 10) };
@@ -134,17 +134,20 @@ export class EditHolidayComponent implements OnInit {
const locale = this.settingsService.language.code; const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat; const dateFormat = this.settingsService.dateFormat;
if (!this.isActiveHoliday) { if (!this.isActiveHoliday) {
if (holidayFormData.fromDate instanceof Date) { const prevFromDate = this.holidayForm.value.fromDate;
holidayFormData.fromDate = this.dateUtils.formatDate(holidayFormData.fromDate, dateFormat); const prevToDate = this.holidayForm.value.toDate;
if (prevFromDate instanceof Date) {
holidayFormData.fromDate = this.dateUtils.formatDateAsString(prevFromDate, dateFormat);
} }
if (holidayFormData.toDate instanceof Date) { if (prevToDate instanceof Date) {
holidayFormData.toDate = this.dateUtils.formatDate(holidayFormData.toDate, dateFormat); holidayFormData.toDate = this.dateUtils.formatDateAsString(prevToDate, dateFormat);
} }
if (this.reSchedulingType === 2 && holidayFormData.repaymentsRescheduledTo instanceof Date) { if (this.reSchedulingType === 2) {
holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDate( const repaymentScheduledTo = this.holidayForm.value.repaymentsRescheduledTo;
holidayFormData.repaymentsRescheduledTo, if (repaymentScheduledTo instanceof Date) {
dateFormat holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDateAsString(repaymentScheduledTo, dateFormat);
); }
} }
} }
const data = { const data = {