Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,11 @@ def to_w3c_string(self) -> str:
"""
return self._to_string("w3c")

def _to_string(self, fmt: str, locale: str | None = None) -> str:
def _to_string(self, fmt: str, locale: str = "en") -> str:
"""
Format the instance to a common string format.

These formats use English day and month names whatever the current locale.
"""
if fmt not in self._FORMATS:
raise ValueError(f"Format [{fmt}] is not supported")
Expand Down
18 changes: 18 additions & 0 deletions tests/datetime/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ def test_to_w3c_string():
assert d.to_w3c_string() == "1975-12-25T14:15:16-05:00"


@pytest.mark.parametrize(
"method, expected",
[
("to_cookie_string", "Thursday, 25-Dec-1975 14:15:16 EST"),
("to_rfc822_string", "Thu, 25 Dec 75 14:15:16 -0500"),
("to_rfc850_string", "Thursday, 25-Dec-75 14:15:16 EST"),
("to_rfc1036_string", "Thu, 25 Dec 75 14:15:16 -0500"),
("to_rfc1123_string", "Thu, 25 Dec 1975 14:15:16 -0500"),
("to_rfc2822_string", "Thu, 25 Dec 1975 14:15:16 -0500"),
("to_rss_string", "Thu, 25 Dec 1975 14:15:16 -0500"),
],
)
def test_common_formats_are_not_localized(method, expected):
pendulum.set_locale("fr")
d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")
assert getattr(d, method)() == expected


def test_to_string_invalid():
d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local")

Expand Down