# HG changeset patch # User Paul Boddie # Date 1368748053 -7200 # Node ID d3df73c1c28d6d85e754dad10f1dcfb182ecf991 # Parent 53a942fac7e8f63e9f5f6965f7620c6c519d8bbc Added RFC 2822 datetime parsing with help from the email.utils module. diff -r 53a942fac7e8 -r d3df73c1c28d DateSupport.py --- a/DateSupport.py Tue May 14 23:12:48 2013 +0200 +++ b/DateSupport.py Fri May 17 01:47:33 2013 +0200 @@ -6,6 +6,7 @@ @license: GNU GPL (v2 or later), see COPYING.txt for details. """ +from email.utils import parsedate_tz import calendar import datetime import re @@ -593,9 +594,7 @@ dt = self.as_olson_datetime() if dt: seconds = dt.utcoffset().seconds + dt.utcoffset().days * 24 * 3600 - hours = abs(seconds) / 3600 - minutes = (abs(seconds) % 3600) / 60 - return sign(seconds) * hours, sign(seconds) * minutes + return getHoursAndMinutes(seconds) # Otherwise return None. @@ -910,6 +909,24 @@ else: return None +def getDateTimeFromRFC2822(s): + + """ + Parse the RFC 2822 format datetime string 's', returning a datetime object. + """ + + data = parsedate_tz(s) + offset = data[9] + return DateTime(data[:6] + ("%02d:%02d" % getHoursAndMinutes(offset),)) + +def getHoursAndMinutes(seconds): + + "Return an (hours, minutes) tuple for the given number of 'seconds'." + + hours = abs(seconds) / 3600 + minutes = (abs(seconds) % 3600) / 60 + return sign(seconds) * hours, sign(seconds) * minutes + def getDateStrings(s): "Parse the string 's', extracting and returning all date strings." diff -r 53a942fac7e8 -r d3df73c1c28d README.txt --- a/README.txt Tue May 14 23:12:48 2013 +0200 +++ b/README.txt Fri May 17 01:47:33 2013 +0200 @@ -72,6 +72,7 @@ * Fixed the ISO 8601 representations of datetimes and added ISO 8601 datetime parsing support. * Fixed the time zone information associated with page revisions. + * Added RFC 2822 datetime parsing with help from the email.utils module. New in MoinSupport 0.3 (Changes since MoinSupport 0.2) ------------------------------------------------------