# HG changeset patch # User Paul Boddie # Date 1268605312 -3600 # Node ID b4356d0f6d078be83d0b3287d8a07871337c97cb # Parent 59caeb446995a4cf2e7a3ff972db492957932252 Removed support for Olson identifiers and location-related time zones. Apart from issues with calculating UTC offsets and problems with indicating a widely understood time zone in iCalendar resources, Olson identifiers themselves are not sufficient to disambiguate times, at least in periods affected by local time changes. diff -r 59caeb446995 -r b4356d0f6d07 EventAggregatorSupport.py --- a/EventAggregatorSupport.py Sun Mar 14 22:53:48 2010 +0100 +++ b/EventAggregatorSupport.py Sun Mar 14 23:21:52 2010 +0100 @@ -21,11 +21,6 @@ except NameError: from sets import Set as set -try: - import pytz -except ImportError: - pytz = None - __version__ = "0.6" # Date labels. @@ -50,16 +45,14 @@ month_regexp_str = ur'(?P[0-9]{4})-(?P[0-9]{2})' date_regexp_str = ur'(?P[0-9]{4})-(?P[0-9]{2})-(?P[0-9]{2})' time_regexp_str = ur'(?P[0-2][0-9]):(?P[0-5][0-9])(?::(?P[0-6][0-9]))?' -timezone_olson_str = ur'(?P[a-zA-Z]+/[-_a-zA-Z]+)' timezone_offset_str = ur'(?:UTC)?(?P[-+])(?P[0-9]{2})(?::?(?P[0-9]{2}))?' -timezone_regexp_str = ur'(?P' + timezone_olson_str + '|' + timezone_offset_str + ')' +timezone_regexp_str = ur'(?P' + timezone_offset_str + ')' datetime_regexp_str = date_regexp_str + ur'(?:\s+' + time_regexp_str + ur'(?:\s+' + timezone_regexp_str + ur')?)?' month_regexp = re.compile(month_regexp_str, re.UNICODE) date_regexp = re.compile(date_regexp_str, re.UNICODE) time_regexp = re.compile(time_regexp_str, re.UNICODE) datetime_regexp = re.compile(datetime_regexp_str, re.UNICODE) -timezone_olson_regexp = re.compile(timezone_olson_str, re.UNICODE) timezone_offset_regexp = re.compile(timezone_offset_str, re.UNICODE) verbatim_regexp = re.compile(ur'(?:' @@ -336,10 +329,6 @@ if details.has_key(term): - # Perform additional event configuration. - - self.events[-1].fixTimeZone() - # Make a new event. details = {} @@ -347,10 +336,6 @@ details[term] = desc - # Perform additional event configuration. - - self.events[-1].fixTimeZone() - return self.events def setEvents(self, events): @@ -499,16 +484,6 @@ self.page = page self.details = details - def fixTimeZone(self): - - # Combine location and time zone information. - - location = self.details.get("location") - - if location: - self.details["start"].apply_location(location) - self.details["end"].apply_location(location) - def __cmp__(self, other): """ @@ -1056,6 +1031,8 @@ "Return the UTC offset in hours and minutes." zone = self.time_zone() + if not zone: + return None # Attempt to return a UTC offset where an explicit offset has been set. @@ -1070,74 +1047,8 @@ minutes = int(match.group("minutes") or 0) * sign return hours, minutes - # Attempt to return an offset where an Olson identifier has been given. - - match = timezone_olson_regexp.match(zone) - if match: - if pytz is not None: - tz = pytz.timezone(match.group("olson")) - - # NOTE: Using internal attribute. - - seconds = tz._utcoffset.seconds - hours = seconds / 3600 - minutes = (seconds - hours * 3600) / 60 - return hours, minutes - return None - def apply_location(self, location): - - """ - Apply 'location' information, setting the time zone if none has already - been set. - """ - - if not self.time_zone(): - zone = getTimeZone(location) - if zone: - self.set_time_zone(zone) - -def getTimeZone(location): - - "Find a time zone for the specified 'location'." - - # Only try and find a time zone if pytz is present and able to suggest one. - - if pytz is None: - return None - - code = getCountry(location) - - if code is None: - return None - - try: - zones = pytz.country_timezones(code) - except KeyError: - return None - - # No zones... - - if not zones: - return None - - # Many potential zones. - - if len(zones) > 1: - for zone in zones: - continent, city = zone.split("/") - - # If the specific city is mentioned, choose the - # zone. - - if location.find(city) != -1: - return zone - - # Otherwise choose the first or only zone. - - return zones[0] - def getCountry(s): "Find a country code in the given string 's'."