Jinja2 Time
Jinja2 Extension for Dates and Times
Installation
jinja2-time is available for download from PyPI via pip:
$ pip install jinja2-time
Usage
Now Tag
The extension comes with a now tag that provides convenient access to the arrow.now() API from your templates.
You can control the output by specifying a format, that will be passed to Python’s strftime():
from jinja2 import Environment
env = Environment(extensions=['jinja2_time.TimeExtension'])
# Timezone 'local', default format -> "2015-12-10"
template = env.from_string("{% now 'local' %}")
# Timezone 'utc', explicit format -> "Thu, 10 Dec 2015 15:49:01"
template = env.from_string("{% now 'utc', '%a, %d %b %Y %H:%M:%S' %}")
# Timezone 'Europe/Berlin', explicit format -> "CET +0100"
template = env.from_string("{% now 'Europe/Berlin', '%Z %z' %}")
# Timezone 'utc', explicit format -> "2015"
template = env.from_string("{% now 'utc', '%Y' %}")
template.render()
Default Datetime Format
TimeExtension extends the environment with a datetime_format attribute.
It is used as a fallback if you omit the format for now.
from jinja2 import Environment
env = Environment(extensions=['jinja2_time.TimeExtension'])
env.datetime_format = '%a, %d %b %Y %H:%M:%S'
# Timezone 'utc', default format -> "Thu, 10 Dec 2015 15:49:01"
template = env.from_string("{% now 'utc' %}")
template.render()
Time Offset
jinja2-time implements a convenient interface to modify now by a relative time offset:
# Examples for now "2015-12-09 23:33:01"
# "Thu, 10 Dec 2015 01:33:31"
"{% now 'utc' + 'hours=2, seconds=30' %}"
# "Wed, 09 Dec 2015 23:22:01"
"{% now 'utc' - 'minutes=11' %}"
# "07 Dec 2015 23:00:00"
"{% now 'utc' - 'days=2, minutes=33, seconds=1', '%d %b %Y %H:%M:%S' %}"
Further documentation on the underlying functionality can be found in the arrow replace docs.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Code of Conduct
Everyone interacting in the jinja2-time project’s codebases, issue trackers, chat rooms, and mailing lists is expected to follow the PyPA Code of Conduct.
License
Distributed under the terms of the MIT license, jinja2-time is free and open source software
Metadata
Release files for jinja2-time 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| jinja2-time-0.2.0.tar.gz | 5.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jinja2_time-0.2.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 12.1 kB
Release files / jinja2-time-0.2.0.tar.gz
| Download URL | jinja2-time-0.2.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d14eaa4d315e7688daa4969f616f226614350c48730bfa1692d2caebd8c90d40
|
|
BLAKE2b-256 checksum How to use checksums |
de7cee2f2014a2a0616ad3328e58e7dac879251babdb4cb796d770b5d32c469f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / jinja2_time-0.2.0-py2.py3-none-any.whl
| Download URL | jinja2_time-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d3eab6605e3ec8b7a0863df09cc1d23714908fa61aa6986a845c20ba488b4efa
|
|
BLAKE2b-256 checksum How to use checksums |
6aa1d44fa38306ffa34a7e1af09632b158e13ec89670ce491f8a15af3ebcb4e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for jinja2-time 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.