MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / format

Method format

src/pendulum/formatting/formatter.py:245–266  ·  view source on GitHub ↗

Formats a DateTime instance with a given format and locale. :param dt: The instance to format :param fmt: The format to use :param locale: The locale to use

(
        self, dt: pendulum.DateTime, fmt: str, locale: str | Locale | None = None
    )

Source from the content-addressed store, hash-verified

243 }
244
245 def format(
246 self, dt: pendulum.DateTime, fmt: str, locale: str | Locale | None = None
247 ) -> str:
248 """
249 Formats a DateTime instance with a given format and locale.
250
251 :param dt: The instance to format
252 :param fmt: The format to use
253 :param locale: The locale to use
254 """
255 loaded_locale: Locale = Locale.load(locale or pendulum.get_locale())
256
257 result = self._FORMAT_RE.sub(
258 lambda m: m.group(1)
259 if m.group(1)
260 else m.group(2)
261 if m.group(2)
262 else self._format_token(dt, m.group(3), loaded_locale),
263 fmt,
264 )
265
266 return result
267
268 def _format_token(self, dt: pendulum.DateTime, token: str, locale: Locale) -> str:
269 """

Callers 15

_format_tokenMethod · 0.95
test_year_tokensFunction · 0.95
test_quarter_tokensFunction · 0.95
test_month_tokensFunction · 0.95
test_day_tokensFunction · 0.95
test_day_of_yearFunction · 0.95
test_week_of_yearFunction · 0.95
test_day_of_weekFunction · 0.95
test_day_of_iso_weekFunction · 0.95
test_am_pmFunction · 0.95
test_hourFunction · 0.95

Calls 2

_format_tokenMethod · 0.95
loadMethod · 0.80

Tested by 15

test_year_tokensFunction · 0.76
test_quarter_tokensFunction · 0.76
test_month_tokensFunction · 0.76
test_day_tokensFunction · 0.76
test_day_of_yearFunction · 0.76
test_week_of_yearFunction · 0.76
test_day_of_weekFunction · 0.76
test_day_of_iso_weekFunction · 0.76
test_am_pmFunction · 0.76
test_hourFunction · 0.76
test_minuteFunction · 0.76