Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ function isValidDate(date: string | Date): boolean {

const pastDate = subYears(new Date(), 1000);
const futureDate = addYears(new Date(), 1000);

if (typeof date === 'string') {
const parsedDate = parse(date, 'yyyy-MM-dd', new Date());
if (!isValid(parsedDate)) {
return false;
}
return isAfter(parsedDate, pastDate) && isBefore(parsedDate, futureDate);
}

const testDate = new Date(date);
Comment thread
thelullabyy marked this conversation as resolved.
return isValid(testDate) && isAfter(testDate, pastDate) && isBefore(testDate, futureDate);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/ValidationUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ describe('ValidationUtils', () => {
const isValid = isValidDate(futureDate);
expect(isValid).toBe(false);
});

test('Should return false for a invalid date format', () => {
const validDate = '2025-07';
const isValid = isValidDate(validDate);
expect(isValid).toBe(false);
});
});

describe('isValidPastDate', () => {
Expand Down
Loading