Permalink
Browse files

escape periods in regex when that's what you mean

  • Loading branch information...
1 parent d90d12e commit 744e8ea86fae3299d99586c0b038076b76a86cec @zackdever committed Sep 16, 2012
Showing with 10 additions and 4 deletions.
  1. +9 −0 test/time.test.js
  2. +1 −4 time.js
View
@@ -41,6 +41,15 @@ describe('Time', function() {
}
});
+ it('should fail with bogus am/pm values', function() {
+ time('8ap').isValid().should.not.be.ok;
+ time('ap').isValid().should.not.be.ok;
+ time('a').isValid().should.not.be.ok;
+ time('am').isValid().should.not.be.ok;
+ time('a.m.').isValid().should.not.be.ok;
+ time('2 ama').isValid().should.not.be.ok;
+ });
+
it('should pass all the hours with all the minutes 1:00 - 12:59', function() {
var hour, minute, result, input;
for (var i = 0; i < hours.length; i++) {
View
@@ -1,8 +1,5 @@
(function() {
- // TODO support military time
- // TODO make military time optional
- // TODO make british delineation optional
var am = 'am'
, pm = 'pm';
@@ -11,7 +8,7 @@
else window.Time = Time;
// what you might expect to be a valid time e.g. 2, 2:00a, 12:18, 4.23 p.m.
- Time.re = /^(10|11|12|[1-9])(?::|\.)?([0-5][0-9])?([ap].?(m.?)?)?$/;
+ Time.re = /^(10|11|12|[1-9])(?::|\.)?([0-5][0-9])?([ap]\.?(m\.?)?)?$/;
/*
* Time constructor works with(out) 'new'

0 comments on commit 744e8ea

Please sign in to comment.