Skip to content

Commit 173b26f

Browse files
committed
fix timezone
1 parent 22e1b43 commit 173b26f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

admin_tools_stats/modules.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@
2020
from django.contrib import messages
2121
from django.core.exceptions import FieldError
2222
from django.utils.safestring import mark_safe
23+
from django.utils import timezone
2324
from qsstats import QuerySetStats
2425
from cache_utils.decorators import cached
2526
from admin_tools.dashboard import modules
2627
from admin_tools_stats.models import DashboardStats
27-
from datetime import datetime, timedelta
28-
28+
from datetime import timedelta
2929
import time
3030

31-
from django.utils.timezone import now
32-
3331

3432
class DashboardChart(modules.DashboardModule):
3533
"""Dashboard module with user registration charts.
@@ -124,7 +122,7 @@ def get_registrations(self, interval, days, graph_key, select_box_value):
124122
stats = QuerySetStats(model_name.objects.filter(**kwargs).distinct(),
125123
conf_data.date_field_name, aggregate)
126124
# stats = QuerySetStats(User.objects.filter(is_active=True), 'date_joined')
127-
today = now()
125+
today = timezone.now()
128126
if days == 24:
129127
begin = today - timedelta(hours=days - 1)
130128
return stats.time_series(begin, today + timedelta(hours=1), interval)
@@ -136,7 +134,7 @@ def get_registrations(self, interval, days, graph_key, select_box_value):
136134
User = get_user_model()
137135
stats = QuerySetStats(
138136
User.objects.filter(is_active=True), 'date_joined')
139-
today = now()
137+
today = timezone.now()
140138
if days == 24:
141139
begin = today - timedelta(hours=days - 1)
142140
return stats.time_series(begin, today + timedelta(hours=1), interval)
@@ -161,8 +159,9 @@ def prepare_template_data(self, data, graph_key, select_box_value, other_select_
161159

162160
xdata = []
163161
ydata = []
162+
current_tz = timezone.get_current_timezone()
164163
for data_date in self.data:
165-
start_time = int(time.mktime(data_date[0].timetuple()) * 1000)
164+
start_time = int(time.mktime(data_date[0].astimezone(current_tz).timetuple()) * 1000)
166165
xdata.append(start_time)
167166
ydata.append(data_date[1])
168167

0 commit comments

Comments
 (0)