# HG changeset patch # User Paul Boddie # Date 1442696497 -7200 # Node ID 796a915569f6d85cfffbe7deadb0852d32e3ee10 # Parent e6564d017302859a613e3717a2c2c636652cda8a Changed the free/busy offer periods to use iCalendar period syntax. Made use of more convenience functions for timestamp-related tasks. diff -r e6564d017302 -r 796a915569f6 docs/preferences.txt --- a/docs/preferences.txt Sat Sep 19 22:09:25 2015 +0200 +++ b/docs/preferences.txt Sat Sep 19 23:01:37 2015 +0200 @@ -70,15 +70,16 @@ supporting this setting when counter-proposals are made during event scheduling. -This setting requires a value of one of the following forms: +This setting requires a value indicating a duration as described in the +iCalendar format specification: - - d +http://tools.ietf.org/html/rfc5545#section-3.3.6 For example: - 600 extend scheduling offers for 10 minutes - 1d extend offers for 1 day + PT10M extend scheduling offers for 10 minutes + PT600S extend scheduling offers for 600 seconds (10 minutes) + PT1D extend offers for 1 day freebusy_publishing ------------------- diff -r e6564d017302 -r 796a915569f6 imiptools/client.py --- a/imiptools/client.py Sat Sep 19 22:09:25 2015 +0200 +++ b/imiptools/client.py Sat Sep 19 23:01:37 2015 +0200 @@ -25,7 +25,7 @@ is_new_object, make_freebusy, to_part, \ uri_dict, uri_items, uri_values from imiptools.dates import check_permitted_values, format_datetime, get_default_timezone, \ - get_timestamp, to_timezone + get_duration, get_time, get_timestamp from imiptools.period import can_schedule, remove_period, \ remove_additional_periods, remove_affected_period, \ update_freebusy @@ -139,28 +139,14 @@ def get_offer_period(self): - """ - Decode a specification of one of the following forms... - - - d - """ + "Decode a specification in the iCalendar duration format." prefs = self.get_preferences() duration = prefs and prefs.get("freebusy_offers", config.FREEBUSY_OFFER_DEFAULT) - if duration: - try: - if duration.endswith("d"): - return timedelta(days=int(duration[:-1])) - else: - return timedelta(seconds=int(duration)) - # NOTE: Should probably report an error somehow. + # NOTE: Should probably report an error somehow if None. - except ValueError: - return None - else: - return None + return duration and get_duration(duration) or None def get_organiser_replacement(self): prefs = self.get_preferences() @@ -385,7 +371,7 @@ "Update the DTSTAMP in the current object." dtstamp = self.obj.get_utc_datetime("DTSTAMP") - utcnow = to_timezone(datetime.utcnow(), "UTC") + utcnow = get_time() self.dtstamp = format_datetime(dtstamp and dtstamp > utcnow and dtstamp or utcnow) self.obj["DTSTAMP"] = [(self.dtstamp, {})] @@ -683,7 +669,7 @@ if offer: offer_period = self.get_offer_period() if offer_period: - expires = format_datetime(to_timezone(datetime.utcnow(), "UTC") + offer_period) + expires = get_timestamp(offer_period) else: return else: diff -r e6564d017302 -r 796a915569f6 imiptools/dates.py --- a/imiptools/dates.py Sat Sep 19 22:09:25 2015 +0200 +++ b/imiptools/dates.py Sat Sep 19 23:01:37 2015 +0200 @@ -132,7 +132,10 @@ def get_duration(value): - "Return a duration for the given 'value'." + """ + Return a duration for the given 'value' as a timedelta object. + Where no valid duration is specified, None is returned. + """ if not value: return None @@ -433,11 +436,19 @@ else: return None, None -def get_timestamp(): +def get_timestamp(offset=None): "Return the current time as an iCalendar-compatible string." - return format_datetime(to_timezone(datetime.utcnow(), "UTC")) + offset = offset or timedelta(0) + return format_datetime(to_timezone(datetime.utcnow(), "UTC") + offset) + +def get_time(offset=None): + + "Return the current time." + + offset = offset or timedelta(0) + return to_timezone(datetime.utcnow(), "UTC") + offset def get_tzid(dtstart_attr, dtend_attr): diff -r e6564d017302 -r 796a915569f6 tests/test_resource_invitation_constraints.sh --- a/tests/test_resource_invitation_constraints.sh Sat Sep 19 22:09:25 2015 +0200 +++ b/tests/test_resource_invitation_constraints.sh Sat Sep 19 23:01:37 2015 +0200 @@ -35,7 +35,7 @@ echo 'Europe/Oslo' > "$PREFS/$USER/TZID" echo 'share' > "$PREFS/$USER/freebusy_sharing" echo '10,12,14,16,18:0,15,30,45' > "$PREFS/$USER/permitted_times" -echo '60' > "$PREFS/$USER/freebusy_offers" +echo 'PT60S' > "$PREFS/$USER/freebusy_offers" "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-sauna-all.txt" 2>> $ERROR \ | "$SHOWMAIL" \ diff -r e6564d017302 -r 796a915569f6 tests/test_resource_invitation_constraints_alternative.sh --- a/tests/test_resource_invitation_constraints_alternative.sh Sat Sep 19 22:09:25 2015 +0200 +++ b/tests/test_resource_invitation_constraints_alternative.sh Sat Sep 19 23:01:37 2015 +0200 @@ -35,7 +35,7 @@ echo 'Europe/Oslo' > "$PREFS/$USER/TZID" echo 'share' > "$PREFS/$USER/freebusy_sharing" echo '10,12,14,16,18:0,15,30,45' > "$PREFS/$USER/permitted_times" -echo '60' > "$PREFS/$USER/freebusy_offers" +echo 'PT60S' > "$PREFS/$USER/freebusy_offers" "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-sauna-all.txt" 2>> $ERROR \ | "$SHOWMAIL" \