-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = /^\d{4}(-(0[1-9]|1[0-2])(-(0[1-9]|[12][0-9]|3[01]))?)?(T([01][0-9]|2[0-3]):[0-5]\d(:[0-5]\d(\.\d+)?)?(Z|[+-]\d{2}:\d{2}))?$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var assert = require("chai").assert | ||
var iso8601 = require('../lib/iso8601-regex') | ||
|
||
describe("iso8601-regex", function () { | ||
it("should match YYYY", function () { | ||
assert.ok(iso8601.test("2000")) | ||
}) | ||
it("should match YYYY-MM", function () { | ||
assert.ok(iso8601.test("2000-04")) | ||
}) | ||
it("should match YYYY-MM-DD", function () { | ||
assert.ok(iso8601.test("2000-04-01")) | ||
}) | ||
it("should match YYYY-MM-DDThh:mmZ", function () { | ||
assert.ok(iso8601.test("2000-04-01T12:00Z"), 'Z') | ||
assert.ok(iso8601.test("2000-04-01T12:00-08:00"), '-08:00') | ||
assert.ok(iso8601.test("2000-04-01T12:00+01:00"), '+01:00') | ||
}) | ||
it("should match YYYY-MM-DDThh:mm:ssZ", function () { | ||
assert.ok(iso8601.test("2000-04-01T12:00:30Z"), 'Z') | ||
assert.ok(iso8601.test("2000-04-01T12:00:30-08:00"), '-08:00') | ||
assert.ok(iso8601.test("2000-04-01T12:00:30+01:00"), '+01:00') | ||
}) | ||
it("should match YYYY-MM-DDThh:mm:ss.sZ", function () { | ||
assert.ok(iso8601.test("2000-04-01T12:00:30.250Z"), 'Z') | ||
assert.ok(iso8601.test("2000-04-01T12:00:30.250-08:00"), '-08:00') | ||
assert.ok(iso8601.test("2000-04-01T12:00:30.250+01:00"), '+01:00') | ||
}) | ||
it("should not match time without timezone", function () { | ||
assert.notOk(iso8601.test("2000-04-01T12:00"), 'hh:mm') | ||
assert.notOk(iso8601.test("2000-04-01T12:00:00"), 'hh:mm:ss') | ||
assert.notOk(iso8601.test("2000-04-01T12:00:00.000"), 'hh:mm:ss.s') | ||
}) | ||
it("should not match out of range month", function () { | ||
assert.notOk(iso8601.test("2000-00"), '00') | ||
assert.notOk(iso8601.test("2000-13"), '13') | ||
}) | ||
it("should not match out of range day", function () { | ||
assert.notOk(iso8601.test("2000-04-00"), '00') | ||
assert.notOk(iso8601.test("2000-04-32"), '32') | ||
}) | ||
it("should not match out of range hour", function () { | ||
assert.notOk(iso8601.test("2000-04-01T24:00Z")) | ||
}) | ||
it("should not match out of range minute", function () { | ||
assert.notOk(iso8601.test("2000-04-01T12:60Z")) | ||
}) | ||
it("should not match out of range second", function () { | ||
assert.notOk(iso8601.test("2000-04-01T12:00:60Z")) | ||
}) | ||
it("should not match time without timezone", function () { | ||
assert.notOk(iso8601.test("2000-04-01T12:00"), 'hh:mm') | ||
assert.notOk(iso8601.test("2000-04-01T12:00:00"), 'hh:mm:ss') | ||
assert.notOk(iso8601.test("2000-04-01T12:00:00.000"), 'hh:mm:ss.s') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters