1.1 --- a/EventAggregatorSupport.py Sun Mar 14 23:21:52 2010 +0100
1.2 +++ b/EventAggregatorSupport.py Tue Mar 16 00:58:18 2010 +0100
1.3 @@ -45,7 +45,7 @@
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_offset_str = ur'(?:UTC)?(?P<sign>[-+])(?P<hours>[0-9]{2})(?::?(?P<minutes>[0-9]{2}))?'
1.8 +timezone_offset_str = ur'(UTC)?(?:(?P<sign>[-+])(?P<hours>[0-9]{2})(?::?(?P<minutes>[0-9]{2}))?)?'
1.9 timezone_regexp_str = ur'(?P<zone>' + timezone_offset_str + ')'
1.10 datetime_regexp_str = date_regexp_str + ur'(?:\s+' + time_regexp_str + ur'(?:\s+' + timezone_regexp_str + ur')?)?'
1.11
1.12 @@ -890,6 +890,15 @@
1.13
1.14 "A simple year-month-day representation."
1.15
1.16 + def constrain(self):
1.17 + year, month, day = self.as_tuple()[:3]
1.18 +
1.19 + month = max(min(month, 12), 1)
1.20 + wd, last_day = calendar.monthrange(year, month)
1.21 + day = max(min(day, last_day), 1)
1.22 +
1.23 + self.data[1:3] = month, day
1.24 +
1.25 def __str__(self):
1.26 return "%04d-%02d-%02d" % self.as_tuple()[:3]
1.27
1.28 @@ -943,8 +952,19 @@
1.29
1.30 "A simple date plus time representation."
1.31
1.32 - def __init__(self, data):
1.33 - Date.__init__(self, data)
1.34 + def constrain(self):
1.35 + Date.constrain(self)
1.36 +
1.37 + hour, minute, second = self.as_tuple()[3:6]
1.38 +
1.39 + if self.has_time():
1.40 + hour = max(min(hour, 23), 0)
1.41 + minute = max(min(minute, 59), 0)
1.42 +
1.43 + if second is not None:
1.44 + second = max(min(second, 60), 0) # support leap seconds
1.45 +
1.46 + self.data[3:6] = hour, minute, second
1.47
1.48 def __str__(self):
1.49 if self.has_time():
1.50 @@ -1034,6 +1054,11 @@
1.51 if not zone:
1.52 return None
1.53
1.54 + # Support explicit UTC zones.
1.55 +
1.56 + if zone == "UTC":
1.57 + return 0, 0
1.58 +
1.59 # Attempt to return a UTC offset where an explicit offset has been set.
1.60
1.61 match = timezone_offset_regexp.match(zone)