Skip to content

Commit

Permalink
fix timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Sep 19, 2019
1 parent 22e1b43 commit 173b26f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions admin_tools_stats/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
from django.contrib import messages
from django.core.exceptions import FieldError
from django.utils.safestring import mark_safe
from django.utils import timezone
from qsstats import QuerySetStats
from cache_utils.decorators import cached
from admin_tools.dashboard import modules
from admin_tools_stats.models import DashboardStats
from datetime import datetime, timedelta

from datetime import timedelta
import time

from django.utils.timezone import now


class DashboardChart(modules.DashboardModule):
"""Dashboard module with user registration charts.
Expand Down Expand Up @@ -124,7 +122,7 @@ def get_registrations(self, interval, days, graph_key, select_box_value):
stats = QuerySetStats(model_name.objects.filter(**kwargs).distinct(),
conf_data.date_field_name, aggregate)
# stats = QuerySetStats(User.objects.filter(is_active=True), 'date_joined')
today = now()
today = timezone.now()
if days == 24:
begin = today - timedelta(hours=days - 1)
return stats.time_series(begin, today + timedelta(hours=1), interval)
Expand All @@ -136,7 +134,7 @@ def get_registrations(self, interval, days, graph_key, select_box_value):
User = get_user_model()
stats = QuerySetStats(
User.objects.filter(is_active=True), 'date_joined')
today = now()
today = timezone.now()
if days == 24:
begin = today - timedelta(hours=days - 1)
return stats.time_series(begin, today + timedelta(hours=1), interval)
Expand All @@ -161,8 +159,9 @@ def prepare_template_data(self, data, graph_key, select_box_value, other_select_

xdata = []
ydata = []
current_tz = timezone.get_current_timezone()
for data_date in self.data:
start_time = int(time.mktime(data_date[0].timetuple()) * 1000)
start_time = int(time.mktime(data_date[0].astimezone(current_tz).timetuple()) * 1000)
xdata.append(start_time)
ydata.append(data_date[1])

Expand Down

0 comments on commit 173b26f

Please sign in to comment.