summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2013-09-20 15:34:48 (GMT)
committerErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2013-09-20 15:34:48 (GMT)
commit1e7a2fd39f7cfa90e79fd9fbe00220de7f54520a (patch)
tree1b503b1f850c147a13824b131c3e27fe0bb98c7d /program
parent6ba9e32c9b4397e24ac77fbcaf28802b6e7ff5f7 (diff)
fix week number bug. this time for real.
Diffstat (limited to 'program')
-rw-r--r--program/views.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/program/views.py b/program/views.py
index f9ffcab..4b5737b 100644
--- a/program/views.py
+++ b/program/views.py
@@ -91,10 +91,9 @@ def current_show(request):
def week_schedule(request, year=None, week=None):
if year is None and week is None:
- year, week = datetime.strftime(datetime.today(), '%Y__%W').split('__')
-
- monday = datetime.strptime('%s__%s__1__06__00' % (year, week), '%Y__%W__%w__%H__%M')
+ year, week = datetime.strftime(datetime.now(), '%Y__%V').split('__')
+ monday = tofirstdayinisoweek(int(year), int(week))
tuesday = monday+timedelta(days=1)
wednesday = monday+timedelta(days=2)
thursday = monday+timedelta(days=3)
@@ -148,3 +147,10 @@ def json_day_schedule(request, year=None, month=None, day=None):
schedule.append((ts.start.strftime('%H:%M:%S'), -1))
return HttpResponse(json.dumps(schedule), content_type="application/json")
+
+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 \ No newline at end of file