Skip to content

Commit

Permalink
Fix AMPM formatting casing.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmanzo-fundrise committed Aug 23, 2024
1 parent 2de9c66 commit 95485c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/methods/format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ const printFormat = (s, str = '') => {
if (str.indexOf('{') !== -1) {
let sections = /\{(.+?)\}/g
str = str.replace(sections, (_, fmt) => {
fmt = fmt.toLowerCase().trim()
fmt = fmt.trim()
if (fmt !== 'AMPM') {
fmt = fmt.toLowerCase()
}
if (format.hasOwnProperty(fmt)) {
let out = String(format[fmt](s))
if (fmt.toLowerCase() !== 'ampm') {
Expand Down
18 changes: 17 additions & 1 deletion test/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,20 @@ test('unix-year-padding', t => {
s = spacetime('sep 1 2000')
t.equal(s.unixFmt('yy'), '00', 'zero-end')
t.end()
});
})

test('am-pm-variants', (t) => {
let s = spacetime('January 1, 2023')
s = s.time('4:45pm')
let arr = [
['{hour}:{minute}{ampm}', '4:45pm'],
['{hour}:{minute}{AMPM}', '4:45PM'],
['{hour}:{minute}{AMPM }', '4:45PM'],
['{AMPM}', 'PM'],
]
arr.forEach((a) => {
t.equal(s.format(a[0]), a[1], a[2], a[3])
})
t.end()
})

0 comments on commit 95485c8

Please sign in to comment.