Add way to get clear checkpoints for starting new time periods

This commit is contained in:
Eli Ribble 2015-07-30 14:44:24 -06:00
parent c33e9b3b20
commit fbd519488c
3 changed files with 24 additions and 0 deletions

3
pytest.ini Normal file
View File

@ -0,0 +1,3 @@
[pytest]
norecursedirs = ve
addopts=--tb=short

8
teamanalysis/time.py Normal file
View File

@ -0,0 +1,8 @@
import calendar
import datetime
def get_checkpoint(n):
day_of_week = n.isoweekday()
new_day = n - datetime.timedelta(days=(day_of_week-1))
checkpoint = datetime.datetime(new_day.year, new_day.month, new_day.day, 0, 0, 0, 1)
return checkpoint

13
tests/test_time.py Normal file
View File

@ -0,0 +1,13 @@
import datetime
import pytest
import teamanalysis.time
@pytest.mark.parametrize('when, expected', [
(datetime.datetime(2015, 7, 30, 20, 35, 35, 784435), datetime.datetime(2015, 7, 27, 0, 0, 0, 1)),
(datetime.datetime(2015, 1, 3, 2, 5, 5, 7835), datetime.datetime(2014, 12, 29, 0, 0, 0, 1)),
(datetime.datetime(2015, 1, 5, 2, 5, 5, 7835), datetime.datetime(2015, 1, 5, 0, 0, 0, 1)),
])
def test_checkpoint(when, expected):
checkpoint = teamanalysis.time.get_checkpoint(when)
assert checkpoint == expected