diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2016-01-06 19:04:39 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2016-01-06 19:04:39 (GMT) |
commit | f4edd054b264ffe0002dad2ef41bf45a95e4928a (patch) | |
tree | 3db72a8be6a2883948aa61f95f3484a48ea070d5 | |
parent | c547dce30366b3a6097008086cbc0b917c6a2f85 (diff) |
moved tofirstdayinisoweek to utils
-rw-r--r-- | program/utils.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/program/utils.py b/program/utils.py index 9a086da..587e83d 100644 --- a/program/utils.py +++ b/program/utils.py @@ -3,6 +3,7 @@ from django.conf import settings import json import urllib from os.path import join +from datetime import datetime, date, timedelta def get_automation_id_choices(): @@ -26,3 +27,11 @@ def get_automation_id_choices(): shows = [(s['id'], s['title']) for s in shows_list] return shows + + +def tofirstdayinisoweek(year, week): + # http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python + ret = datetime.strptime('%04d-%02d-1' % (year, week), '%Y-%W-%w') + if date(year, 1, 4).isoweekday() > 4: + ret -= timedelta(days=7) + return ret |