1.1 --- a/imiptools/client.py Sun Jun 04 18:28:18 2017 +0200
1.2 +++ b/imiptools/client.py Sun Jun 04 20:15:44 2017 +0200
1.3 @@ -25,8 +25,10 @@
1.4 get_window_end, is_new_object, make_freebusy, \
1.5 make_uid, to_part, uri_dict, uri_item, uri_items, \
1.6 uri_parts, uri_values
1.7 -from imiptools.dates import check_permitted_values, format_datetime, get_default_timezone, \
1.8 - get_duration, get_timestamp
1.9 +from imiptools.dates import check_permitted_values, format_datetime, \
1.10 + get_datetime, get_default_timezone, \
1.11 + get_duration, get_time, get_timestamp, \
1.12 + to_datetime
1.13 from imiptools.i18n import get_translator
1.14 from imiptools.freebusy import SupportAttendee, SupportExpires
1.15 from imiptools.profile import Preferences
1.16 @@ -106,14 +108,28 @@
1.17 return prefs and prefs.get("TZID") or get_default_timezone()
1.18
1.19 def get_window_size(self):
1.20 +
1.21 + "Return the period window size as an integer."
1.22 +
1.23 prefs = self.get_preferences()
1.24 try:
1.25 return prefs and int(prefs.get("window_size")) or self.default_window_size
1.26 except (TypeError, ValueError):
1.27 return self.default_window_size
1.28
1.29 + def get_window_start(self):
1.30 +
1.31 + "Return the period window start as a datetime."
1.32 +
1.33 + prefs = self.get_preferences()
1.34 + start = prefs and get_datetime(prefs.get("window_start"), {"TZID" : self.get_tzid()})
1.35 + return isinstance(start, datetime) and start or start and to_datetime(start, self.get_tzid())
1.36 +
1.37 def get_window_end(self):
1.38 - return get_window_end(self.get_tzid(), self.get_window_size())
1.39 +
1.40 + "Return the period window end as a datetime."
1.41 +
1.42 + return get_window_end(self.get_tzid(), self.get_window_size(), self.get_window_start())
1.43
1.44 def is_participating(self):
1.45
1.46 @@ -224,16 +240,22 @@
1.47 if self.messenger and self.messenger.sender != get_address(self.user):
1.48 attr["SENT-BY"] = get_uri(self.messenger.sender)
1.49
1.50 - def get_periods(self, obj, explicit_only=False):
1.51 + def get_periods(self, obj, explicit_only=False, future_only=False):
1.52
1.53 """
1.54 Return periods for the given 'obj'. Interpretation of periods can depend
1.55 - on the time zone, which is obtained for the current user. If
1.56 - 'explicit_only' is set to a true value, only explicit periods will be
1.57 + on the time zone, which is obtained for the current user.
1.58 +
1.59 + If 'explicit_only' is set to a true value, only explicit periods will be
1.60 returned, not rule-based periods.
1.61 +
1.62 + If 'future_only' is set to a true value, only future periods will be
1.63 + returned, not all periods defined by an event starting in the past.
1.64 """
1.65
1.66 - return obj.get_periods(self.get_tzid(), not explicit_only and self.get_window_end() or None)
1.67 + return obj.get_periods(self.get_tzid(),
1.68 + start=(future_only and self.get_window_start() or None),
1.69 + end=(not explicit_only and self.get_window_end() or None))
1.70
1.71 # Store operations.
1.72
1.73 @@ -1096,7 +1118,7 @@
1.74
1.75 # Obtain the affected periods.
1.76
1.77 - periods = self.get_periods(obj)
1.78 + periods = self.get_periods(obj, future_only=True)
1.79
1.80 # Define an overriding transparency, the indicated event transparency,
1.81 # or the default transparency for the free/busy entry.