From ef6f8d91d68667255d5b0292fd04c3d8c530a65f Mon Sep 17 00:00:00 2001
From: Carlos Vega <carlos.vega@uni.lu>
Date: Fri, 12 Oct 2018 11:09:00 +0200
Subject: [PATCH] added function to get a set of weekdays from a date interval

---
 smash/web/utils.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/smash/web/utils.py b/smash/web/utils.py
index 85341925..81a18cfe 100644
--- a/smash/web/utils.py
+++ b/smash/web/utils.py
@@ -1,6 +1,7 @@
 # coding=utf-8
 from django.utils import timezone
 import datetime, time
+from datetime import timedelta
 
 def timeit(method):
     def timed(*args, **kw):
@@ -21,3 +22,24 @@ def get_today_midnight_date():
 	today_midnight = datetime.datetime(today.year, today.month, today.day, tzinfo=today.tzinfo)
 	return today_midnight
 
+def get_weekdays_in_period(fromdate, todate):
+    '''
+    fromdate and todate must be generated using datetime.date or datetime.datetime like:
+    
+    from datetime import date
+    fromdate = date(2010,1,1)
+    todate = date(2010,3,31)
+
+    fromdate = datetime.datetime(2018, 10, 3, 15, 00, 00)
+    todate = datetime.datetime.today()
+
+    but they must have the same format ! 
+
+
+    Weekdays are returned as isoweekdays like the form described in week_choices from constants.py (starting at 1)
+    '''
+    if todate < fromdate:
+        return set([])
+    day_generator = (fromdate + timedelta(day) for day in xrange((todate - fromdate).days))
+    weekdays = set([date.isoweekday() for date in day_generator])
+    return weekdays
\ No newline at end of file
-- 
GitLab