Skip to content
This repository has been archived by the owner on Jan 26, 2020. It is now read-only.

Commit

Permalink
added 12 hour string formater & test for 24 hr string formater, and 1…
Browse files Browse the repository at this point in the history
…2 hr string formater
  • Loading branch information
prozacgod committed Mar 29, 2013
1 parent c4dde30 commit 5f4bdf4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/date.spec.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -463,4 +463,22 @@ describe('timezoneJS.Date', function () {
date.setYear(2003); date.setYear(2003);
expect(date.getFullYear()).toEqual(2003); expect(date.getFullYear()).toEqual(2003);
}); });

it('Represents hours in 24 hour format', function () {
for (var i = 0; i < 24; i ++) {
var time_value = new timezoneJS.Date(2013, 1, 1, i, 0, 0, 0, "America/Chicago");
expect(time_value.toString("H")).toEqual(i.toString());
}
});

it('Represents hours in single digit 12 hour format', function () {
for (var i = 0; i < 24; i ++) {
var ampm = i >= 12 ? "PM" : "AM";
var hour = (i % 12);
hour = (hour === 0) ? 12 : hour;

var time_value = new timezoneJS.Date(2013, 1, 1, i, 0, 0, 0, "America/Chicago");
expect(time_value.toString("h k")).toEqual(hour.toString() + " " + ampm);
}
});
}); });
2 changes: 2 additions & 0 deletions src/date.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@
}) })
// `H`: hour // `H`: hour
.replace(/H+/g, function (token) { return _fixWidth(hours, token.length); }) .replace(/H+/g, function (token) { return _fixWidth(hours, token.length); })
// 'h': 12 hour format
.replace(/h+/g, function (token) { return _fixWidth( ((hours%12) === 0) ? 12 : (hours % 12), token.length); })
// `E`: day // `E`: day
.replace(/E+/g, function (token) { return DAYS[_this.getDay()].substring(0, token.length); }) .replace(/E+/g, function (token) { return DAYS[_this.getDay()].substring(0, token.length); })
// `Z`: timezone abbreviation // `Z`: timezone abbreviation
Expand Down

0 comments on commit 5f4bdf4

Please sign in to comment.