Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for single char 24h HH vs H #30

Merged
merged 4 commits into from

2 participants

@buholzer

I added support for a single H format which allows to have single character 24 hours formatting. Similar to the Java version (see below).

http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

H Hour in day (0-23) Number 0

Let me know if you want me to do anything else in regards to doc's or tests.

Best, Mirko

@phstc
Owner

Hey @buholzer, thank you very much for the contribution! :)

Could you add a test in the Test file?

https://github.com/phstc/jquery-dateFormat/blob/master/Test.html

It will be awesome to test your H format and guarantee that the other formats still working.

Best

@phstc phstc merged commit 88a34ed into from
@joostory joostory referenced this pull request from a commit in joostory/jquery-dateFormat
@joostory joostory #30 pad with 0 eab655a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +2 −1  README.rdoc
  2. +10 −0 Test.html
  3. +7 −0 jquery.dateFormat-1.0.js
View
3  README.rdoc
@@ -27,7 +27,8 @@ http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
* ddd = day of the week in words (Monday, Tuesday ... Sunday)
* h = hour in am/pm (0-12)
* hh = hour in am/pm (00-12)
-* HH = hour in day (00-23)
+* H = hour in day (0-23)
+* HH = hour in day (00-23)
* mm = minute
* ss = second
* SSS = milliseconds
View
10 Test.html
@@ -184,6 +184,16 @@
assertEqual('5', $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('13.01.10 10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy h'));
}},
+ testLongHour: function() { with(this) {
+ assertEqual('17', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'H'));
+ assertEqual('17', $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'H'));
+ assertEqual('13.01.10 10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy H'));
+ assertEqual('6', $.format.date('Wed Jan 25 06:23:38 PST 2012', 'H'));
+ assertEqual('06', $.format.date('Wed Jan 25 06:23:38 PST 2012', 'HH'));
+ assertEqual('17', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'H'));
+ assertEqual('17', $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'H'));
+ assertEqual('13.01.10 10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy H'));
+ }},
testIssue19: function() { with(this) {
assertEqual('Sep 29, 2011', $.format.date("2011-09-29 14:50:49", "MMM dd, yyyy"));
}},
View
7 jquery.dateFormat-1.0.js
@@ -227,6 +227,13 @@
retValue += time.hour;
pattern = "";
break;
+ case "H":
+ if (format.charAt(i + 1) == "H") {
+ break;
+ }
+ retValue += parseInt(time.hour, 10);
+ pattern = "";
+ break;
case "hh":
/* time.hour is "00" as string == is used instead of === */
var hour = (time.hour == 0 ? 12 : time.hour < 13 ? time.hour : time.hour - 12);
Something went wrong with that request. Please try again.