Format the instance to a common string format.
(self, fmt: str, locale: str | None = None)
| 452 | return self._to_string("w3c") |
| 453 | |
| 454 | def _to_string(self, fmt: str, locale: str | None = None) -> str: |
| 455 | """ |
| 456 | Format the instance to a common string format. |
| 457 | """ |
| 458 | if fmt not in self._FORMATS: |
| 459 | raise ValueError(f"Format [{fmt}] is not supported") |
| 460 | |
| 461 | fmt_value = self._FORMATS[fmt] |
| 462 | if callable(fmt_value): |
| 463 | return fmt_value(self) |
| 464 | |
| 465 | return self.format(fmt_value, locale=locale) |
| 466 | |
| 467 | def __str__(self) -> str: |
| 468 | return self.isoformat(" ") |