Skip to content

Commit 6610a01

Browse files
committed
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
1 parent a1370e0 commit 6610a01

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/app/organization/holidays/create-holiday/create-holiday.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,14 @@ export class CreateHolidayComponent implements OnInit {
332332
const locale = this.settings.language.code;
333333
const prevFromDate: Date = this.holidayForm.value.fromDate;
334334
const prevToDate: Date = this.holidayForm.value.toDate;
335-
holidayFormData.fromDate = this.dateUtils.formatDate(prevFromDate, dateFormat);
336-
holidayFormData.toDate = this.dateUtils.formatDate(prevToDate, dateFormat);
335+
holidayFormData.fromDate = this.dateUtils.formatDateAsString(prevFromDate, dateFormat);
336+
holidayFormData.toDate = this.dateUtils.formatDateAsString(prevToDate, dateFormat);
337337
if (this.holidayForm.contains('repaymentsRescheduledTo')) {
338338
const prevRepaymentsRescheduledTo: Date = this.holidayForm.value.repaymentsRescheduledTo;
339-
holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDate(prevRepaymentsRescheduledTo, dateFormat);
339+
holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDateAsString(
340+
prevRepaymentsRescheduledTo,
341+
dateFormat
342+
);
340343
}
341344
const offices = this.holidayForm.value.offices.map((office: string) => {
342345
return { officeId: Number.parseInt(office, 10) };

src/app/organization/holidays/edit-holiday/edit-holiday.component.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,20 @@ export class EditHolidayComponent implements OnInit {
134134
const locale = this.settingsService.language.code;
135135
const dateFormat = this.settingsService.dateFormat;
136136
if (!this.isActiveHoliday) {
137-
if (holidayFormData.fromDate instanceof Date) {
138-
holidayFormData.fromDate = this.dateUtils.formatDate(holidayFormData.fromDate, dateFormat);
137+
const prevFromDate = this.holidayForm.value.fromDate;
138+
const prevToDate = this.holidayForm.value.toDate;
139+
140+
if (prevFromDate instanceof Date) {
141+
holidayFormData.fromDate = this.dateUtils.formatDateAsString(prevFromDate, dateFormat);
139142
}
140-
if (holidayFormData.toDate instanceof Date) {
141-
holidayFormData.toDate = this.dateUtils.formatDate(holidayFormData.toDate, dateFormat);
143+
if (prevToDate instanceof Date) {
144+
holidayFormData.toDate = this.dateUtils.formatDateAsString(prevToDate, dateFormat);
142145
}
143-
if (this.reSchedulingType === 2 && holidayFormData.repaymentsRescheduledTo instanceof Date) {
144-
holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDate(
145-
holidayFormData.repaymentsRescheduledTo,
146-
dateFormat
147-
);
146+
if (this.reSchedulingType === 2) {
147+
const repaymentScheduledTo = this.holidayForm.value.repaymentsRescheduledTo;
148+
if (repaymentScheduledTo instanceof Date) {
149+
holidayFormData.repaymentsRescheduledTo = this.dateUtils.formatDateAsString(repaymentScheduledTo, dateFormat);
150+
}
148151
}
149152
}
150153
const data = {

0 commit comments

Comments
 (0)