| 1 |
Metadata-Version: 1.1 |
| 2 |
Name: jinja2-time |
| 3 |
Version: 0.2.0 |
| 4 |
Summary: Jinja2 Extension for Dates and Times |
| 5 |
Home-page: https://github.com/hackebrot/jinja2-time |
| 6 |
Author: Raphael Pierzina |
| 7 |
Author-email: [email protected] |
| 8 |
License: MIT |
| 9 |
Description: =========== |
| 10 |
Jinja2 Time |
| 11 |
=========== |
| 12 |
|
| 13 |
|pypi| |pyversions| |license| |travis-ci| |
| 14 |
|
| 15 |
Jinja2 Extension for Dates and Times |
| 16 |
|
| 17 |
.. |pypi| image:: https://img.shields.io/pypi/v/jinja2-time.svg |
| 18 |
:target: https://pypi.python.org/pypi/jinja2-time |
| 19 |
:alt: PyPI Package |
| 20 |
|
| 21 |
.. |pyversions| image:: https://img.shields.io/pypi/pyversions/jinja2-time.svg |
| 22 |
:target: https://pypi.python.org/pypi/jinja2-time/ |
| 23 |
:alt: PyPI Python Versions |
| 24 |
|
| 25 |
.. |license| image:: https://img.shields.io/pypi/l/jinja2-time.svg |
| 26 |
:target: https://pypi.python.org/pypi/jinja2-time |
| 27 |
:alt: PyPI Package License |
| 28 |
|
| 29 |
.. |travis-ci| image:: https://travis-ci.org/hackebrot/jinja2-time.svg?branch=master |
| 30 |
:target: https://travis-ci.org/hackebrot/jinja2-time |
| 31 |
:alt: See Build Status on Travis CI |
| 32 |
|
| 33 |
Installation |
| 34 |
------------ |
| 35 |
|
| 36 |
**jinja2-time** is available for download from `PyPI`_ via `pip`_:: |
| 37 |
|
| 38 |
$ pip install jinja2-time |
| 39 |
|
| 40 |
It will automatically install `jinja2`_ along with `arrow`_. |
| 41 |
|
| 42 |
.. _`jinja2`: https://github.com/mitsuhiko/jinja2 |
| 43 |
.. _`PyPI`: https://pypi.python.org/pypi |
| 44 |
.. _`arrow`: https://github.com/crsmithdev/arrow |
| 45 |
.. _`pip`: https://pypi.python.org/pypi/pip/ |
| 46 |
|
| 47 |
Usage |
| 48 |
----- |
| 49 |
|
| 50 |
Now Tag |
| 51 |
~~~~~~~ |
| 52 |
|
| 53 |
The extension comes with a ``now`` tag that provides convenient access to the |
| 54 |
`arrow.now()`_ API from your templates. |
| 55 |
|
| 56 |
You can control the output by specifying a format, that will be passed to |
| 57 |
Python's `strftime()`_: |
| 58 |
|
| 59 |
.. _`arrow.now()`: http://crsmithdev.com/arrow/#arrow.factory.ArrowFactory.now |
| 60 |
.. _`strftime()`: https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior |
| 61 |
|
| 62 |
.. code-block:: python |
| 63 |
|
| 64 |
from jinja2 import Environment |
| 65 |
|
| 66 |
env = Environment(extensions=['jinja2_time.TimeExtension']) |
| 67 |
|
| 68 |
# Timezone 'local', default format -> "2015-12-10" |
| 69 |
template = env.from_string("{% now 'local' %}") |
| 70 |
|
| 71 |
# Timezone 'utc', explicit format -> "Thu, 10 Dec 2015 15:49:01" |
| 72 |
template = env.from_string("{% now 'utc', '%a, %d %b %Y %H:%M:%S' %}") |
| 73 |
|
| 74 |
# Timezone 'Europe/Berlin', explicit format -> "CET +0100" |
| 75 |
template = env.from_string("{% now 'Europe/Berlin', '%Z %z' %}") |
| 76 |
|
| 77 |
# Timezone 'utc', explicit format -> "2015" |
| 78 |
template = env.from_string("{% now 'utc', '%Y' %}") |
| 79 |
|
| 80 |
template.render() |
| 81 |
|
| 82 |
Default Datetime Format |
| 83 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 84 |
|
| 85 |
**TimeExtension** extends the environment with a ``datetime_format`` attribute. |
| 86 |
|
| 87 |
It is used as a fallback if you omit the format for ``now``. |
| 88 |
|
| 89 |
.. code-block:: python |
| 90 |
|
| 91 |
from jinja2 import Environment |
| 92 |
|
| 93 |
env = Environment(extensions=['jinja2_time.TimeExtension']) |
| 94 |
|
| 95 |
env.datetime_format = '%a, %d %b %Y %H:%M:%S' |
| 96 |
|
| 97 |
# Timezone 'utc', default format -> "Thu, 10 Dec 2015 15:49:01" |
| 98 |
template = env.from_string("{% now 'utc' %}") |
| 99 |
|
| 100 |
template.render() |
| 101 |
|
| 102 |
Time Offset |
| 103 |
~~~~~~~~~~~ |
| 104 |
|
| 105 |
**jinja2-time** implements a convenient interface to modify ``now`` by a |
| 106 |
relative time offset: |
| 107 |
|
| 108 |
.. code-block:: python |
| 109 |
|
| 110 |
# Examples for now "2015-12-09 23:33:01" |
| 111 |
|
| 112 |
# "Thu, 10 Dec 2015 01:33:31" |
| 113 |
"{% now 'utc' + 'hours=2, seconds=30' %}" |
| 114 |
|
| 115 |
# "Wed, 09 Dec 2015 23:22:01" |
| 116 |
"{% now 'utc' - 'minutes=11' %}" |
| 117 |
|
| 118 |
# "07 Dec 2015 23:00:00" |
| 119 |
"{% now 'utc' - 'days=2, minutes=33, seconds=1', '%d %b %Y %H:%M:%S' %}" |
| 120 |
|
| 121 |
Further documentation on the underlying functionality can be found in the |
| 122 |
`arrow replace docs`_. |
| 123 |
|
| 124 |
.. _`arrow replace docs`: http://arrow.readthedocs.io/en/latest/#replace-shift |
| 125 |
|
| 126 |
|
| 127 |
Issues |
| 128 |
------ |
| 129 |
|
| 130 |
If you encounter any problems, please `file an issue`_ along with a detailed description. |
| 131 |
|
| 132 |
.. _`file an issue`: https://github.com/hackebrot/jinja2-time/issues |
| 133 |
|
| 134 |
|
| 135 |
Code of Conduct |
| 136 |
--------------- |
| 137 |
|
| 138 |
Everyone interacting in the jinja2-time project's codebases, issue trackers, chat |
| 139 |
rooms, and mailing lists is expected to follow the `PyPA Code of Conduct`_. |
| 140 |
|
| 141 |
.. _`PyPA Code of Conduct`: https://www.pypa.io/en/latest/code-of-conduct/ |
| 142 |
|
| 143 |
License |
| 144 |
------- |
| 145 |
|
| 146 |
Distributed under the terms of the `MIT`_ license, jinja2-time is free and open source software |
| 147 |
|
| 148 |
.. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png |
| 149 |
:align: left |
| 150 |
:alt: OSI certified |
| 151 |
:target: https://opensource.org/ |
| 152 |
|
| 153 |
.. _`MIT`: http://opensource.org/licenses/MIT |
| 154 |
|
| 155 |
Keywords: jinja2,extension,time |
| 156 |
Platform: UNKNOWN |
| 157 |
Classifier: Development Status :: 3 - Alpha |
| 158 |
Classifier: Intended Audience :: Developers |
| 159 |
Classifier: License :: OSI Approved :: MIT License |
| 160 |
Classifier: Natural Language :: English |
| 161 |
Classifier: Operating System :: OS Independent |
| 162 |
Classifier: Programming Language :: Python :: 2 |
| 163 |
Classifier: Programming Language :: Python :: 2.7 |
| 164 |
Classifier: Programming Language :: Python :: 3 |
| 165 |
Classifier: Programming Language :: Python :: 3.3 |
| 166 |
Classifier: Programming Language :: Python :: 3.4 |
| 167 |
Classifier: Programming Language :: Python :: 3.5 |
| 168 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 169 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 170 |
Classifier: Programming Language :: Python |