|
| 1 | + |
| 2 | +import isRFC3339 from "./rfc3339" |
| 3 | + |
| 4 | +describe("isRFC3339", () => { |
| 5 | + const testCases = { |
| 6 | + // From the RFC |
| 7 | + "1985-04-12T23:20:50.52Z": true, |
| 8 | + "1990-12-31T23:59:60Z": true, |
| 9 | + "1990-12-31T15:59:60-08:00": true, |
| 10 | + "1937-01-01T12:00:27.87+00:20": true, |
| 11 | + |
| 12 | + // T and Z can be t or z |
| 13 | + "1985-04-12t23:20:50.52z": true, |
| 14 | + |
| 15 | + // From http://henry.precheur.org/python/rfc3339 |
| 16 | + "2008-04-02T20:00:00Z": true, |
| 17 | + "1970-01-01T00:00:00Z": true, |
| 18 | + |
| 19 | + // https://github.com/chronotope/chrono/blob/main/src/format/parse.rs |
| 20 | + "2015-01-20T17:35:20-08:00": true, // normal case |
| 21 | + "1944-06-06T04:04:00Z": true, // D-day |
| 22 | + "2001-09-11T09:45:00-08:00": true, |
| 23 | + "2015-01-20T17:35:20.001-08:00": true, |
| 24 | + "2015-01-20T17:35:20.000031-08:00": true, |
| 25 | + "2015-01-20T17:35:20.000000004-08:00": true, |
| 26 | + "2015-01-20T17:35:20.000000000452-08:00": true, // too small |
| 27 | + "2015-02-30T17:35:20-08:00": false, // bad day of month |
| 28 | + "2015-01-20T25:35:20-08:00": false, // bad hour |
| 29 | + "2015-01-20T17:65:20-08:00": false, // bad minute |
| 30 | + "2015-01-20T17:35:90-08:00": false, // bad second |
| 31 | + |
| 32 | + // Ensure the regex is anchored |
| 33 | + "x1985-04-12T23:20:50.52Zx": false, |
| 34 | + "1985-04-12T23:20:50.52Zx": false, |
| 35 | + } |
| 36 | + |
| 37 | + for (const [s, expected] of Object.entries(testCases)) { |
| 38 | + it(`correctly validates ${s}`, () => { |
| 39 | + expect(isRFC3339(s)).toEqual(expected) |
| 40 | + }) |
| 41 | + } |
| 42 | +}) |
0 commit comments