Permalink
Browse files

added 12 hour string formater & test for 24 hr string formater, and 1…

…2 hr string formater
  • Loading branch information...
1 parent c4dde30 commit 5f4bdf4bcb95eaec3176d344082b67ca79bd8f4f @prozacgod prozacgod committed Mar 29, 2013
Showing with 20 additions and 0 deletions.
  1. +18 −0 spec/date.spec.js
  2. +2 −0 src/date.js
View
@@ -463,4 +463,22 @@ describe('timezoneJS.Date', function () {
date.setYear(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);
+ }
+ });
});
View
@@ -473,6 +473,8 @@
})
// `H`: hour
.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
.replace(/E+/g, function (token) { return DAYS[_this.getDay()].substring(0, token.length); })
// `Z`: timezone abbreviation

0 comments on commit 5f4bdf4

Please sign in to comment.