1.1 --- a/imip_manager.py Tue Feb 03 17:43:44 2015 +0100
1.2 +++ b/imip_manager.py Tue Feb 03 18:19:59 2015 +0100
1.3 @@ -286,6 +286,10 @@
1.4 self.preferences = Preferences(self.user)
1.5 return self.preferences
1.6
1.7 + def get_tzid(self):
1.8 + prefs = self.get_preferences()
1.9 + return prefs.get("TZID", "UTC")
1.10 +
1.11 # Prettyprinting of dates and times.
1.12
1.13 def format_date(self, dt, format):
1.14 @@ -387,8 +391,7 @@
1.15
1.16 # Obtain the user's timezone.
1.17
1.18 - prefs = self.get_preferences()
1.19 - tzid = prefs.get("TZID", "UTC")
1.20 + tzid = self.get_tzid()
1.21
1.22 # Invent a unique identifier.
1.23
1.24 @@ -558,8 +561,7 @@
1.25
1.26 # Obtain the user's timezone.
1.27
1.28 - prefs = self.get_preferences()
1.29 - tzid = prefs.get("TZID", "UTC")
1.30 + tzid = self.get_tzid()
1.31
1.32 # Provide a summary of the object.
1.33
1.34 @@ -803,8 +805,7 @@
1.35
1.36 # Obtain the user's timezone.
1.37
1.38 - prefs = self.get_preferences()
1.39 - tzid = prefs.get("TZID", "UTC")
1.40 + tzid = self.get_tzid()
1.41
1.42 # Day view: start at the earliest known day and produce days until the
1.43 # latest known day, perhaps with expandable sections of empty days.
1.44 @@ -851,7 +852,7 @@
1.45
1.46 # Add start of day time points for multi-day periods.
1.47
1.48 - add_day_start_points(slots)
1.49 + add_day_start_points(slots, tzid)
1.50
1.51 # Record the slots and all time points employed.
1.52
1.53 @@ -1026,13 +1027,17 @@
1.54
1.55 page = self.page
1.56
1.57 + # Obtain the user's timezone.
1.58 +
1.59 + tzid = self.get_tzid()
1.60 +
1.61 # Produce a row for each interval.
1.62
1.63 intervals = list(intervals)
1.64 intervals.sort()
1.65
1.66 for point, endpoint in intervals:
1.67 - continuation = point == get_start_of_day(point)
1.68 + continuation = point == get_start_of_day(point, tzid)
1.69
1.70 # Some rows contain no period details and are marked as such.
1.71
1.72 @@ -1081,7 +1086,7 @@
1.73 if point == start or continuation:
1.74
1.75 has_continued = continuation and point != start
1.76 - will_continue = not ends_on_same_day(point, end)
1.77 + will_continue = not ends_on_same_day(point, end, tzid)
1.78 css = " ".join(
1.79 ["event"] +
1.80 (has_continued and ["continued"] or []) +
1.81 @@ -1152,12 +1157,13 @@
1.82 """
1.83
1.84 page = self.page
1.85 + tzid = self.get_tzid()
1.86 daystr = format_datetime(point.date())
1.87 value, identifier = self._slot_value_and_identifier(point, endpoint)
1.88 slots = self.env.get_args().get("slot", [])
1.89 self._slot_selector(value, identifier, slots)
1.90 page.label(self.format_time(point, "long"), class_="timepoint day-%s" % daystr, for_=identifier)
1.91 - page.span(self.format_time(endpoint or get_end_of_day(point), "long"), class_="endpoint")
1.92 + page.span(self.format_time(endpoint or get_end_of_day(point, tzid), "long"), class_="endpoint")
1.93
1.94 def _slot_selector(self, value, identifier, slots):
1.95 page = self.page
2.1 --- a/imiptools/dates.py Tue Feb 03 17:43:44 2015 +0100
2.2 +++ b/imiptools/dates.py Tue Feb 03 18:19:59 2015 +0100
2.3 @@ -111,22 +111,23 @@
2.4
2.5 return None
2.6
2.7 -def get_start_of_day(dt, tzid=None):
2.8 - return datetime(dt.year, dt.month, dt.day, 0, 0, tzinfo=(tzid and timezone(tzid) or dt.tzinfo))
2.9 +def get_start_of_day(dt, tzid):
2.10 + start = datetime(dt.year, dt.month, dt.day, 0, 0)
2.11 + return to_timezone(start, tzid)
2.12
2.13 -def get_end_of_day(dt, tzid=None):
2.14 +def get_end_of_day(dt, tzid):
2.15 return get_start_of_day(dt + timedelta(1), tzid)
2.16
2.17 -def get_start_of_next_day(dt, tzid=None):
2.18 +def get_start_of_next_day(dt, tzid):
2.19 if isinstance(dt, datetime):
2.20 return get_end_of_day(dt, tzid)
2.21 else:
2.22 return dt + timedelta(1)
2.23
2.24 -def ends_on_same_day(dt, end):
2.25 +def ends_on_same_day(dt, end, tzid):
2.26 return (
2.27 dt.date() == end.date() or
2.28 - end == get_end_of_day(dt)
2.29 + end == get_end_of_day(dt, tzid)
2.30 )
2.31
2.32 def get_timestamp():
3.1 --- a/imiptools/period.py Tue Feb 03 17:43:44 2015 +0100
3.2 +++ b/imiptools/period.py Tue Feb 03 18:19:59 2015 +0100
3.3 @@ -215,11 +215,12 @@
3.4
3.5 return slots
3.6
3.7 -def add_day_start_points(slots):
3.8 +def add_day_start_points(slots, tzid):
3.9
3.10 """
3.11 Introduce into the 'slots' any day start points required by multi-day
3.12 - periods.
3.13 + periods. The 'tzid' is required to make sure that appropriate time zones
3.14 + are chosen and not necessarily those provided by the existing time points.
3.15 """
3.16
3.17 new_slots = []
3.18 @@ -227,7 +228,7 @@
3.19 previously_active = []
3.20
3.21 for point, active in slots:
3.22 - start_of_day = get_start_of_day(point)
3.23 + start_of_day = get_start_of_day(point, tzid)
3.24 this_date = point.date()
3.25
3.26 # For each new day, add a slot for the start of the day where periods