License Public Domain
Lines 3
Keywords
atom date (1) atom feed (2) RFC 3339 (2) sitemap (2)
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Easily highlight source code for your blog with our Syntax Highlighter. Join Siafoo Now or Learn More

Atom feed date function Atom Feed 0

In Brief A function for converting a timezone aware datetime object into an RFC 3339 compliant date format, as used by the atom feed and sitemap updated tag.... more
# 's
1def date_internet(date):
2 d = date.strftime('%Y-%m-%dT%H:%M:%S%z')
3 return d[:-2] + ':' + d[-2:]

A function for converting a timezone aware datetime object into an RFC 3339 compliant date format, as used by the atom feed and sitemap updated tag.

The ugliness of the code stems from the fact that the UTC offset format parameter %z returns a solid time, like -0700, but RFC 3339 requires the : between the hour and minutes, like -07:00.

If you know of a cleaner way to do this... please feel free to change it.