Private
Public Access
1
0

removing date.today and replacing with timezone.now

This commit is contained in:
Sander Roosendaal
2021-08-09 20:30:38 +02:00
parent ef34af1770
commit 0438d3b396
5 changed files with 61 additions and 30 deletions

View File

@@ -26,6 +26,7 @@ queuehigh = django_rq.get_queue('low')
import json
import pandas as pd
import arrow
from rowingdata import rowingdata as rrdata
from rowingdata import rower as rrower
@@ -350,7 +351,7 @@ def get_indoorraces(workout):
return races
def get_todays_micro(plan,thedate=date.today()):
def get_todays_micro(plan,thedate=timezone.now()):
thismicro = None
thismacro = TrainingMacroCycle.objects.filter(
@@ -381,7 +382,7 @@ def get_todays_micro(plan,thedate=date.today()):
thismicro = thismicro[0]
else:
mms = TrainingMicroCycle.objects.all()
return None
return thismicro
@@ -619,7 +620,7 @@ cratiocolors = {
def is_session_complete_ws(ws,ps):
ws = ws.order_by("date")
if ws.count()==0:
today = date.today()
today = timezone.now()
if today > ps.enddate:
verdict = 'missed'
ratio = 0
@@ -851,7 +852,7 @@ def get_team(request):
return teamid
def get_dates_timeperiod(request,startdatestring='',enddatestring='',
defaulttimeperiod='thisweek'):
defaulttimeperiod='thisweek',rower=None):
# set start end date according timeperiod
# should always return datetime.date
@@ -883,40 +884,47 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
startdate = enddate
enddate = e
if rower is not None:
tz = pytz.timezone(rower.defaulttimezone)
startdate = arrow.get(startdate)
enddate = arrow.get(enddate)
startdate = startdate.astimezone(tz)
enddate = enddate.astimezone(tz)
return startdate,enddate
daterangetester = re.compile('^(\d+-\d+-\d+)\/(\d+-\d+-\d+)')
if timeperiod=='today': # pragma: no cover
startdate=date.today()
enddate=date.today()
startdate=timezone.now()
enddate=timezone.now()
elif timeperiod=='last30':
startdate = date.today()-timezone.timedelta(days=30)
enddate = date.today()+timezone.timedelta(days=1)
startdate = timezone.now()-timezone.timedelta(days=30)
enddate = timezone.now()+timezone.timedelta(days=1)
elif timeperiod=='tomorrow': # pragma: no cover
startdate=date.today()+timezone.timedelta(days=1)
enddate=date.today()+timezone.timedelta(days=1)
startdate=timezone.now()+timezone.timedelta(days=1)
enddate=timezone.now()+timezone.timedelta(days=1)
elif timeperiod=='thisweek': # pragma: no cover
today = date.today()
startdate = date.today()-timezone.timedelta(days=today.weekday())
today = timezone.now()
startdate = timezone.now()-timezone.timedelta(days=today.weekday())
enddate = startdate+timezone.timedelta(days=6)
elif timeperiod=='thismonth': # pragma: no cover
today = date.today()
today = timezone.now()
startdate = today.replace(day=1)
enddate = startdate+timezone.timedelta(days=32)
enddate = enddate.replace(day=1)
enddate = enddate-timezone.timedelta(days=1)
elif timeperiod=='lastweek': # pragma: no cover
today = date.today()
today = timezone.now()
enddate = today-timezone.timedelta(days=today.weekday())-timezone.timedelta(days=1)
startdate = enddate-timezone.timedelta(days=6)
elif timeperiod=='nextweek': # pragma: no cover
today = date.today()
today = timezone.now()
startdate = today-timezone.timedelta(days=today.weekday())+timezone.timedelta(days=7)
enddate = startdate+timezone.timedelta(days=6)
elif timeperiod=='lastmonth': # pragma: no cover
today = date.today()
today = timezone.now()
startdate = today.replace(day=1)
startdate = startdate-timezone.timedelta(days=3)
startdate = startdate.replace(day=1)
@@ -924,7 +932,7 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
enddate = enddate.replace(day=1)
enddate = enddate-timezone.timedelta(days=1)
elif timeperiod=='nextmonth': # pragma: no cover
today = date.today()
today = timezone.now()
startdate = today.replace(day=1)
startdate = startdate+timezone.timedelta(days=32)
startdate = startdate.replace(day=1)
@@ -932,7 +940,7 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
enddate = enddate.replace(day=1)
enddate = enddate-timezone.timedelta(days=1)
elif timeperiod=='lastyear': # pragma: no cover
today = date.today()
today = timezone.now()
startdate = today-timezone.timedelta(days=365)
enddate = today+timezone.timedelta(days=1)
elif daterangetester.match(timeperiod):
@@ -946,11 +954,11 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
enddate = startdate
startdate = startdate2
except ValueError: # pragma: no cover
startdate = date.today()
enddate = date.today()
startdate = timezone.now()
enddate = timezone.now()
else:
startdate = date.today()
enddate = date.today()
startdate = timezone.now()
enddate = timezone.now()
if startdatestring != '':
@@ -965,10 +973,18 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
except ParseError:
pass
if rower is not None:
startdate = arrow.get(startdate)
enddate = arrow.get(enddate)
tz = pytz.timezone(rower.defaulttimezone)
startdate = startdate.astimezone(tz)
enddate = enddate.astimezone(tz)
return startdate,enddate
def get_sessions_manager(m,teamid=0,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
def get_sessions_manager(m,teamid=0,startdate=timezone.now(),
enddate=timezone.now()+timezone.timedelta(+1000)):
if teamid: # pragma: no cover
t = Team.objects.get(id=teamid)
rs = Rower.objects.filter(team__in=[t]).distinct()
@@ -991,8 +1007,8 @@ def get_sessions_manager(m,teamid=0,startdate=date.today(),
return sps
def get_sessions(r,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
def get_sessions(r,startdate=timezone.now(),
enddate=timezone.now()+timezone.timedelta(+1000)):
sps = PlannedSession.objects.filter(
rower__in=[r],