1.1 --- a/EventAggregatorSupport.py Sun Mar 14 21:06:15 2010 +0100
1.2 +++ b/EventAggregatorSupport.py Sun Mar 14 22:53:48 2010 +0100
1.3 @@ -50,13 +50,17 @@
1.4 month_regexp_str = ur'(?P<year>[0-9]{4})-(?P<month>[0-9]{2})'
1.5 date_regexp_str = ur'(?P<year>[0-9]{4})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})'
1.6 time_regexp_str = ur'(?P<hour>[0-2][0-9]):(?P<minute>[0-5][0-9])(?::(?P<second>[0-6][0-9]))?'
1.7 -timezone_regexp_str = ur'(?P<zone>[A-Z]{3,}|[a-zA-Z]+/[-_a-zA-Z]+|[-+][0-9]{1,4})'
1.8 +timezone_olson_str = ur'(?P<olson>[a-zA-Z]+/[-_a-zA-Z]+)'
1.9 +timezone_offset_str = ur'(?:UTC)?(?P<sign>[-+])(?P<hours>[0-9]{2})(?::?(?P<minutes>[0-9]{2}))?'
1.10 +timezone_regexp_str = ur'(?P<zone>' + timezone_olson_str + '|' + timezone_offset_str + ')'
1.11 datetime_regexp_str = date_regexp_str + ur'(?:\s+' + time_regexp_str + ur'(?:\s+' + timezone_regexp_str + ur')?)?'
1.12
1.13 month_regexp = re.compile(month_regexp_str, re.UNICODE)
1.14 date_regexp = re.compile(date_regexp_str, re.UNICODE)
1.15 time_regexp = re.compile(time_regexp_str, re.UNICODE)
1.16 datetime_regexp = re.compile(datetime_regexp_str, re.UNICODE)
1.17 +timezone_olson_regexp = re.compile(timezone_olson_str, re.UNICODE)
1.18 +timezone_offset_regexp = re.compile(timezone_offset_str, re.UNICODE)
1.19
1.20 verbatim_regexp = re.compile(ur'(?:'
1.21 ur'<<Verbatim\((?P<verbatim>.*?)\)>>'
1.22 @@ -1053,25 +1057,31 @@
1.23
1.24 zone = self.time_zone()
1.25
1.26 - # Only attempt to return a UTC offset where an explicit offset has been
1.27 - # set.
1.28 + # Attempt to return a UTC offset where an explicit offset has been set.
1.29
1.30 - if zone and zone[0] in "-+":
1.31 - digits = zone[1:]
1.32 - if zone[0] == "-":
1.33 + match = timezone_offset_regexp.match(zone)
1.34 + if match:
1.35 + if match.group("sign") == "-":
1.36 sign = -1
1.37 else:
1.38 sign = 1
1.39
1.40 - if 1 <= len(digits) <= 2:
1.41 - return int(digits) * sign, 0
1.42 - elif len(digits) == 3:
1.43 - hours = int(digits[:1]) * sign
1.44 - minutes = int(digits[1:]) * sign
1.45 - return hours, minutes
1.46 - elif len(digits) == 4:
1.47 - hours = int(digits[:2]) * sign
1.48 - minutes = int(digits[2:]) * sign
1.49 + hours = int(match.group("hours")) * sign
1.50 + minutes = int(match.group("minutes") or 0) * sign
1.51 + return hours, minutes
1.52 +
1.53 + # Attempt to return an offset where an Olson identifier has been given.
1.54 +
1.55 + match = timezone_olson_regexp.match(zone)
1.56 + if match:
1.57 + if pytz is not None:
1.58 + tz = pytz.timezone(match.group("olson"))
1.59 +
1.60 + # NOTE: Using internal attribute.
1.61 +
1.62 + seconds = tz._utcoffset.seconds
1.63 + hours = seconds / 3600
1.64 + minutes = (seconds - hours * 3600) / 60
1.65 return hours, minutes
1.66
1.67 return None
1.68 @@ -1147,9 +1157,9 @@
1.69 if m:
1.70 groups = list(m.groups())
1.71
1.72 - # Convert all but the zone to integer or None.
1.73 + # Convert date and time data to integer or None.
1.74
1.75 - return DateTime(map(int_or_none, groups[:-1]) + groups[-1:])
1.76 + return DateTime(map(int_or_none, groups[:6]) + [m.group("zone")])
1.77 else:
1.78 return None
1.79