Skip to content

Commit

Permalink
Use timezone aware datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Nov 23, 2023
1 parent 2812a51 commit 4697323
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions umap/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
import socket
from datetime import date, timedelta
from datetime import date, datetime, timedelta

import pytest
from django.conf import settings
from django.contrib.auth import get_user, get_user_model
from django.test import RequestFactory
from django.urls import reverse
from django.utils.timezone import make_aware

from umap import VERSION
from umap.views import validate_url
Expand Down Expand Up @@ -186,9 +187,9 @@ def test_stats_empty(client):

@pytest.mark.django_db
def test_stats_basic(client, map, datalayer, user2):
map.owner.last_login = date.today()
map.owner.last_login = make_aware(datetime.now())
map.owner.save()
user2.last_login = date.today() - timedelta(days=8)
user2.last_login = make_aware(datetime.now()) - timedelta(days=8)
user2.save()
response = client.get(reverse("stats"))
assert json.loads(response.content.decode()) == {
Expand Down
5 changes: 3 additions & 2 deletions umap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re
import socket
from datetime import date, timedelta
from datetime import datetime, timedelta
from http.client import InvalidURL
from pathlib import Path
from urllib.error import URLError
Expand Down Expand Up @@ -33,6 +33,7 @@
from django.urls import reverse, reverse_lazy
from django.utils.encoding import smart_bytes
from django.utils.http import http_date
from django.utils.timezone import make_aware
from django.utils.translation import gettext as _
from django.utils.translation import to_locale
from django.views.decorators.cache import cache_control
Expand Down Expand Up @@ -1027,7 +1028,7 @@ def render_to_response(self, context, **response_kwargs):


def stats(request):
last_week = date.today() - timedelta(days=7)
last_week = make_aware(datetime.now()) - timedelta(days=7)
return simple_json_response(
**{
"version": VERSION,
Expand Down

0 comments on commit 4697323

Please sign in to comment.