Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pendulum/mixins/default.py: 50%
16 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1from ..formatting import Formatter
4_formatter = Formatter()
7class FormattableMixin(object):
9 _formatter = _formatter
11 def format(self, fmt, locale=None):
12 """
13 Formats the instance using the given format.
15 :param fmt: The format to use
16 :type fmt: str
18 :param locale: The locale to use
19 :type locale: str or None
21 :rtype: str
22 """
23 return self._formatter.format(self, fmt, locale)
25 def for_json(self):
26 """
27 Methods for automatic json serialization by simplejson
29 :rtype: str
30 """
31 return str(self)
33 def __format__(self, format_spec):
34 if len(format_spec) > 0:
35 if "%" in format_spec:
36 return self.strftime(format_spec)
38 return self.format(format_spec)
40 return str(self)
42 def __str__(self):
43 return self.isoformat()