Skip to content

Commit dec6a42

Browse files
authored
Merge pull request #67 from aj3sh/bugfix/formatter-am-pm-issue-for-noon
fix: fixed AM/PM formatting issue of noon
2 parents 2281d81 + 57091bc commit dec6a42

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ const amPmUpperCase: Formatter = (nepaliDate, locale) => {
197197
*/
198198
return 'A'
199199
}
200-
return nepaliDate.getHours() > 12 ? 'PM' : 'AM'
200+
return nepaliDate.getHours() >= 12 ? 'PM' : 'AM'
201201
}
202202

203203
const amPmLowerCase: Formatter = (nepaliDate, locale) => {
204204
if (locale === LOCALE_NE) {
205205
return 'a'
206206
}
207-
return nepaliDate.getHours() > 12 ? 'pm' : 'am'
207+
return nepaliDate.getHours() >= 12 ? 'pm' : 'am'
208208
}
209209

210210
/* Formatters mapping and implementations */

tests/format.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,20 @@ describe('format', () => {
221221
const formattedDate = format(nepaliDate3, formatStr)
222222
expect(formattedDate).toEqual('pm')
223223
})
224+
225+
it('should format NepaliDate (AM) for midnight', () => {
226+
const nepaliDate = new NepaliDate(2079, 5, 3)
227+
const formatStr = 'A'
228+
const formattedDate = format(nepaliDate, formatStr)
229+
expect(formattedDate).toEqual('AM')
230+
})
231+
232+
it('should format NepaliDate (PM) for noon', () => {
233+
const nepaliDate = new NepaliDate(2079, 5, 3, 12)
234+
const formatStr = 'A'
235+
const formattedDate = format(nepaliDate, formatStr)
236+
expect(formattedDate).toEqual('PM')
237+
})
224238
})
225239

226240
describe('formatNepali', () => {

0 commit comments

Comments
 (0)