Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html_last_updated_fmt does not support UTC offset (%z) #8683

Closed
th0ger opened this issue Jan 12, 2021 · 3 comments · Fixed by #8685
Closed

html_last_updated_fmt does not support UTC offset (%z) #8683

th0ger opened this issue Jan 12, 2021 · 3 comments · Fixed by #8685

Comments

@th0ger
Copy link

th0ger commented Jan 12, 2021

According to Sphinx docs, html_last_updated_fmt uses the strftime().
The python strftime format codes defines: %z as UTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive).

However, with:

html_last_updated_fmt = '%Y-%m-%d %H:%M:%S %z'

I get a literal %z at output:

© Copyright 2020, .... Revision 81dbc58. Last updated on 2021-01-12 07:34:52 %z.

The expected output in my case is ... +0100.

Notes:

  • Uppercase %Z (Time zone name) does "work". On my local box is gives GMT+01:00, but on our CI pipeline is gives the full string Coordinated Universal Time which is a bit anoying. I guess it may be platform dependent.
    The "literal %z"-issue occurs on both platforms.
  • Some basic testing with Python, shows that %z works well with strftime().
  • I have tested all other format tokens and they all work, except %U and %W (week numbers) which throws an exception. Someone may want to raise a separate issue for this.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 12, 2021
…t (%z)

sphinx.util.i18n:format_date() does not support %z so far.  This
adds a mapping for %z to the babel form 'ZZZ'.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 12, 2021
…for %Z

sphinx.util.i18n:format_date() converts '%Z' to full name of time zone
unexpectedly.  It should be converted to short name.
@tk0miya tk0miya added this to the 3.5.0 milestone Jan 12, 2021
@tk0miya
Copy link
Member

tk0miya commented Jan 12, 2021

Thank you for reporting. Both %z and %Z are bugs.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 12, 2021
…t (%z)

sphinx.util.i18n:format_date() does not support %z so far.  This
adds a mapping for %z to the babel form 'ZZZ'.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 12, 2021
…for %Z

sphinx.util.i18n:format_date() converts '%Z' to full name of time zone
unexpectedly.  It should be converted to short name.
@th0ger
Copy link
Author

th0ger commented Jan 12, 2021

@tk0miya thanks for fixing.
I see that test_format_date() needs a little love to fully cover https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
For example %U and %W which fails for me. Will you create an issue for this?

@tk0miya
Copy link
Member

tk0miya commented Jan 12, 2021

Could you try to make a pull request instead of issue? Contributions are always welcome :-)

tk0miya added a commit that referenced this issue Jan 13, 2021
Fix #8683: html_last_updated_fmt does not support UTC offset (%z)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants