Fix timezone bug for ATOM generation

This commit is contained in:
Rémy HUBSCHER 2011-08-16 15:11:49 +02:00
commit 32a6ecbcc5
4 changed files with 16 additions and 9 deletions

View file

@ -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