Debian Codegraph @

README.rst

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