summaryrefslogtreecommitdiff
path: root/django/utils/timezone.py
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2021-05-07 10:42:59 +0100
committerCarlton Gibson <carlton.gibson@noumenal.es>2021-05-12 11:08:41 +0200
commitd06c5b358149c02a62da8a5469264d05f29ac659 (patch)
tree2ca0d6884062980dea5e8085af0868f9d9b5a266 /django/utils/timezone.py
parent69ffb1acf38bd34f76707468bb592eb4b164e2da (diff)
Fixed #32366 -- Updated datetime module usage to recommended approach.
- Replaced datetime.utcnow() with datetime.now(). - Replaced datetime.utcfromtimestamp() with datetime.fromtimestamp(). - Replaced datetime.utctimetuple() with datetime.timetuple(). - Replaced calendar.timegm() and datetime.utctimetuple() with datetime.timestamp().
Diffstat (limited to 'django/utils/timezone.py')
-rw-r--r--django/utils/timezone.py6
1 files changed, 1 insertions, 5 deletions
diff --git a/django/utils/timezone.py b/django/utils/timezone.py
index cf22ec34d0..bb2b6b9594 100644
--- a/django/utils/timezone.py
+++ b/django/utils/timezone.py
@@ -194,11 +194,7 @@ def now():
"""
Return an aware or naive datetime.datetime, depending on settings.USE_TZ.
"""
- if settings.USE_TZ:
- # timeit shows that datetime.now(tz=utc) is 24% slower
- return datetime.utcnow().replace(tzinfo=utc)
- else:
- return datetime.now()
+ return datetime.now(tz=utc if settings.USE_TZ else None)
# By design, these four functions don't perform any checks on their arguments.