Simplified django.utils.feedgenerator.rfc3339_date().

This commit is contained in:
Sergey Fedoseev 2018-01-05 20:36:33 +05:00 committed by Tim Graham
parent cd41f7d6b8
commit c794b56811
1 changed files with 3 additions and 11 deletions

View File

@ -53,17 +53,9 @@ def rfc2822_date(date):
def rfc3339_date(date): def rfc3339_date(date):
# Support datetime objects older than 1900 if not isinstance(date, datetime.datetime):
date = datetime_safe.new_datetime(date) date = datetime.datetime.combine(date, datetime.time())
time_str = date.strftime('%Y-%m-%dT%H:%M:%S') return date.isoformat() + ('Z' if date.utcoffset() is None else '')
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)
def get_tag_uri(url, date): def get_tag_uri(url, date):