# HG changeset patch # User Paul Boddie # Date 1422983999 -3600 # Node ID 9d17bc8ffa199703dd1a9e35291f5ca5a895deef # Parent 70562154ed5bfd8ca57d47a1fa510243eb0c656f Introduced explicit time regime (TZID) usage so that the start of each day is positioned in the appropriate time zone. This affects end of day and adjacent day calculations. diff -r 70562154ed5b -r 9d17bc8ffa19 imip_manager.py --- a/imip_manager.py Tue Feb 03 17:43:44 2015 +0100 +++ b/imip_manager.py Tue Feb 03 18:19:59 2015 +0100 @@ -286,6 +286,10 @@ self.preferences = Preferences(self.user) return self.preferences + def get_tzid(self): + prefs = self.get_preferences() + return prefs.get("TZID", "UTC") + # Prettyprinting of dates and times. def format_date(self, dt, format): @@ -387,8 +391,7 @@ # Obtain the user's timezone. - prefs = self.get_preferences() - tzid = prefs.get("TZID", "UTC") + tzid = self.get_tzid() # Invent a unique identifier. @@ -558,8 +561,7 @@ # Obtain the user's timezone. - prefs = self.get_preferences() - tzid = prefs.get("TZID", "UTC") + tzid = self.get_tzid() # Provide a summary of the object. @@ -803,8 +805,7 @@ # Obtain the user's timezone. - prefs = self.get_preferences() - tzid = prefs.get("TZID", "UTC") + tzid = self.get_tzid() # Day view: start at the earliest known day and produce days until the # latest known day, perhaps with expandable sections of empty days. @@ -851,7 +852,7 @@ # Add start of day time points for multi-day periods. - add_day_start_points(slots) + add_day_start_points(slots, tzid) # Record the slots and all time points employed. @@ -1026,13 +1027,17 @@ page = self.page + # Obtain the user's timezone. + + tzid = self.get_tzid() + # Produce a row for each interval. intervals = list(intervals) intervals.sort() for point, endpoint in intervals: - continuation = point == get_start_of_day(point) + continuation = point == get_start_of_day(point, tzid) # Some rows contain no period details and are marked as such. @@ -1081,7 +1086,7 @@ if point == start or continuation: has_continued = continuation and point != start - will_continue = not ends_on_same_day(point, end) + will_continue = not ends_on_same_day(point, end, tzid) css = " ".join( ["event"] + (has_continued and ["continued"] or []) + @@ -1152,12 +1157,13 @@ """ page = self.page + tzid = self.get_tzid() daystr = format_datetime(point.date()) value, identifier = self._slot_value_and_identifier(point, endpoint) slots = self.env.get_args().get("slot", []) self._slot_selector(value, identifier, slots) page.label(self.format_time(point, "long"), class_="timepoint day-%s" % daystr, for_=identifier) - page.span(self.format_time(endpoint or get_end_of_day(point), "long"), class_="endpoint") + page.span(self.format_time(endpoint or get_end_of_day(point, tzid), "long"), class_="endpoint") def _slot_selector(self, value, identifier, slots): page = self.page diff -r 70562154ed5b -r 9d17bc8ffa19 imiptools/dates.py --- a/imiptools/dates.py Tue Feb 03 17:43:44 2015 +0100 +++ b/imiptools/dates.py Tue Feb 03 18:19:59 2015 +0100 @@ -111,22 +111,23 @@ return None -def get_start_of_day(dt, tzid=None): - return datetime(dt.year, dt.month, dt.day, 0, 0, tzinfo=(tzid and timezone(tzid) or dt.tzinfo)) +def get_start_of_day(dt, tzid): + start = datetime(dt.year, dt.month, dt.day, 0, 0) + return to_timezone(start, tzid) -def get_end_of_day(dt, tzid=None): +def get_end_of_day(dt, tzid): return get_start_of_day(dt + timedelta(1), tzid) -def get_start_of_next_day(dt, tzid=None): +def get_start_of_next_day(dt, tzid): if isinstance(dt, datetime): return get_end_of_day(dt, tzid) else: return dt + timedelta(1) -def ends_on_same_day(dt, end): +def ends_on_same_day(dt, end, tzid): return ( dt.date() == end.date() or - end == get_end_of_day(dt) + end == get_end_of_day(dt, tzid) ) def get_timestamp(): diff -r 70562154ed5b -r 9d17bc8ffa19 imiptools/period.py --- a/imiptools/period.py Tue Feb 03 17:43:44 2015 +0100 +++ b/imiptools/period.py Tue Feb 03 18:19:59 2015 +0100 @@ -215,11 +215,12 @@ return slots -def add_day_start_points(slots): +def add_day_start_points(slots, tzid): """ Introduce into the 'slots' any day start points required by multi-day - periods. + periods. The 'tzid' is required to make sure that appropriate time zones + are chosen and not necessarily those provided by the existing time points. """ new_slots = [] @@ -227,7 +228,7 @@ previously_active = [] for point, active in slots: - start_of_day = get_start_of_day(point) + start_of_day = get_start_of_day(point, tzid) this_date = point.date() # For each new day, add a slot for the start of the day where periods