Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pendulum/mixins/default.py: 53%
17 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-30 06:11 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-30 06:11 +0000
1from __future__ import annotations
3from pendulum.formatting import Formatter
6_formatter = Formatter()
9class FormattableMixin:
10 _formatter: Formatter = _formatter
12 def format(self, fmt: str, locale: str | None = None) -> str:
13 """
14 Formats the instance using the given format.
16 :param fmt: The format to use
17 :param locale: The locale to use
18 """
19 return self._formatter.format(self, fmt, locale)
21 def for_json(self) -> str:
22 """
23 Methods for automatic json serialization by simplejson.
24 """
25 return self.isoformat()
27 def __format__(self, format_spec: str) -> str:
28 if len(format_spec) > 0:
29 if "%" in format_spec:
30 return self.strftime(format_spec)
32 return self.format(format_spec)
34 return str(self)
36 def __str__(self) -> str:
37 return self.isoformat()