Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 5d54fe0

Browse files
author
Evan Taylor
committed
Fixed case when just "12" is entered. Added test for this case.
1 parent 10ecf75 commit 5d54fe0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/formatters/ampm.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@
354354
minute,
355355
format = format || 'H:i:s',
356356
pm = time.match(/p/i) !== null,
357+
am = time.match(/a/i) !== null,
357358
num = time.replace(/[^0-9]/g, '');
358359

359360
// Parse for hour and minute
@@ -375,10 +376,13 @@
375376
return '';
376377
}
377378

378-
if(hour == 12 && pm === false){
379+
// if 12 and am/pm not specified assume pm
380+
if (hour == 12 && pm === false && am === false) {
381+
hour = 12;
382+
pm = true;
383+
} else if (hour == 12 && pm === false) {
379384
hour = 0;
380-
}
381-
else if(pm === true && hour > 0 && hour < 12){
385+
} else if (pm === true && hour > 0 && hour < 12) {
382386
hour += 12;
383387
}
384388

tests/spec/formatters/ampm.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ describe('formatter/ampm', function(){
184184
'25:60 PM': '2:50 PM',
185185
'83 PM': '8:30 PM',
186186
'27 PM': '2:07 PM',
187-
'33 PM': '3:30 PM'
187+
'33 PM': '3:30 PM',
188+
'23': '11:00 PM',
189+
'00': '12:00 AM',
190+
'12': '12:00 PM'
188191
};
189192

190193
for(var k in re){

0 commit comments

Comments
 (0)