Skip to content

Commit

Permalink
Merge pull request #34 from dimagi/sk/event-date
Browse files Browse the repository at this point in the history
use django timezone util to avoid runtime warnings
  • Loading branch information
snopoke authored Jan 24, 2024
2 parents 9cb70d2 + 195e9be commit 6c37936
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions field_audit/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from datetime import datetime
from enum import Enum
from functools import wraps
from itertools import islice

from django.conf import settings
from django.db import models, transaction
from django.db.models import Expression
from django.utils import timezone

from .const import BOOTSTRAP_BATCH_SIZE
from .utils import class_import_helper
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_date():
This is the "getter" for default values of the ``AuditEvent.event_date``
field.
"""
return datetime.utcnow()
return timezone.now()


class AuditEvent(models.Model):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from contextlib import ContextDecorator
from datetime import datetime, timedelta
from datetime import timedelta
from enum import Enum
from unittest.mock import ANY, Mock, patch

Expand All @@ -10,6 +10,7 @@
from django.db.models import Case, When, Value
from django.db.utils import IntegrityError, DatabaseError
from django.test import TestCase, override_settings
from django.utils import timezone

from field_audit.auditors import audit_dispatcher
from field_audit.const import BOOTSTRAP_BATCH_SIZE
Expand Down Expand Up @@ -295,7 +296,7 @@ def test_get_manager_uses_default_if_no_setting(self):
def test_get_date(self):
then = get_date()
self.assertLess(
datetime.utcnow() - then,
timezone.now() - then,
timedelta(seconds=1),
)

Expand Down

0 comments on commit 6c37936

Please sign in to comment.