diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-05-07 10:42:59 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2021-05-12 11:08:41 +0200 |
| commit | d06c5b358149c02a62da8a5469264d05f29ac659 (patch) | |
| tree | 2ca0d6884062980dea5e8085af0868f9d9b5a266 /django/utils/http.py | |
| parent | 69ffb1acf38bd34f76707468bb592eb4b164e2da (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/http.py')
| -rw-r--r-- | django/utils/http.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index 5397bb8190..6aa45a2cd6 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -1,5 +1,4 @@ import base64 -import calendar import datetime import re import unicodedata @@ -112,9 +111,10 @@ def parse_http_date(date): else: raise ValueError("%r is not in a valid HTTP date format" % date) try: + tz = datetime.timezone.utc year = int(m['year']) if year < 100: - current_year = datetime.datetime.utcnow().year + current_year = datetime.datetime.now(tz=tz).year current_century = current_year - (current_year % 100) if year - (current_year % 100) > 50: # year that appears to be more than 50 years in the future are @@ -127,8 +127,8 @@ def parse_http_date(date): hour = int(m['hour']) min = int(m['min']) sec = int(m['sec']) - result = datetime.datetime(year, month, day, hour, min, sec) - return calendar.timegm(result.utctimetuple()) + result = datetime.datetime(year, month, day, hour, min, sec, tzinfo=tz) + return int(result.timestamp()) except Exception as exc: raise ValueError("%r is not a valid date" % date) from exc |
