Skip to content
Snippets Groups Projects
Commit ef6f8d91 authored by Carlos Vega's avatar Carlos Vega
Browse files

added function to get a set of weekdays from a date interval

parent 453e4e33
No related branches found
No related tags found
1 merge request!171Feature/daily availability
# coding=utf-8 # coding=utf-8
from django.utils import timezone from django.utils import timezone
import datetime, time import datetime, time
from datetime import timedelta
def timeit(method): def timeit(method):
def timed(*args, **kw): def timed(*args, **kw):
...@@ -21,3 +22,24 @@ def get_today_midnight_date(): ...@@ -21,3 +22,24 @@ def get_today_midnight_date():
today_midnight = datetime.datetime(today.year, today.month, today.day, tzinfo=today.tzinfo) today_midnight = datetime.datetime(today.year, today.month, today.day, tzinfo=today.tzinfo)
return today_midnight 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment