diff --git a/src/pendulum/datetime.py b/src/pendulum/datetime.py index 96aff25b..48e176f5 100644 --- a/src/pendulum/datetime.py +++ b/src/pendulum/datetime.py @@ -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") diff --git a/tests/datetime/test_strings.py b/tests/datetime/test_strings.py index e78dbc8a..c53768e4 100644 --- a/tests/datetime/test_strings.py +++ b/tests/datetime/test_strings.py @@ -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")