Skip to content

Keep RFC and RSS strings in English regardless of the locale - #1063

Open
PDGGK wants to merge 1 commit into
python-pendulum:masterfrom
PDGGK:fix-common-formats-locale
Open

PDGGK wants to merge 1 commit into
python-pendulum:masterfrom
PDGGK:fix-common-formats-locale

Conversation

@PDGGK

@PDGGK PDGGK commented Oct 20, 2026

Copy link
Copy Markdown

After pendulum.set_locale(...), the RFC 822/850/1036/1123/2822 and RSS string methods use the locale's day and month names, which email, HTTP and RSS parsers reject:

import email.utils, pendulum

dt = pendulum.datetime(1975, 12, 25, 14, 15, 16)
pendulum.set_locale("fr")
dt.to_rfc2822_string()  # 'jeu., 25 déc. 1975 14:15:16 +0000'
email.utils.parsedate_to_datetime(dt.to_rfc2822_string())
# ValueError: Invalid date value or format "jeu., 25 déc. 1975 14:15:16 +0000"

These formats are protocol formats with fixed English names, and the docs show them in English. to_cookie_string() and to_day_datetime_string() already pass locale="en"; this makes _to_string default to English so the other common formats behave the same. format() keeps using the current locale.

With the change, to_rfc2822_string() returns Thu, 25 Dec 1975 14:15:16 +0000, which email.utils parses.

  • Added tests for changed code (test_common_formats_are_not_localized, which fails for the six affected methods without the change).
  • Updated documentation for changed code (no change needed; the docs already show English output).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant