diff --git a/program/utils.py b/program/utils.py index 9a086daf1cf7a177def60607f961a5e090a9c9f0..587e83db0e0ff2559b1bd79fa804b68ebcd206af 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