summaryrefslogtreecommitdiff
path: root/django/utils/dateformat.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/dateformat.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/dateformat.py')
-rw-r--r--django/utils/dateformat.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index 4833b5af2c..0d4eb4bdf0 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -12,7 +12,6 @@ Usage:
"""
import calendar
import datetime
-import time
from email.utils import format_datetime as format_datetime_rfc5322
from django.utils.dates import (
@@ -20,7 +19,7 @@ from django.utils.dates import (
)
from django.utils.regex_helper import _lazy_re_compile
from django.utils.timezone import (
- _datetime_ambiguous_or_imaginary, get_default_timezone, is_aware, is_naive,
+ _datetime_ambiguous_or_imaginary, get_default_timezone, is_naive,
make_aware,
)
from django.utils.translation import gettext as _
@@ -295,10 +294,10 @@ class DateFormat(TimeFormat):
def U(self):
"Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)"
- if isinstance(self.data, datetime.datetime) and is_aware(self.data):
- return int(calendar.timegm(self.data.utctimetuple()))
- else:
- return int(time.mktime(self.data.timetuple()))
+ value = self.data
+ if not isinstance(value, datetime.datetime):
+ value = datetime.datetime.combine(value, datetime.time.min)
+ return int(value.timestamp())
def w(self):
"Day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday)"