Skip to content

Commit a463575

Browse files
committed
fix: make datetime aware in get_start_time and get_end_time methods
1 parent 24b36bf commit a463575

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

apps/application/serializers/application_stats.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.db import models
1414
from django.db.models import QuerySet
1515
from django.utils.translation import gettext_lazy as _
16+
from django.utils import timezone
1617
from rest_framework import serializers
1718

1819
from application.models import ApplicationChatUserStats, Application
@@ -48,12 +49,14 @@ def is_valid(self, *, raise_exception=False):
4849
raise AppApiException(500, _('Application id does not exist'))
4950

5051
def get_end_time(self):
51-
return datetime.datetime.combine(
52-
datetime.datetime.strptime(self.data.get('end_time'), '%Y-%m-%d'),
53-
datetime.datetime.max.time())
52+
d = datetime.datetime.strptime(self.data.get('end_time'), '%Y-%m-%d').date()
53+
naive = datetime.datetime.combine(d, datetime.time.max)
54+
return timezone.make_aware(naive, timezone.get_default_timezone())
5455

5556
def get_start_time(self):
56-
return self.data.get('start_time')
57+
d = datetime.datetime.strptime(self.data.get('start_time'), '%Y-%m-%d').date()
58+
naive = datetime.datetime.combine(d, datetime.time.min)
59+
return timezone.make_aware(naive, timezone.get_default_timezone())
5760

5861
def get_customer_count_trend(self, with_valid=True):
5962
if with_valid:

0 commit comments

Comments
 (0)