Fixed #26, Fixed Localized Time Formatting Issues
Signed-off-by: Lars Kiesow <lkiesow@uos.de>
This commit is contained in:
parent
303c047697
commit
9819fd98b3
3 changed files with 17 additions and 9 deletions
|
@ -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 []:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
:copyright: 2013, Lars Kiesow <lkiesow@uos.de>
|
||||
: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
|
||||
|
|
Loading…
Reference in a new issue