Skip to content

Commit aea25fa

Browse files
committed
Micro-optimize RFC3339 checker
Slight adjustments to the regex to make it faster. Use character classes for trivial ORs and check the bounds on day-of-month in the regex.
1 parent 439860f commit aea25fa

File tree

1 file changed

+6
-5
lines changed
  • src/check_jsonschema/formats/implementations

1 file changed

+6
-5
lines changed

src/check_jsonschema/formats/implementations/rfc3339.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@
3434
-
3535
(?:0[1-9]|1[0-2])
3636
-
37-
(?:\d{2})
38-
(?:T|t)
37+
(?:[0-3]\d)
38+
(?:[Tt])
3939
(?:[01]\d|2[0123])
4040
:
4141
(?:[0-5]\d)
4242
:
4343
(?:[0-5]\d)
4444
# (optional) fractional seconds
45-
(?:(\.|,)\d+)?
45+
(?:[\.,]\d+)?
4646
# UTC or offset
4747
(?:
48-
Z
49-
| z
48+
[Zz]
5049
| [+-](?:[01]\d|2[0123]):[0-5]\d
5150
)
5251
$
@@ -84,6 +83,8 @@ def validate(date_str: object) -> bool:
8483
("basic", "2018-12-31T23:59:59Z"),
8584
("in_february", "2018-02-12T23:59:59Z"),
8685
("in_february_invalid", "2018-02-29T23:59:59Z"),
86+
("missing_t", "2018-12-31 23:59:59Z"),
87+
("invalid_day", "2018-12-41T23:59:59Z"),
8788
)
8889

8990
print("benchmarking")

0 commit comments

Comments
 (0)