Skip to content

Support Unix timestamps in date formatting - #252

Open
nehachinnasani23 wants to merge 1 commit into
python-babel:masterfrom
nehachinnasani23:fix/timestamp-date-formatting
Open

nehachinnasani23 wants to merge 1 commit into
python-babel:masterfrom
nehachinnasani23:fix/timestamp-date-formatting

Conversation

@nehachinnasani23

Copy link
Copy Markdown

format_date(1700000000) currently raises AssertionError, so the dateformat template filter cannot format Unix timestamps directly. Convert integer and float timestamps to UTC-aware datetimes before the existing timezone conversion. The user's timezone determines the displayed date by default; rebase=False keeps the UTC date.

Fixes #203. This accepts timestamps directly, without adding a flag, consistent with Babel's datetime/time formatting functions accepting numeric timestamps.

Adds nine regression cases covering zero, negative and fractional timestamps, dates crossing midnight in negative and positive UTC offsets, rebase=False, and the Jinja filter. Updates the API documentation and changelog. This branch is independent of #251.

Validation on Python 3.10:

  • All nine new cases fail on unchanged upstream and pass with the fix using Babel 2.12.1.
  • New tests plus existing date formatting tests with Babel 2.18.0: 13 passed.
  • Full suite with Babel 2.12.1: 39 passed, 3 failed. The failures are the existing translation-directory ordering assertions in test_list_translations, test_list_translations_default_locale_exists, and test_multiple_directories; the same three were verified on unchanged upstream during Accept hyphenated locale names from selectors #251 work. PR Fix list-translations() ordering in tests #242 already addresses ordering tests.
  • Black, whitespace checks, and Sphinx HTML build pass.

Prepared with OpenAI Codex assistance. The full supported Python/OS matrix has not been run locally.

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.

Support for timestamp in dateformat

1 participant