|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import io |
4 | | -from datetime import timedelta |
| 4 | +from datetime import date, datetime, time, timedelta |
5 | 5 | from functools import partial |
6 | 6 | from typing import Any, Callable, cast |
7 | 7 |
|
@@ -30,9 +30,9 @@ def __init__(self, *, indent: int): |
30 | 30 | 'generator': partial(self._format_list_like, 'generator((', '))'), |
31 | 31 | 'bytes': self._format_bytes, |
32 | 32 | 'Decimal': partial(self._write, 'Decimal(', ')', True), |
33 | | - 'date': partial(self._write, 'date(', ')', True), |
34 | | - 'datetime': partial(self._write, 'datetime(', ')', True), |
35 | | - 'time': partial(self._write, 'time(', ')', True), |
| 33 | + 'date': self._format_date, |
| 34 | + 'datetime': self._format_datetime, |
| 35 | + 'time': self._format_time, |
36 | 36 | 'timedelta': self._format_timedelta, |
37 | 37 | 'Enum': partial(self._write, '(', ')', True), |
38 | 38 | 'IPv4Address': partial(self._write, 'IPv4Address(', ')', True), |
@@ -273,6 +273,15 @@ def _format_data_frame(self, _indent_current: int, value: list[Any], schema: JSO |
273 | 273 | real_row_count=schema.get('x-row-count', 0), |
274 | 274 | ) |
275 | 275 |
|
| 276 | + def _format_date(self, _indent_current: int, value: Any, schema: JSONSchema | None) -> None: |
| 277 | + self._write('', '', True, 0, date.fromisoformat(value) if isinstance(value, str) else value, schema) |
| 278 | + |
| 279 | + def _format_datetime(self, _indent_current: int, value: Any, schema: JSONSchema | None) -> None: |
| 280 | + self._write('', '', True, 0, datetime.fromisoformat(value) if isinstance(value, str) else value, schema) |
| 281 | + |
| 282 | + def _format_time(self, _indent_current: int, value: Any, schema: JSONSchema | None) -> None: |
| 283 | + self._write('', '', True, 0, time.fromisoformat(value) if isinstance(value, str) else value, schema) |
| 284 | + |
276 | 285 |
|
277 | 286 | json_args_value_formatter = JsonArgsValueFormatter(indent=4) |
278 | 287 | json_args_value_formatter_compact = JsonArgsValueFormatter(indent=0) |
0 commit comments