1.1 --- a/EventAggregatorSupport.py Mon Mar 22 00:27:34 2010 +0100
1.2 +++ b/EventAggregatorSupport.py Mon Mar 22 00:55:35 2010 +0100
1.3 @@ -21,6 +21,11 @@
1.4 except NameError:
1.5 from sets import Set as set
1.6
1.7 +try:
1.8 + import pytz
1.9 +except ImportError:
1.10 + pytz = None
1.11 +
1.12 __version__ = "0.6"
1.13
1.14 # Date labels.
1.15 @@ -55,6 +60,7 @@
1.16 date_regexp = re.compile(date_regexp_str, re.UNICODE)
1.17 time_regexp = re.compile(time_regexp_str, re.UNICODE)
1.18 datetime_regexp = re.compile(datetime_regexp_str, re.UNICODE)
1.19 +timezone_olson_regexp = re.compile(timezone_olson_str, re.UNICODE)
1.20 timezone_offset_regexp = re.compile(timezone_offset_str, re.UNICODE)
1.21
1.22 verbatim_regexp = re.compile(ur'(?:'
1.23 @@ -1045,6 +1051,9 @@
1.24 hour -= 24
1.25
1.26 return date.as_datetime(hour, minute, second, "UTC")
1.27 +
1.28 + # Cannot convert.
1.29 +
1.30 else:
1.31 return None
1.32
1.33 @@ -1076,6 +1085,37 @@
1.34
1.35 return None
1.36
1.37 + def olson_identifier(self):
1.38 +
1.39 + "Return the Olson identifier from any zone information."
1.40 +
1.41 + zone = self.time_zone()
1.42 + if not zone:
1.43 + return None
1.44 +
1.45 + # Attempt to match an identifier.
1.46 +
1.47 + match = timezone_olson_regexp.match(zone)
1.48 + if match:
1.49 + return match.group("olson")
1.50 + else:
1.51 + return None
1.52 +
1.53 + def ambiguous(self):
1.54 +
1.55 + "Return whether the time is local and ambiguous."
1.56 +
1.57 + olson = self.olson_identifier()
1.58 + if olson and pytz:
1.59 + try:
1.60 + tz = pytz.timezone(olson)
1.61 + data = self.padded().as_tuple()[:6]
1.62 + dt = tz.localize(datetime.datetime(*data), None)
1.63 + except (pytz.UnknownTimeZoneError, pytz.AmbiguousTimeError):
1.64 + return 1
1.65 +
1.66 + return 0
1.67 +
1.68 def getCountry(s):
1.69
1.70 "Find a country code in the given string 's'."