jinja2-time-0.2.0/0000755000076500000240000000000012726124545014371 5ustar raphaelstaff00000000000000jinja2-time-0.2.0/CONTRIBUTING.rst0000644000076500000240000000023612630307621017023 0ustar raphaelstaff00000000000000============ Contributing ============ Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given. jinja2-time-0.2.0/CONTRIBUTORS.rst0000644000076500000240000000055512726072744017070 0ustar raphaelstaff00000000000000======= Credits ======= Development Lead ---------------- * Raphael Pierzina (`@hackebrot`_) Pull Requests and Patches ------------------------- * Juan Madurga (`@jlmadurga`_) Bug Reports and Suggestions --------------------------- None yet. Why not be the first? .. _`@hackebrot`: https://github.com/hackebrot .. _`@jlmadurga`: https://github.com/jlmadurga jinja2-time-0.2.0/HISTORY.rst0000644000076500000240000000063112726107162016260 0ustar raphaelstaff00000000000000.. :changelog: History ------- 0.2.0 (2016-06-08) ------------------ Features: * Relative time offset via ``"{% now 'utc' + 'hours=2,seconds=30' %}"`` or ``-`` to modify the rendered datetime 0.1.0 (2015-12-11) ------------------ First release on PyPI. Features: * TimeExtension with a ``now`` tag to get the current time in `jinja2`_ templates .. _`jinja2`: https://github.com/mitsuhiko/jinja2 jinja2-time-0.2.0/jinja2_time/0000755000076500000240000000000012726124545016564 5ustar raphaelstaff00000000000000jinja2-time-0.2.0/jinja2_time/__init__.py0000755000076500000240000000027012726123063020671 0ustar raphaelstaff00000000000000# -*- coding: utf-8 -*- from .jinja2_time import TimeExtension __author__ = 'Raphael Pierzina' __email__ = 'raphael@hackebrot.de' __version__ = '0.2.0' __all__ = ['TimeExtension'] jinja2-time-0.2.0/jinja2_time/jinja2_time.py0000755000076500000240000000404012726123063021324 0ustar raphaelstaff00000000000000# -*- coding: utf-8 -*- import arrow from jinja2 import nodes from jinja2.ext import Extension class TimeExtension(Extension): tags = set(['now']) def __init__(self, environment): super(TimeExtension, self).__init__(environment) # add the defaults to the environment environment.extend(datetime_format='%Y-%m-%d') def _datetime(self, timezone, operator, offset, datetime_format): d = arrow.now(timezone) # Parse replace kwargs from offset and include operator replace_params = {} for param in offset.split(','): interval, value = param.split('=') replace_params[interval.strip()] = float(operator + value.strip()) d = d.replace(**replace_params) if datetime_format is None: datetime_format = self.environment.datetime_format return d.strftime(datetime_format) def _now(self, timezone, datetime_format): if datetime_format is None: datetime_format = self.environment.datetime_format return arrow.now(timezone).strftime(datetime_format) def parse(self, parser): lineno = next(parser.stream).lineno node = parser.parse_expression() if parser.stream.skip_if('comma'): datetime_format = parser.parse_expression() else: datetime_format = nodes.Const(None) if isinstance(node, nodes.Add): call_method = self.call_method( '_datetime', [node.left, nodes.Const('+'), node.right, datetime_format], lineno=lineno, ) elif isinstance(node, nodes.Sub): call_method = self.call_method( '_datetime', [node.left, nodes.Const('-'), node.right, datetime_format], lineno=lineno, ) else: call_method = self.call_method( '_now', [node, datetime_format], lineno=lineno, ) return nodes.Output([call_method], lineno=lineno) jinja2-time-0.2.0/jinja2_time.egg-info/0000755000076500000240000000000012726124545020256 5ustar raphaelstaff00000000000000jinja2-time-0.2.0/jinja2_time.egg-info/dependency_links.txt0000644000076500000240000000000112726124545024324 0ustar raphaelstaff00000000000000 jinja2-time-0.2.0/jinja2_time.egg-info/not-zip-safe0000644000076500000240000000000112726124545022504 0ustar raphaelstaff00000000000000 jinja2-time-0.2.0/jinja2_time.egg-info/PKG-INFO0000644000076500000240000001416712726124545021364 0ustar raphaelstaff00000000000000Metadata-Version: 1.1 Name: jinja2-time Version: 0.2.0 Summary: Jinja2 Extension for Dates and Times Home-page: https://github.com/hackebrot/jinja2-time Author: Raphael Pierzina Author-email: raphael@hackebrot.de License: MIT Description: =========== Jinja2 Time =========== |pypi| |pyversions| |license| |travis-ci| Jinja2 Extension for Dates and Times .. |pypi| image:: https://img.shields.io/pypi/v/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time :alt: PyPI Package .. |pyversions| image:: https://img.shields.io/pypi/pyversions/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time/ :alt: PyPI Python Versions .. |license| image:: https://img.shields.io/pypi/l/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time :alt: PyPI Package License .. |travis-ci| image:: https://travis-ci.org/hackebrot/jinja2-time.svg?branch=master :target: https://travis-ci.org/hackebrot/jinja2-time :alt: See Build Status on Travis CI Installation ------------ **jinja2-time** is available for download from `PyPI`_ via `pip`_:: $ pip install jinja2-time It will automatically install `jinja2`_ along with `arrow`_. .. _`jinja2`: https://github.com/mitsuhiko/jinja2 .. _`PyPI`: https://pypi.python.org/pypi .. _`arrow`: https://github.com/crsmithdev/arrow .. _`pip`: https://pypi.python.org/pypi/pip/ 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()`_: .. _`arrow.now()`: http://crsmithdev.com/arrow/#arrow.factory.ArrowFactory.now .. _`strftime()`: https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior .. code-block:: python 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``. .. code-block:: python 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: .. code-block:: python # 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`_. .. _`arrow replace docs`: http://arrow.readthedocs.io/en/latest/#replace-shift Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. .. _`file an issue`: https://github.com/hackebrot/jinja2-time/issues 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`_. .. _`PyPA Code of Conduct`: https://www.pypa.io/en/latest/code-of-conduct/ License ------- Distributed under the terms of the `MIT`_ license, jinja2-time is free and open source software .. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png :align: left :alt: OSI certified :target: https://opensource.org/ .. _`MIT`: http://opensource.org/licenses/MIT Keywords: jinja2,extension,time Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Programming Language :: Python jinja2-time-0.2.0/jinja2_time.egg-info/requires.txt0000644000076500000240000000001512726124545022652 0ustar raphaelstaff00000000000000jinja2 arrow jinja2-time-0.2.0/jinja2_time.egg-info/SOURCES.txt0000644000076500000240000000056412726124545022147 0ustar raphaelstaff00000000000000CONTRIBUTING.rst CONTRIBUTORS.rst HISTORY.rst LICENSE MANIFEST.in README.rst setup.cfg setup.py jinja2_time/__init__.py jinja2_time/jinja2_time.py jinja2_time.egg-info/PKG-INFO jinja2_time.egg-info/SOURCES.txt jinja2_time.egg-info/dependency_links.txt jinja2_time.egg-info/not-zip-safe jinja2_time.egg-info/requires.txt jinja2_time.egg-info/top_level.txt tests/test_now.pyjinja2-time-0.2.0/jinja2_time.egg-info/top_level.txt0000644000076500000240000000001412726124545023003 0ustar raphaelstaff00000000000000jinja2_time jinja2-time-0.2.0/LICENSE0000644000076500000240000000207412640067631015376 0ustar raphaelstaff00000000000000The MIT License (MIT) Copyright (c) 2015 Raphael Pierzina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jinja2-time-0.2.0/MANIFEST.in0000644000076500000240000000030112726071734016122 0ustar raphaelstaff00000000000000include CONTRIBUTORS.rst include CONTRIBUTING.rst include HISTORY.rst include LICENSE include README.rst recursive-include tests * recursive-exclude * __pycache__ recursive-exclude * *.py[co] jinja2-time-0.2.0/PKG-INFO0000644000076500000240000001416712726124545015477 0ustar raphaelstaff00000000000000Metadata-Version: 1.1 Name: jinja2-time Version: 0.2.0 Summary: Jinja2 Extension for Dates and Times Home-page: https://github.com/hackebrot/jinja2-time Author: Raphael Pierzina Author-email: raphael@hackebrot.de License: MIT Description: =========== Jinja2 Time =========== |pypi| |pyversions| |license| |travis-ci| Jinja2 Extension for Dates and Times .. |pypi| image:: https://img.shields.io/pypi/v/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time :alt: PyPI Package .. |pyversions| image:: https://img.shields.io/pypi/pyversions/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time/ :alt: PyPI Python Versions .. |license| image:: https://img.shields.io/pypi/l/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time :alt: PyPI Package License .. |travis-ci| image:: https://travis-ci.org/hackebrot/jinja2-time.svg?branch=master :target: https://travis-ci.org/hackebrot/jinja2-time :alt: See Build Status on Travis CI Installation ------------ **jinja2-time** is available for download from `PyPI`_ via `pip`_:: $ pip install jinja2-time It will automatically install `jinja2`_ along with `arrow`_. .. _`jinja2`: https://github.com/mitsuhiko/jinja2 .. _`PyPI`: https://pypi.python.org/pypi .. _`arrow`: https://github.com/crsmithdev/arrow .. _`pip`: https://pypi.python.org/pypi/pip/ 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()`_: .. _`arrow.now()`: http://crsmithdev.com/arrow/#arrow.factory.ArrowFactory.now .. _`strftime()`: https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior .. code-block:: python 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``. .. code-block:: python 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: .. code-block:: python # 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`_. .. _`arrow replace docs`: http://arrow.readthedocs.io/en/latest/#replace-shift Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. .. _`file an issue`: https://github.com/hackebrot/jinja2-time/issues 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`_. .. _`PyPA Code of Conduct`: https://www.pypa.io/en/latest/code-of-conduct/ License ------- Distributed under the terms of the `MIT`_ license, jinja2-time is free and open source software .. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png :align: left :alt: OSI certified :target: https://opensource.org/ .. _`MIT`: http://opensource.org/licenses/MIT Keywords: jinja2,extension,time Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Programming Language :: Python jinja2-time-0.2.0/README.rst0000644000076500000240000001001312726123063016045 0ustar raphaelstaff00000000000000=========== Jinja2 Time =========== |pypi| |pyversions| |license| |travis-ci| Jinja2 Extension for Dates and Times .. |pypi| image:: https://img.shields.io/pypi/v/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time :alt: PyPI Package .. |pyversions| image:: https://img.shields.io/pypi/pyversions/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time/ :alt: PyPI Python Versions .. |license| image:: https://img.shields.io/pypi/l/jinja2-time.svg :target: https://pypi.python.org/pypi/jinja2-time :alt: PyPI Package License .. |travis-ci| image:: https://travis-ci.org/hackebrot/jinja2-time.svg?branch=master :target: https://travis-ci.org/hackebrot/jinja2-time :alt: See Build Status on Travis CI Installation ------------ **jinja2-time** is available for download from `PyPI`_ via `pip`_:: $ pip install jinja2-time It will automatically install `jinja2`_ along with `arrow`_. .. _`jinja2`: https://github.com/mitsuhiko/jinja2 .. _`PyPI`: https://pypi.python.org/pypi .. _`arrow`: https://github.com/crsmithdev/arrow .. _`pip`: https://pypi.python.org/pypi/pip/ 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()`_: .. _`arrow.now()`: http://crsmithdev.com/arrow/#arrow.factory.ArrowFactory.now .. _`strftime()`: https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior .. code-block:: python 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``. .. code-block:: python 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: .. code-block:: python # 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`_. .. _`arrow replace docs`: http://arrow.readthedocs.io/en/latest/#replace-shift Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. .. _`file an issue`: https://github.com/hackebrot/jinja2-time/issues 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`_. .. _`PyPA Code of Conduct`: https://www.pypa.io/en/latest/code-of-conduct/ License ------- Distributed under the terms of the `MIT`_ license, jinja2-time is free and open source software .. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png :align: left :alt: OSI certified :target: https://opensource.org/ .. _`MIT`: http://opensource.org/licenses/MIT jinja2-time-0.2.0/setup.cfg0000644000076500000240000000036412726124545016215 0ustar raphaelstaff00000000000000[bumpversion] current_version = 0.2.0 commit = True tag = True tag_name = {new_version} [bumpversion:file:setup.py] [bumpversion:file:jinja2_time/__init__.py] [wheel] universal = 1 [egg_info] tag_build = tag_svn_revision = 0 tag_date = 0 jinja2-time-0.2.0/setup.py0000644000076500000240000000306512726123063016101 0ustar raphaelstaff00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- import codecs import os from setuptools import setup def read(fname): file_path = os.path.join(os.path.dirname(__file__), fname) return codecs.open(file_path, encoding='utf-8').read() setup( name='jinja2-time', version='0.2.0', author='Raphael Pierzina', author_email='raphael@hackebrot.de', maintainer='Raphael Pierzina', maintainer_email='raphael@hackebrot.de', license='MIT', url='https://github.com/hackebrot/jinja2-time', description='Jinja2 Extension for Dates and Times', long_description=read('README.rst'), packages=[ 'jinja2_time', ], package_dir={'jinja2_time': 'jinja2_time'}, include_package_data=True, zip_safe=False, install_requires=[ 'jinja2', 'arrow' ], classifiers=[ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Programming Language :: Python', ], keywords=['jinja2', 'extension', 'time'], ) jinja2-time-0.2.0/tests/0000755000076500000240000000000012726124545015533 5ustar raphaelstaff00000000000000jinja2-time-0.2.0/tests/test_now.py0000644000076500000240000000367212726123063017751 0ustar raphaelstaff00000000000000# -*- coding: utf-8 -*- import pytest from freezegun import freeze_time from jinja2 import Environment, exceptions @pytest.fixture def environment(): return Environment(extensions=['jinja2_time.TimeExtension']) @pytest.yield_fixture(autouse=True) def freeze(): freezer = freeze_time("2015-12-09 23:33:01") freezer.start() yield freezer.stop() def test_tz_is_required(environment): with pytest.raises(exceptions.TemplateSyntaxError): environment.from_string('{% now %}') def test_utc_default_datetime_format(environment): template = environment.from_string("{% now 'utc' %}") assert template.render() == "2015-12-09" @pytest.fixture(params=['utc', 'local', 'Europe/Berlin']) def valid_tz(request): return request.param def test_accept_valid_timezones(environment, valid_tz): template = environment.from_string( "{% now '" + valid_tz + "', '%Y-%m' %}" ) assert template.render() == '2015-12' def test_environment_datetime_format(environment): environment.datetime_format = '%a, %d %b %Y %H:%M:%S' template = environment.from_string("{% now 'utc' %}") assert template.render() == "Wed, 09 Dec 2015 23:33:01" def test_add_time(environment): environment.datetime_format = '%a, %d %b %Y %H:%M:%S' template = environment.from_string( "{% now 'utc' + 'hours=2,seconds=30' %}" ) assert template.render() == "Thu, 10 Dec 2015 01:33:31" def test_substract_time(environment): environment.datetime_format = '%a, %d %b %Y %H:%M:%S' template = environment.from_string( "{% now 'utc' - 'minutes=11' %}" ) assert template.render() == "Wed, 09 Dec 2015 23:22:01" def test_offset_with_format(environment): environment.datetime_format = '%d %b %Y %H:%M:%S' template = environment.from_string( "{% now 'utc' - 'days=2, minutes=33,seconds=1', '%d %b %Y %H:%M:%S' %}" ) assert template.render() == "07 Dec 2015 23:00:00"