]> granicus.if.org Git - python/commitdiff
Feature added by Bill van Melle: when no timezone is present, assume
authorGuido van Rossum <guido@python.org>
Thu, 19 Feb 1998 00:28:58 +0000 (00:28 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 19 Feb 1998 00:28:58 +0000 (00:28 +0000)
local time -- that's better than failure.

Doc/lib/librfc822.tex
Doc/librfc822.tex
Lib/rfc822.py

index aa7e459792117a7cbf2ec237a1e8ee4d60257dce..d764ce65401aa7d2cb84d2b645debc7fda27959b 100644 (file)
@@ -47,11 +47,13 @@ offset of the date's timezone from UTC (which is the official term
 for Greenwich Mean Time).  (Note that the sign of the timezone offset
 is the opposite of the sign of the \code{time.timezone} variable for
 the same timezone; the latter variable follows the \POSIX{} standard
-while this module follows \rfc{822}.)
+while this module follows \rfc{822}.)  If the input string has no
+timezone, the last element of the tuple returned is \code{None}.
 \end{funcdesc}
 
 \begin{funcdesc}{mktime_tz}{tuple}
 Turn a 10-tuple as returned by \code{parsedate_tz()} into a UTC timestamp.
+It the timezone item in the tuple is \code{None}, assume local time.
 Minor deficiency: this first interprets the first 8 elements as a
 local time and then compensates for the timezone difference;
 this may yield a slight error around daylight savings time
index aa7e459792117a7cbf2ec237a1e8ee4d60257dce..d764ce65401aa7d2cb84d2b645debc7fda27959b 100644 (file)
@@ -47,11 +47,13 @@ offset of the date's timezone from UTC (which is the official term
 for Greenwich Mean Time).  (Note that the sign of the timezone offset
 is the opposite of the sign of the \code{time.timezone} variable for
 the same timezone; the latter variable follows the \POSIX{} standard
-while this module follows \rfc{822}.)
+while this module follows \rfc{822}.)  If the input string has no
+timezone, the last element of the tuple returned is \code{None}.
 \end{funcdesc}
 
 \begin{funcdesc}{mktime_tz}{tuple}
 Turn a 10-tuple as returned by \code{parsedate_tz()} into a UTC timestamp.
+It the timezone item in the tuple is \code{None}, assume local time.
 Minor deficiency: this first interprets the first 8 elements as a
 local time and then compensates for the timezone difference;
 this may yield a slight error around daylight savings time
index f58543a9f5c63e42bdf0d20e18e4f251ab7770ff..967a85efd2d3956693dcd578f1874eac52967dfd 100644 (file)
@@ -660,7 +660,7 @@ def parsedate_tz(data):
         tss = string.atoi(tss)
     except string.atoi_error:
         return None
-    tzoffset=0
+    tzoffset=None
     tz=string.upper(tz)
     if _timezones.has_key(tz):
         tzoffset=_timezones[tz]
@@ -670,10 +670,13 @@ def parsedate_tz(data):
         except string.atoi_error: 
             pass
     # Convert a timezone offset into seconds ; -0500 -> -18000
-    if tzoffset<0: tzsign=-1
-    else: tzsign=1
-    tzoffset=tzoffset*tzsign
-    tzoffset = tzsign * ( (tzoffset/100)*3600 + (tzoffset % 100)*60)
+    if tzoffset:
+       if tzoffset < 0:
+           tzsign = -1
+           tzoffset = -tzoffset
+       else:
+           tzsign = 1
+       tzoffset = tzsign * ( (tzoffset/100)*3600 + (tzoffset % 100)*60)
     tuple = (yy, mm, dd, thh, tmm, tss, 0, 0, 0, tzoffset)
     return tuple
 
@@ -695,8 +698,12 @@ def mktime_tz(data):
     switch dates.  Not enough to worry about for common use.
     
     """
-    t = time.mktime(data[:8] + (0,))
-    return t - data[9] - time.timezone
+    if data[9] is None:
+       # No zone info, so localtime is better assumption than GMT
+       return time.mktime(data[:8] + (-1,))
+    else:
+       t = time.mktime(data[:8] + (0,))
+       return t - data[9] - time.timezone
 
 
 # When used as script, run a small test program.