diff --git a/feedgen/entry.py b/feedgen/entry.py index bf17d5f..bf50357 100644 --- a/feedgen/entry.py +++ b/feedgen/entry.py @@ -12,7 +12,7 @@ from lxml import etree from datetime import datetime import dateutil.parser import dateutil.tz -from feedgen.util import ensure_format +from feedgen.util import ensure_format, formatRFC2822 from feedgen.compat import string_types @@ -220,8 +220,7 @@ class FeedEntry(object): enclosure.attrib['type'] = self.__rss_enclosure['type'] if self.__rss_pubDate: pubDate = etree.SubElement(entry, 'pubDate') - pubDate.text = self.__rss_pubDate.strftime( - '%a, %d %b %Y %H:%M:%S %z') + pubDate.text = formatRFC2822(self.__rss_pubDate) if extensions: for ext in self.__extensions.values() or []: diff --git a/feedgen/feed.py b/feedgen/feed.py index ad38109..4c09dd3 100644 --- a/feedgen/feed.py +++ b/feedgen/feed.py @@ -14,7 +14,7 @@ from datetime import datetime import dateutil.parser import dateutil.tz from feedgen.entry import FeedEntry -from feedgen.util import ensure_format +from feedgen.util import ensure_format, formatRFC2822 import feedgen.version import sys from feedgen.compat import string_types @@ -313,15 +313,14 @@ class FeedGenerator(object): language.text = self.__rss_language if self.__rss_lastBuildDate: lastBuildDate = etree.SubElement(channel, 'lastBuildDate') - lastBuildDate.text = self.__rss_lastBuildDate.strftime( - '%a, %d %b %Y %H:%M:%S %z') + + lastBuildDate.text = formatRFC2822(self.__rss_lastBuildDate) if self.__rss_managingEditor: managingEditor = etree.SubElement(channel, 'managingEditor') managingEditor.text = self.__rss_managingEditor if self.__rss_pubDate: pubDate = etree.SubElement(channel, 'pubDate') - pubDate.text = self.__rss_pubDate.strftime( - '%a, %d %b %Y %H:%M:%S %z') + pubDate.text = formatRFC2822(self.__rss_pubDate) if self.__rss_rating: rating = etree.SubElement(channel, 'rating') rating.text = self.__rss_rating diff --git a/feedgen/util.py b/feedgen/util.py index 3f3d97e..c7c9454 100644 --- a/feedgen/util.py +++ b/feedgen/util.py @@ -8,7 +8,7 @@ :copyright: 2013, Lars Kiesow :license: FreeBSD and LGPL, see license.* for more details. ''' -import sys +import sys, locale def ensure_format(val, allowed, required, allowed_values=None, defaults=None): @@ -60,3 +60,13 @@ def ensure_format(val, allowed, required, allowed_values=None, defaults=None): if elem.get(k) and not elem[k] in v: raise ValueError('Invalid value for %s' % k ) return val + + +def formatRFC2822(d): + '''Make sure the locale setting do not interfere with the time format. + ''' + l = locale.setlocale(locale.LC_ALL) + locale.setlocale(locale.LC_ALL, 'C') + d = d.strftime('%a, %d %b %Y %H:%M:%S %z') + locale.setlocale(locale.LC_ALL, l) + return d