Permalink
Browse files

Unit names also work in singular form.

  • Loading branch information...
1 parent 0999500 commit f6a0f874cac78bc68f4b29628c27d8e3a7834bc3 @nene committed Feb 16, 2009
Showing with 9 additions and 1 deletion.
  1. +1 −1 jintervals.js
  2. +8 −0 test_jintervals.js
View
@@ -37,7 +37,7 @@ var jintervals = (function() {
// interprets a single interval code -- the text between { and }
// returns the corresponding value
function evalCode(code, t) {
- var re = /^[{]([smhdg])([smhdg]*)?(ays|ours|inutes|econds|reatests|\.)?(\?(.*))?[}]$/i;
+ var re = /^[{]([smhdg])([smhdg]*)?(ays?|ours?|inutes?|econds?|reatests?|\.)?(\?(.*))?[}]$/i;
var matches = re.exec(code);
if (!matches) {
return "?";
View
@@ -158,6 +158,14 @@ test("unit names", function() {
equals(interval("002 00:00:00", "{days}"), "2 days");
});
+test("unit names in singular form", function() {
+ equals(interval("000 00:00:02", "{second}"), "2 seconds");
+ equals(interval("000 00:02:00", "{minute}"), "2 minutes");
+ equals(interval("000 02:00:00", "{hour}"), "2 hours");
+ equals(interval("002 00:00:00", "{day}"), "2 days");
+ equals(interval("002 00:00:00", "{greatest}"), "2 days");
+});
+
test("optionality modifier", function() {
equals(interval("000 00:00:00", "{h?}"), "");
equals(interval("000 00:12:00", "{h?}"), "");

0 comments on commit f6a0f87

Please sign in to comment.