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

Class Formatter

src/pendulum/formatting/formatter.py:48–698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47
48class Formatter:
49 _TOKENS: str = (
50 r"\[([^\[]*)\]|\\(.)|"
51 "("
52 "Mo|MM?M?M?"
53 "|Do|DDDo|DD?D?D?|ddd?d?|do?|eo?"
54 "|E{1,4}"
55 "|w[o|w]?|W[o|W]?|Qo?"
56 "|YYYY|YY|Y"
57 "|gg(ggg?)?|GG(GGG?)?"
58 "|a|A"
59 "|hh?|HH?|kk?"
60 "|mm?|ss?|S{1,9}"
61 "|x|X"
62 "|zz?|ZZ?"
63 "|LTS|LT|LL?L?L?"
64 ")"
65 )
66
67 _FORMAT_RE: re.Pattern[str] = re.compile(_TOKENS)
68
69 _FROM_FORMAT_RE: re.Pattern[str] = re.compile(r"(?<!\\\[)" + _TOKENS + r"(?!\\\])")
70
71 _LOCALIZABLE_TOKENS: ClassVar[
72 dict[str, str | Callable[[Locale], Sequence[str]] | None]
73 ] = {
74 "Qo": None,
75 "MMMM": "months.wide",
76 "MMM": "months.abbreviated",
77 "Mo": None,
78 "DDDo": None,
79 "Do": lambda locale: tuple(
80 rf"\d+{o}" for o in locale.get("custom.ordinal").values()
81 ),
82 "dddd": "days.wide",
83 "ddd": "days.abbreviated",
84 "dd": "days.short",
85 "do": None,
86 "e": None,
87 "eo": None,
88 "Wo": None,
89 "wo": None,
90 "A": lambda locale: (
91 locale.translation("day_periods.am"),
92 locale.translation("day_periods.pm"),
93 ),
94 "a": lambda locale: (
95 locale.translation("day_periods.am").lower(),
96 locale.translation("day_periods.pm").lower(),
97 ),
98 }
99
100 _TOKENS_RULES: ClassVar[dict[str, Callable[[pendulum.DateTime], str]]] = {
101 # Year
102 "YYYY": lambda dt: f"{dt.year:d}",
103 "YY": lambda dt: f"{dt.year:d}"[2:],
104 "Y": lambda dt: f"{dt.year:d}",
105 # Quarter

Callers 15

__init__.pyFile · 0.90
default.pyFile · 0.90
test_year_tokensFunction · 0.90
test_quarter_tokensFunction · 0.90
test_month_tokensFunction · 0.90
test_day_tokensFunction · 0.90
test_day_of_yearFunction · 0.90
test_week_of_yearFunction · 0.90
test_day_of_weekFunction · 0.90
test_day_of_iso_weekFunction · 0.90
test_am_pmFunction · 0.90

Calls 3

getMethod · 0.80
translationMethod · 0.80
tznameMethod · 0.80

Tested by 15

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…