Skip to content

Commit c9c41d5

Browse files
author
taylorhakes
committed
Fixed multiple bugs in AM/PM. Upgraded version to 1.1.0
1 parent 9658599 commit c9c41d5

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

fecha.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151
MMM: [word, monthUpdate('monthNamesShort')],
5252
MMMM: [word, monthUpdate('monthNames')],
5353
a: [word, function (d, v) {
54-
if (amPm.indexOf(v.toLowerCase())) {
54+
var val = v.toLowerCase();
55+
if (val === amPm[0]) {
56+
d.isPm = false;
57+
} else if (val === amPm[1]) {
5558
d.isPm = true;
5659
}
5760
}],
@@ -228,8 +231,10 @@
228231
}
229232

230233
today = new Date();
231-
if (dateInfo.isPm && dateInfo.hour) {
232-
dateInfo.hour = +dateInfo.hour + 12
234+
if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
235+
dateInfo.hour = +dateInfo.hour + 12;
236+
} else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
237+
dateInfo.hour = 0;
233238
}
234239

235240
if (dateInfo.timezoneOffset != null) {

fecha.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fecha.spec.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,24 @@
3939
it('day name', function () {
4040
expect(fecha.parse('Wednesday Feb 03, 2100', 'dddd MMM DD, YYYY')).toEqual(new Date(2100, 1, 3));
4141
});
42-
it('ampm', function () {
42+
it('ampm 10PM', function () {
4343
expect(fecha.parse('2015-11-07 10PM', 'YYYY-MM-DD hhA')).toEqual(new Date(2015, 10, 7, 22));
4444
});
45-
it('ampm am', function () {
46-
expect(fecha.parse('2000-01-01 12AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2000, 0, 1, 12));
45+
it('ampm 9AM', function () {
46+
expect(fecha.parse('2015-11-07 9AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2015, 10, 7, 9));
47+
});
48+
it('ampm 12am', function () {
49+
expect(fecha.parse('2000-01-01 12AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2000, 0, 1, 0));
50+
});
51+
it('ampm 3am', function () {
52+
expect(fecha.parse('2000-01-01 3AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2000, 0, 1, 3));
4753
});
4854
it('ampm am lowercase', function () {
4955
expect(fecha.parse('2000-01-01 11am', 'YYYY-MM-DD hha')).toEqual(new Date(2000, 0, 1, 11));
5056
});
57+
it('noon pm lowercase', function () {
58+
expect(fecha.parse('2000-01-01 12pm', 'YYYY-MM-DD hha')).toEqual(new Date(2000, 0, 1, 12));
59+
});
5160
it('24 hour time long', function () {
5261
expect(fecha.parse('2000-01-01 20', 'YYYY-MM-DD HH')).toEqual(new Date(2000, 0, 1, 20));
5362
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fecha",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Date formatting and parsing",
55
"main": "fecha.js",
66
"scripts": {

0 commit comments

Comments
 (0)