Local branding module for CodeRefinery Sphinx projects
Project description
sphinx-localtime: automatic local timezone HTML conversion
This allows you to define a time with a timezone, and HTML renders will show it converted to the apparent local timezone, with a tooltip with the original time.
How it works:
-
The role contains a date and optional format:
:localtime:`10:00 August 8, 2024 +03:00` :localtime:`10:00 August 8, 2024 +03:00 (HH:mm)`
-
At build time (all server-side),
python-dateutilparses those dates and converts it to UTC. -
It embeds the UTC timestamp and some javascript into the built HTML file. When rendered,
dayjsconverts it toHH:mmor the format in parentheses.
Installation
pip install https://github.com/coderefinery/sphinx-localtime/archive/main.zip
(PyPI release to come later)
Add sphinx_localtime to extensions in conf.py
Examples
Show time in hh:mm:
The meeting is at :localtime:`13 Aug 2024 10:00:00 +03:00`.
Show time as hh:mm (on YYYY-MM-DD). [] is used to escape raw
text - this is dayjs syntax:
The course starts at :localtime:`13 Aug 2024 10:00:00
+03:00 (hh:mm [on ]YYYY-MM-DD[)])`
You can show the detected timezone at a certain time with the format
zzz:
The times on this page are automatically converted by your
browser into the timezone :localtime:`13 Aug 2024 (zzz)`.
Usage
The time format can be anything parsed by dateutil.parser.parse. A
parenthesized time format (in the form in
https://day.js.org/docs/en/display/format) is used for the output.
The default output format is HH:mm. Note the escapes aren't
printf standard but what is used by dayjs.
ReST::
:localtime:`13 Aug 2024 10:00:00 +03:00`
:localtime:`13 Aug 2024 10:00:00 +03:00 (D MMM HH:mm)`
:localtime:`13 Aug 2024 (zzz)`
MyST:
{localtime}`13 Aug 2024 10:00:00 +03:00`
{localtime}`13 Aug 2024 10:00:00 +03:00 (D MMM HH:mm)`
{localtime}`13 Aug 2024 (zzz)`
Rendered:
10:00
13 Aug 10:00
Eastern European Summer Time
Specifying timezones in the source
Currently it is safest to use formats such as +03:00, for example
13 Aug 2024 10:00 +03:00.
In order for the conversion to work, you need to specify a timezone in
your original date in a format that dateutil.parser.parse can
understand. This seems to be harder than it looks (if anyone can
help: please do!). What we know:
- Using
+03:00and similar seems safe. - Using long names like
Europe/Helsinkiwould be good butdateutil.parser.parsedoesn't recognize them. - Short abbreviations like
EDT,EESTshould work, but only for some common ones, and it seems that all the summer/daylight saving ones don't. One could generate a list of all abbreviations, but they aren't necessarily unique. (Anything listed inpytz.all_timezones_setshould work).- It does work for your local timezone. So it'll act differently on different build hosts...
- Short non-summer time names are wrong when used in summer time.
Currently it is safest to use formats such as +03:00.
In conf.py you can set a default, then you don't need to add a timezone to every individual localtime role:
import dateutil.tz
localtime_default_tz = dateutil.tz.gettz('Europe/Helsinki')
Status and development
Beta but being used in our own production. Contributions welcome.
Big issues:
- Non-HTML builders work but don't give the most useful output - but it does show something minimally useful so people know what the time is, without localtime conversion.
- Timezone abbreviation lookup could be improved.
- The name could be still changed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_localtime-0.1.0.tar.gz.
File metadata
- Download URL: sphinx_localtime-0.1.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23e744ba4c178be12ec69be8f45b404d23aafd4b953cb1075fd48c49cb63f56e
|
|
| MD5 |
6e3159ea421132d29b0893621a661441
|
|
| BLAKE2b-256 |
fefea190d8630140a2093a1724796827c2572ae49b6d1a6b0109d6cc04a32b84
|
Provenance
The following attestation bundles were made for sphinx_localtime-0.1.0.tar.gz:
Publisher:
release.yml on coderefinery/sphinx-localtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_localtime-0.1.0.tar.gz -
Subject digest:
23e744ba4c178be12ec69be8f45b404d23aafd4b953cb1075fd48c49cb63f56e - Sigstore transparency entry: 227492008
- Sigstore integration time:
-
Permalink:
coderefinery/sphinx-localtime@73ca28945a420d74dbd632537f5e43470632d6b6 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/coderefinery
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73ca28945a420d74dbd632537f5e43470632d6b6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphinx_localtime-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sphinx_localtime-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0ad8a500be24291306ea7bc0459ae53a67f402f5394d85cdc25f6b667e494fc
|
|
| MD5 |
c4cb1a2ec82ff7544a1d92bb9f12beee
|
|
| BLAKE2b-256 |
c2c278bff6c2d4ac58340add66941ea77c2e262c06ae6eba2ece477b24e257d2
|
Provenance
The following attestation bundles were made for sphinx_localtime-0.1.0-py3-none-any.whl:
Publisher:
release.yml on coderefinery/sphinx-localtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_localtime-0.1.0-py3-none-any.whl -
Subject digest:
e0ad8a500be24291306ea7bc0459ae53a67f402f5394d85cdc25f6b667e494fc - Sigstore transparency entry: 227492018
- Sigstore integration time:
-
Permalink:
coderefinery/sphinx-localtime@73ca28945a420d74dbd632537f5e43470632d6b6 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/coderefinery
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73ca28945a420d74dbd632537f5e43470632d6b6 -
Trigger Event:
push
-
Statement type: