diff --git a/projects/go-lib/src/lib/components/go-datepicker/locale-format.spec.ts b/projects/go-lib/src/lib/components/go-datepicker/locale-format.spec.ts index ec3aab77f..c4bdfa469 100644 --- a/projects/go-lib/src/lib/components/go-datepicker/locale-format.spec.ts +++ b/projects/go-lib/src/lib/components/go-datepicker/locale-format.spec.ts @@ -13,5 +13,14 @@ describe('LocaleFormat', () => { dec.toUTCString() + ' is not a valid date' ); }); + it('should return true for a leap year date', () => { + const feb = 1; + expect(LocaleFormat.validDate(feb, 29, 2024)).toBe(true); + }); + + it('should return false for a non leap year date', () => { + const feb = 1; + expect(LocaleFormat.validDate(feb, 29, 2023)).toBe(false); + }); }); }); diff --git a/projects/go-lib/src/lib/components/go-datepicker/locale-format.ts b/projects/go-lib/src/lib/components/go-datepicker/locale-format.ts index f5cd53893..cee852a94 100644 --- a/projects/go-lib/src/lib/components/go-datepicker/locale-format.ts +++ b/projects/go-lib/src/lib/components/go-datepicker/locale-format.ts @@ -41,7 +41,7 @@ export class LocaleFormat { if (day <= validDays[month]) { return true; } - if (year % 4 === 0 && month === 2 && day === 29) { + if (year % 4 === 0 && (month + 1) === 2 && day === 29) { return true; } return false;