Skip to content

Commit fc0bb23

Browse files
committed
Adding back isInOlderThanToday
1 parent d0be889 commit fc0bb23

File tree

2 files changed

+57
-57
lines changed

2 files changed

+57
-57
lines changed

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-table/time-plannings-table.component.spec.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -316,42 +316,42 @@ describe('TimePlanningsTableComponent', () => {
316316
});
317317
});
318318

319-
// describe('isInOlderThanToday', () => {
320-
// it('should return false for null date', () => {
321-
// expect(component.isInOlderThanToday(null as any)).toBe(false);
322-
// });
323-
//
324-
// it('should return false for undefined date', () => {
325-
// expect(component.isInOlderThanToday(undefined as any)).toBe(false);
326-
// });
327-
//
328-
// it('should return true for date in the past', () => {
329-
// const pastDate = new Date();
330-
// pastDate.setDate(pastDate.getDate() - 5);
331-
// expect(component.isInOlderThanToday(pastDate)).toBe(true);
332-
// });
333-
//
334-
// it('should return false for today', () => {
335-
// const today = new Date();
336-
// expect(component.isInOlderThanToday(today)).toBe(false);
337-
// });
338-
//
339-
// it('should return false for future date', () => {
340-
// const futureDate = new Date();
341-
// futureDate.setDate(futureDate.getDate() + 5);
342-
// expect(component.isInOlderThanToday(futureDate)).toBe(false);
343-
// });
344-
//
345-
// it('should handle string dates', () => {
346-
// const pastDateString = '2020-01-01';
347-
// expect(component.isInOlderThanToday(pastDateString as any)).toBe(true);
348-
// });
349-
//
350-
// it('should return false for invalid date string', () => {
351-
// const invalidDate = 'invalid-date';
352-
// expect(component.isInOlderThanToday(invalidDate as any)).toBe(false);
353-
// });
354-
// });
319+
describe('isInOlderThanToday', () => {
320+
it('should return false for null date', () => {
321+
expect(component.isInOlderThanToday(null as any)).toBe(false);
322+
});
323+
324+
it('should return false for undefined date', () => {
325+
expect(component.isInOlderThanToday(undefined as any)).toBe(false);
326+
});
327+
328+
it('should return true for date in the past', () => {
329+
const pastDate = new Date();
330+
pastDate.setDate(pastDate.getDate() - 5);
331+
expect(component.isInOlderThanToday(pastDate)).toBe(true);
332+
});
333+
334+
it('should return false for today', () => {
335+
const today = new Date();
336+
expect(component.isInOlderThanToday(today)).toBe(false);
337+
});
338+
339+
it('should return false for future date', () => {
340+
const futureDate = new Date();
341+
futureDate.setDate(futureDate.getDate() + 5);
342+
expect(component.isInOlderThanToday(futureDate)).toBe(false);
343+
});
344+
345+
it('should handle string dates', () => {
346+
const pastDateString = '2020-01-01';
347+
expect(component.isInOlderThanToday(pastDateString as any)).toBe(true);
348+
});
349+
350+
it('should return false for invalid date string', () => {
351+
const invalidDate = 'invalid-date';
352+
expect(component.isInOlderThanToday(invalidDate as any)).toBe(false);
353+
});
354+
});
355355

356356
describe('getStopTimeDisplay', () => {
357357
it('should return empty string when startedAt is null', () => {

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-table/time-plannings-table.component.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,27 @@ export class TimePlanningsTableComponent implements OnInit, OnChanges {
205205

206206
protected readonly JSON = JSON;
207207

208-
// isInOlderThanToday(date: Date): boolean {
209-
// // take the midnight of the date to compare ot today's midnight
210-
// if (!date) {
211-
// return false;
212-
// }
213-
// // Convert the date to a string to ensure it's in a valid format
214-
// if (typeof date === 'string') {
215-
// date = new Date(date);
216-
// }
217-
// // Compare the date with today's date
218-
// if (isNaN(date.getTime())) {
219-
// console.error('Invalid date:', date);
220-
// return false; // or handle the error as needed
221-
// }
222-
// // Create a new Date object for today at midnight
223-
// const todayMidnight = new Date();
224-
// todayMidnight.setHours(0, 0, 0, 0); // Set to midnight
225-
// const dateMidnight = new Date(date);
226-
// dateMidnight.setHours(0, 0, 0, 0); // Set to midnight
227-
// return dateMidnight <todayMidnight;
228-
// }
208+
isInOlderThanToday(date: Date): boolean {
209+
// take the midnight of the date to compare ot today's midnight
210+
if (!date) {
211+
return false;
212+
}
213+
// Convert the date to a string to ensure it's in a valid format
214+
if (typeof date === 'string') {
215+
date = new Date(date);
216+
}
217+
// Compare the date with today's date
218+
if (isNaN(date.getTime())) {
219+
console.error('Invalid date:', date);
220+
return false; // or handle the error as needed
221+
}
222+
// Create a new Date object for today at midnight
223+
const todayMidnight = new Date();
224+
todayMidnight.setHours(0, 0, 0, 0); // Set to midnight
225+
const dateMidnight = new Date(date);
226+
dateMidnight.setHours(0, 0, 0, 0); // Set to midnight
227+
return dateMidnight <todayMidnight;
228+
}
229229

230230
getStopTimeDisplay(startedAt: string | null, stoppedAt: string | null): string {
231231
if (!startedAt || !stoppedAt) {

0 commit comments

Comments
 (0)