Skip to main content

Jinja2 Extension for Dates and Times

Project description

PyPI Package PyPI Python Versions PyPI Package License See Build Status on Travis CI

Jinja2 Extension for Dates and Times

Installation

jinja2-time is available for download from PyPI via pip:

$ pip install jinja2-time

It will automatically install jinja2 along with arrow.

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()

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinja2-time-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

jinja2_time-0.1.0-py2.py3-none-any.whl (5.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jinja2-time-0.1.0.tar.gz.

File metadata

  • Download URL: jinja2-time-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jinja2-time-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1dc60e917be18e7b07d5e908531ff55134f2bb67e1aeb4573a1d0267f33aa91
MD5 bc14d8196c223e94061c9e9fa393a563
BLAKE2b-256 5660e1c8fdaa735c6eb7b9c3ca4466622d8ddf02154682ce0449c2c7b05c4ec4

See more details on using hashes here.

File details

Details for the file jinja2_time-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jinja2_time-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 edf39817f07bf088eabc7c3dbcb9902af3721a4ca9a849873d0d5dfeb5a80318
MD5 78d2f4e7726de4f3132ca07f46047d2b
BLAKE2b-256 989666ed871f0012db79107f988cf6bde960015e9be3b54adb057ce77fa2a391

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page