Skip to content

Commit

Permalink
Fixed multiple bugs in AM/PM. Upgraded version to 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorhakes committed Nov 19, 2015
1 parent 9658599 commit c9c41d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
11 changes: 8 additions & 3 deletions fecha.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
MMM: [word, monthUpdate('monthNamesShort')],
MMMM: [word, monthUpdate('monthNames')],
a: [word, function (d, v) {
if (amPm.indexOf(v.toLowerCase())) {
var val = v.toLowerCase();
if (val === amPm[0]) {
d.isPm = false;
} else if (val === amPm[1]) {
d.isPm = true;
}
}],
Expand Down Expand Up @@ -228,8 +231,10 @@
}

today = new Date();
if (dateInfo.isPm && dateInfo.hour) {
dateInfo.hour = +dateInfo.hour + 12
if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
dateInfo.hour = +dateInfo.hour + 12;
} else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
dateInfo.hour = 0;
}

if (dateInfo.timezoneOffset != null) {
Expand Down
2 changes: 1 addition & 1 deletion fecha.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions fecha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@
it('day name', function () {
expect(fecha.parse('Wednesday Feb 03, 2100', 'dddd MMM DD, YYYY')).toEqual(new Date(2100, 1, 3));
});
it('ampm', function () {
it('ampm 10PM', function () {
expect(fecha.parse('2015-11-07 10PM', 'YYYY-MM-DD hhA')).toEqual(new Date(2015, 10, 7, 22));
});
it('ampm am', function () {
expect(fecha.parse('2000-01-01 12AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2000, 0, 1, 12));
it('ampm 9AM', function () {
expect(fecha.parse('2015-11-07 9AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2015, 10, 7, 9));
});
it('ampm 12am', function () {
expect(fecha.parse('2000-01-01 12AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2000, 0, 1, 0));
});
it('ampm 3am', function () {
expect(fecha.parse('2000-01-01 3AM', 'YYYY-MM-DD hhA')).toEqual(new Date(2000, 0, 1, 3));
});
it('ampm am lowercase', function () {
expect(fecha.parse('2000-01-01 11am', 'YYYY-MM-DD hha')).toEqual(new Date(2000, 0, 1, 11));
});
it('noon pm lowercase', function () {
expect(fecha.parse('2000-01-01 12pm', 'YYYY-MM-DD hha')).toEqual(new Date(2000, 0, 1, 12));
});
it('24 hour time long', function () {
expect(fecha.parse('2000-01-01 20', 'YYYY-MM-DD HH')).toEqual(new Date(2000, 0, 1, 20));
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fecha",
"version": "1.0.0",
"version": "1.1.0",
"description": "Date formatting and parsing",
"main": "fecha.js",
"scripts": {
Expand Down

0 comments on commit c9c41d5

Please sign in to comment.