hackebrot/jinja2-time

Don't work correctly relative time offsets in RHEL

Opened this issue · 1 comments

Crash when i'm trying to add month (or years) offset in Red Hat Linux (in Windows it's works successfully).

>>> from jinja2 import Environment
>>> env = Environment(extensions=['jinja2_time.TimeExtension'])
>>> env.from_string("{% now 'utc' + 'months=1' %}").render()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 1, in top-level template code
  File "/usr/lib/python2.7/site-packages/jinja2_time/jinja2_time.py", line 26, in _datetime
    d = d.replace(**replace_params)
  File "/usr/lib/python2.7/site-packages/arrow/arrow.py", line 495, in replace
    current += relativedelta(**relative_kwargs) # TODO: DEPRECATED
  File "/usr/lib/python2.7/site-packages/dateutil/relativedelta.py", line 318, in __radd__
    return self.__add__(other)
  File "/usr/lib/python2.7/site-packages/dateutil/relativedelta.py", line 290, in __add__
    day = min(calendar.monthrange(year, month)[1],
  File "/usr/lib64/python2.7/calendar.py", line 121, in monthrange
    day1 = weekday(year, month, 1)
  File "/usr/lib64/python2.7/calendar.py", line 113, in weekday
    return datetime.date(year, month, day).weekday()
TypeError: integer argument expected, got float

Python version == 2.7.5

Problem in replace function of arrow package:

>>> import arrow
>>> d = arrow.now()
>>> d
<Arrow [2018-09-17T10:43:43.396398+03:00]>
>>> d.replace(days=1)
<Arrow [2018-09-18T10:43:43.396398+03:00]>
>>> d.replace(months=1)
<Arrow [2018-10-17T10:43:43.396398+03:00]>
>>> d.replace(months=1.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/arrow/arrow.py", line 495, in replace
    current += relativedelta(**relative_kwargs) # TODO: DEPRECATED
  File "/usr/lib/python2.7/site-packages/dateutil/relativedelta.py", line 318, in __radd__
    return self.__add__(other)
  File "/usr/lib/python2.7/site-packages/dateutil/relativedelta.py", line 290, in __add__
    day = min(calendar.monthrange(year, month)[1],
  File "/usr/lib64/python2.7/calendar.py", line 121, in monthrange
    day1 = weekday(year, month, 1)
  File "/usr/lib64/python2.7/calendar.py", line 113, in weekday
    return datetime.date(year, month, day).weekday()
TypeError: integer argument expected, got float