Skip to content

Commit c2259ee

Browse files
committed
improved date-time format validation (issue #37)
minor change to license format.
1 parent f7dac29 commit c2259ee

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/formats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function validateFormatPhone(obj) {
3535
var formats = {
3636
'date-time': { // ISO 8601 (YYYY-MM-DDThh:mm:ssZ in UTC time)
3737
types: ['string'],
38-
regex: /^\d{4}-\d{2}-\d{2}T[0-2]\d:[0-5]\d:[0-5]\d([.,]\d+)?Z$/
38+
regex: /^(\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?))?$/
3939
},
4040
'date': { // YYYY-MM-DD
4141
types: ['string'],

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "json-gate",
33
"description": "A friendly, fast JSON schema validator",
4-
"version": "0.8.22",
4+
"version": "0.8.23",
55
"author": {
66
"name": "Ofer Reichman",
77
"email": "[email protected]"
@@ -52,10 +52,5 @@
5252
"engines": {
5353
"node": "*"
5454
},
55-
"licenses": [
56-
{
57-
"type": "MIT",
58-
"url": "https://raw.github.com/oferei/json-gate/master/LICENSE"
59-
}
60-
]
55+
"license": "MIT"
6156
}

test/object-format-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ var objDateTimeFractionComma = {
1818
dateTime: '2012-11-06T09:13:24,142857Z'
1919
};
2020

21+
var objDateTimeWithAheadOffset = {
22+
dateTime: '2016-10-18T11:11:11.616+05'
23+
};
24+
25+
var objDateTimeWithBehindOffset = {
26+
dateTime: '2016-10-18T11:11:11.616-05'
27+
};
28+
2129
var objInvalidDateTime = {
2230
dateTime: '2012-11-06'
2331
};
@@ -311,6 +319,8 @@ vows.describe('Object Format').addBatch({
311319
'when a date-time is passed for a date-time': objectShouldBeValid(objDateTime, schemaDateTime),
312320
'when a date-time with a dot fraction is passed for a date-time': objectShouldBeValid(objDateTimeFractionDot, schemaDateTime),
313321
'when a date-time with a comma fraction is passed for a date-time': objectShouldBeValid(objDateTimeFractionComma, schemaDateTime),
322+
'when a date-time with a ahead offset is passed for a date-time': objectShouldBeValid(objDateTimeWithAheadOffset, schemaDateTime),
323+
'when a date-time with a behind offset is passed for a date-time': objectShouldBeValid(objDateTimeWithBehindOffset, schemaDateTime),
314324
'when a date-time is passed for a date-time': objectShouldBeValid(objDateTime, schemaDateTime),
315325
'when trying to pass a date for a date-time': objectShouldBeInvalid(objInvalidDateTime, schemaDateTime, { errMsg: 'JSON object property \'dateTime\' does not conform to the \'date-time\' format' }),
316326
'when a date is passed for a date': objectShouldBeValid(objDate, schemaDate),

0 commit comments

Comments
 (0)