Skip to content

Commit

Permalink
Fixed issue with timedelta calculation. Replaced with relativedeltas
Browse files Browse the repository at this point in the history
  • Loading branch information
dfezzie committed Apr 21, 2017
1 parent 0a44a1f commit fd31a1f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import mock
from random import randint

Expand Down Expand Up @@ -243,14 +244,10 @@ def _year(x):
assert _week(d) == _week(now - timedelta(weeks=3-idx))
# 2 - months
for idx, d in enumerate(d2):
this_month = now.replace(day=1) # work with first day of month
months_ago = (5 - idx) * 365 / 12 # no 'months' arg for timedelta
assert _month(d) == _month(this_month - timedelta(months_ago))
assert _month(d) == _month(now - relativedelta(months=(5 - idx)))
# 3 - years
for idx, d in enumerate(d3):
this_year = now.replace(month=1, day=1) # work with first day of year
years_ago = (1 - idx) * 365 # no 'years' arg for timedelta
assert _year(d) == _year(this_year - timedelta(years_ago))
assert _year(d) == _year(now - relativedelta(years=(1-idx)))


def test_chain_events():
Expand Down

0 comments on commit fd31a1f

Please sign in to comment.