Parse a string and return a datetime.date. Raise ValueError if the input is well formatted but not a valid date. Return None if the input isn't well formatted.
(value)
| 66 | |
| 67 | |
| 68 | def parse_date(value): |
| 69 | """Parse a string and return a datetime.date. |
| 70 | |
| 71 | Raise ValueError if the input is well formatted but not a valid date. |
| 72 | Return None if the input isn't well formatted. |
| 73 | """ |
| 74 | try: |
| 75 | return datetime.date.fromisoformat(value) |
| 76 | except ValueError: |
| 77 | if match := date_re.match(value): |
| 78 | kw = {k: int(v) for k, v in match.groupdict().items()} |
| 79 | return datetime.date(**kw) |
| 80 | |
| 81 | |
| 82 | def parse_time(value): |