aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorAlban Gruin2017-10-14 11:25:46 +0200
committerAlban Gruin2017-10-14 11:25:46 +0200
commit640496deb262349101567de12d2476cbfe5065b3 (patch)
treef3a0f6a102abbb0e41995e1d750c8fcc774efb55 /utils.py
parente2fb71d3377dee14cf1934ac3d6ad448bb7063bc (diff)
timezone.now() retourne l’heure UTC, ce qui empêche la mise à jour de
la semaine prochaine le samedi à minuit. Remplacement de ces appels par une fonction qui retourne la bonne heure dans le bon fuseau horaire.
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/utils.py b/utils.py
index bd337e4..28a1ba2 100644
--- a/utils.py
+++ b/utils.py
@@ -19,12 +19,12 @@ import re
from django.utils import timezone
def get_current_week():
- return timezone.now().isocalendar()[:2]
+ return tz_now().isocalendar()[:2]
def get_current_or_next_week():
- year, week, day = timezone.now().isocalendar()
+ year, week, day = tz_now().isocalendar()
if day >= 6:
- year, week, _ = (timezone.now() + datetime.timedelta(weeks=1)).isocalendar()
+ year, week, _ = (tz_now() + datetime.timedelta(weeks=1)).isocalendar()
return year, week
@@ -74,3 +74,7 @@ def parse_group(name):
return parts[0], parts[5], parts[6], None
elif parts[7] is not None: # Groupe de TP
return parts[0], parts[8], parts[9], parts[10]
+
+def tz_now():
+ """Retourne la date et l’heure avec le bon fuseau horaire"""
+ return timezone.make_aware(datetime.datetime.now())