Skip to content

Commit

Permalink
Merge pull request opensource-nepal#67 from aj3sh/bugfix/formatter-am…
Browse files Browse the repository at this point in the history
…-pm-issue-for-noon

fix: fixed AM/PM formatting issue of noon
  • Loading branch information
aj3sh authored Oct 3, 2023
2 parents 2281d81 + 57091bc commit dec6a42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 14 additions & 0 deletions tests/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit dec6a42

Please sign in to comment.