diff options
-rw-r--r-- | management/commands/timetables.py | 10 | ||||
-rw-r--r-- | tests.py | 3 | ||||
-rw-r--r-- | utils.py | 10 |
3 files changed, 14 insertions, 9 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py index a152f9e..35fb26e 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -21,7 +21,7 @@ from django.db.models import Min from django.utils import timezone from edt.models import Course, Timetable -from edt.utils import get_week +from edt.utils import get_week, tz_now from ._private import delete_courses_in_week, get_events, get_update_date, get_weeks, get_xml @transaction.atomic @@ -32,7 +32,7 @@ def process_timetable_week(timetable, soup, weeks_in_soup, force, year=None, wee if force: today = begin else: - today = timezone.make_aware(datetime.datetime.now()) + today = tz_now() # On récupère la mise à jour la plus ancienne dans les cours de l’emploi du temps # commençant à partir de maintenant @@ -107,16 +107,16 @@ class Command(BaseCommand): if options["all"]: weeks = None elif options["week"] is None: - _, week, day = timezone.now().isocalendar() + _, 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() weeks = [week] else: weeks = options["week"] if not options["all"]: if options["year"] is None and year is None: - year = timezone.now().year + year = tz_now().year elif year is None: year = options["year"][0] @@ -17,11 +17,12 @@ from django.test import TestCase from django.utils import timezone from .models import Course, Group, Timetable, Year +from .utils import tz_now class CourseTestCase(TestCase): def setUp(self): - dt = timezone.now() + dt = tz_now() self.year = Year(name="L2", slug="l2") self.year.save() @@ -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()) |