Skip to content

Commit aaa601b

Browse files
author
0x1337
committed
+ Bugfix for leading 0 when using 'm' and 's'
1 parent ee8ed0b commit aaa601b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/dateFormat.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ var DateFormat = {};
354354
if(nextRight === 'm') {
355355
break;
356356
}
357-
retValue += time.minute;
357+
retValue += parseInt(time.minute,10);
358358
pattern = '';
359359
break;
360360
case 'ss':
@@ -366,7 +366,7 @@ var DateFormat = {};
366366
if(nextRight === 's') {
367367
break;
368368
}
369-
retValue += time.second;
369+
retValue += parseInt(time.second,10);
370370
pattern = '';
371371
break;
372372
case 'S':
@@ -444,7 +444,7 @@ var DateFormat = {};
444444
}
445445

446446
diff = (((new Date()).getTime() - date.getTime()) / 1000);
447-
447+
448448
abs_diff = Math.abs(diff);
449449
abs_day_diff = Math.floor(abs_diff / 86400);
450450

@@ -453,7 +453,7 @@ var DateFormat = {};
453453
}
454454

455455
tense = diff < 0 ? 'from now' : 'ago';
456-
456+
457457
if(abs_diff < 60) {
458458
if(diff >= 0)
459459
return 'just now';

test/issues_spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ describe('issues', function() {
7070
// Leading 0 for "SSS"(milliseconds) is missing
7171
expect($.format.date(new Date(2015, 4, 6, 15, 32, 12, 34), 'MM/dd/yyyy HH:mm:ss.SSS')).toEqual('05/06/2015 15:32:12.034');
7272
});
73+
74+
it('formats `m s` `2017-05-10 15:02:03`', function() {
75+
//Leading 0 should not appear in these cases
76+
expect($.format.date(new Date(2017, 4, 10, 15, 2, 3), 'm s')).toEqual('2 3');
77+
});
7378
});

0 commit comments

Comments
 (0)