forked from github/pelican
Fix timezone bug for ATOM generation
This commit is contained in:
parent
66ca61dfbb
commit
32a6ecbcc5
4 changed files with 16 additions and 9 deletions
|
|
@ -4,6 +4,7 @@ import os
|
|||
import shutil
|
||||
import time
|
||||
import calendar
|
||||
import pytz
|
||||
from datetime import datetime
|
||||
from codecs import open as _open
|
||||
from itertools import groupby
|
||||
|
|
@ -225,9 +226,12 @@ def files_changed(path, extensions):
|
|||
return True
|
||||
return False
|
||||
|
||||
def local_to_utc(t):
|
||||
"Convert article time to UTC time for ATOM feeds"
|
||||
secs = time.mktime(t)
|
||||
gmtime = list(time.gmtime(secs))
|
||||
gmtime[8] = 1
|
||||
return datetime.fromtimestamp(time.mktime(gmtime))
|
||||
def set_date_tzinfo(d, tz_name=None):
|
||||
""" Date without tzinfo shoudbe utc.
|
||||
This function set the right tz to date that aren't utc and don't have tzinfo
|
||||
"""
|
||||
if tz_name is not None:
|
||||
tz = pytz.timezone(tz_name)
|
||||
return tz.localize(d)
|
||||
else:
|
||||
return d
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from functools import partial
|
|||
import locale
|
||||
|
||||
from feedgenerator import Atom1Feed, Rss201rev2Feed
|
||||
from pelican.utils import get_relative_path, local_to_utc
|
||||
from pelican.utils import get_relative_path, set_date_tzinfo
|
||||
from pelican.paginator import Paginator
|
||||
from pelican.log import *
|
||||
|
||||
|
|
@ -37,7 +37,8 @@ class Writer(object):
|
|||
description=item.content,
|
||||
categories=item.tags if hasattr(item, 'tags') else None,
|
||||
author_name=getattr(item, 'author', 'John Doe'),
|
||||
pubdate=local_to_utc(item.date.timetuple()))
|
||||
pubdate=set_date_tzinfo(item.date,
|
||||
self.settings.get('TIMEZONE', None)))
|
||||
|
||||
def write_feed(self, elements, context, filename=None, feed_type='atom'):
|
||||
"""Generate a feed with the list of articles provided
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -4,7 +4,7 @@ import sys
|
|||
|
||||
VERSION = "2.7.2" # find a better way to do so.
|
||||
|
||||
requires = ['feedgenerator', 'jinja2', 'pygments', 'docutils']
|
||||
requires = ['feedgenerator', 'jinja2', 'pygments', 'docutils', 'pytz']
|
||||
if sys.version_info < (2,7):
|
||||
requires.append('argparse')
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ AUTHOR = u"$author"
|
|||
SITENAME = u"$sitename"
|
||||
SITEURL = '/'
|
||||
|
||||
TIMEZONE = 'Europe/Paris'
|
||||
|
||||
DEFAULT_LANG='$lang'
|
||||
|
||||
# Blogroll
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue