diff --git a/src/format.ts b/src/format.ts index 9e9365a..8ac69b2 100644 --- a/src/format.ts +++ b/src/format.ts @@ -197,14 +197,14 @@ const amPmUpperCase: Formatter = (nepaliDate, locale) => { */ return 'A' } - return nepaliDate.getHours() > 12 ? 'PM' : 'AM' + return nepaliDate.getHours() >= 12 ? 'PM' : 'AM' } const amPmLowerCase: Formatter = (nepaliDate, locale) => { if (locale === LOCALE_NE) { return 'a' } - return nepaliDate.getHours() > 12 ? 'pm' : 'am' + return nepaliDate.getHours() >= 12 ? 'pm' : 'am' } /* Formatters mapping and implementations */ diff --git a/tests/format.test.ts b/tests/format.test.ts index b1deae5..ad8b41b 100644 --- a/tests/format.test.ts +++ b/tests/format.test.ts @@ -221,6 +221,20 @@ describe('format', () => { const formattedDate = format(nepaliDate3, formatStr) expect(formattedDate).toEqual('pm') }) + + it('should format NepaliDate (AM) for midnight', () => { + const nepaliDate = new NepaliDate(2079, 5, 3) + const formatStr = 'A' + const formattedDate = format(nepaliDate, formatStr) + expect(formattedDate).toEqual('AM') + }) + + it('should format NepaliDate (PM) for noon', () => { + const nepaliDate = new NepaliDate(2079, 5, 3, 12) + const formatStr = 'A' + const formattedDate = format(nepaliDate, formatStr) + expect(formattedDate).toEqual('PM') + }) }) describe('formatNepali', () => {