Skip to content

Commit 5458db5

Browse files
committed
format "duration"
1 parent 5a15df1 commit 5458db5

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The package defines these formats:
2424
- _date_: full-date according to [RFC3339](http://tools.ietf.org/html/rfc3339#section-5.6).
2525
- _time_: time with optional time-zone.
2626
- _date-time_: date-time from the same source (time-zone is mandatory).
27+
- _duration_: duration from [RFC3339](https://tools.ietf.org/html/rfc3339#appendix-A)
2728
- _uri_: full URI.
2829
- _uri-reference_: URI reference, including full and relative URIs.
2930
- _uri-template_: URI template according to [RFC6570](https://tools.ietf.org/html/rfc6570)

src/formats.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type FormatName =
66
| "date"
77
| "time"
88
| "date-time"
9+
| "duration"
910
| "uri"
1011
| "uri-reference"
1112
| "uri-template"
@@ -30,6 +31,8 @@ export const fullFormats: DefinedFormats = {
3031
// date-time: http://tools.ietf.org/html/rfc3339#section-5.6
3132
time,
3233
"date-time": date_time,
34+
// duration: https://tools.ietf.org/html/rfc3339#appendix-A
35+
duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,
3336
uri,
3437
"uri-reference": /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,
3538
// uri-template: https://tools.ietf.org/html/rfc6570

tests/json-schema.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jsonSchemaTest(ajv, {
1010
suites: {
1111
"draft-07 formats": "./JSON-Schema-Test-Suite/tests/draft7/optional/format/*.json",
1212
"draft-07 regex": "./JSON-Schema-Test-Suite/tests/draft7/optional/ecmascript-regex.json",
13+
"draft-2019-09 formats": "./JSON-Schema-Test-Suite/tests/draft2019-09/optional/format/*.json",
14+
"draft-2019-09 regex":
15+
"./JSON-Schema-Test-Suite/tests/draft2019-09/optional/ecmascript-regex.json",
1316
extras: "./extras/{**/,}*.json",
1417
},
1518
only: [],

0 commit comments

Comments
 (0)