summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-05-02 14:11:11 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-05-02 21:11:25 +0200
commit76220fe73003292fb7b40113682b24da9376f052 (patch)
treea5fa279a0a128f8cadd94b53b102cdacc868e823
parent432678dbc1dd4f80203468d83bb0eb6c20ed5247 (diff)
Optimized two functions slightly.
This avoids calling date.tzinfo.utcoffset(date) twice. It's also robust to cases where that function returns None -- which never happens in practice :-)
-rw-r--r--django/utils/feedgenerator.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index d870b50435..9637d86a8a 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -29,7 +29,6 @@ from django.utils import datetime_safe, six
from django.utils.encoding import force_text, iri_to_uri
from django.utils.six import StringIO
from django.utils.six.moves.urllib.parse import urlparse
-from django.utils.timezone import is_aware
from django.utils.xmlutils import SimplerXMLGenerator
@@ -46,13 +45,14 @@ def rfc2822_date(date):
time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month))
if six.PY2: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
- if is_aware(date):
- offset = date.tzinfo.utcoffset(date)
+ offset = date.utcoffset()
+ # Historically, this function assumes that naive datetimes are in UTC.
+ if offset is None:
+ return time_str + '-0000'
+ else:
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d%02d' % (hour, minute)
- else:
- return time_str + '-0000'
def rfc3339_date(date):
@@ -61,13 +61,14 @@ def rfc3339_date(date):
time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
if six.PY2: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
- if is_aware(date):
- offset = date.tzinfo.utcoffset(date)
+ offset = date.utcoffset()
+ # Historically, this function assumes that naive datetimes are in UTC.
+ if offset is None:
+ return time_str + 'Z'
+ else:
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d:%02d' % (hour, minute)
- else:
- return time_str + 'Z'
def get_tag_uri(url, date):