Skip to content

Commit

Permalink
escape periods in regex when that's what you mean
Browse files Browse the repository at this point in the history
  • Loading branch information
zackdever committed Sep 16, 2012
1 parent d90d12e commit 744e8ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 9 additions & 0 deletions test/time.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
5 changes: 1 addition & 4 deletions time.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
(function() {

// TODO support military time
// TODO make military time optional
// TODO make british delineation optional
var am = 'am'
, pm = 'pm';

Expand All @@ -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'
Expand Down

0 comments on commit 744e8ea

Please sign in to comment.