From cb699e9c941121d9b9e063997b61a86b3c672f90 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Fri, 8 Sep 2017 11:27:14 +0200
Subject: [PATCH] appointments api is timezone aware

---
 smash/web/api_views/appointment.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/smash/web/api_views/appointment.py b/smash/web/api_views/appointment.py
index 8945d166..db8122ed 100644
--- a/smash/web/api_views/appointment.py
+++ b/smash/web/api_views/appointment.py
@@ -1,8 +1,10 @@
 import traceback
+from datetime import datetime
 
 from django.contrib.auth.decorators import login_required
 from django.http import JsonResponse
 from django.urls import reverse
+from django.utils import timezone
 
 from web.models import Appointment
 from web.views import e500_error
@@ -29,9 +31,11 @@ def get_appointments(request, type, min_date, max_date):
         raise TypeError("Unknown query type: " + type)
 
     if min_date is not None:
+        min_date = datetime.strptime(min_date, "%Y-%m-%d").replace(tzinfo=timezone.now().tzinfo)
         result = result.filter(datetime_when__gt=min_date)
 
     if max_date is not None:
+        max_date = datetime.strptime(max_date, "%Y-%m-%d").replace(tzinfo=timezone.now().tzinfo)
         result = result.filter(datetime_when__lt=max_date)
     return result.order_by("datetime_when")
 
@@ -57,12 +61,12 @@ def appointments(request, type):
 
         sliced_subjects = all_appointments[start:(start + length)]
 
-        appointments = sliced_subjects
+        result_appointments = sliced_subjects
 
         count_filtered = all_appointments.count()
 
         data = []
-        for appointment in appointments:
+        for appointment in result_appointments:
             data.append(serialize_appointment(appointment))
 
         return JsonResponse({
-- 
GitLab