# HG changeset patch # User Paul Boddie # Date 1445356873 -7200 # Node ID e288b996492be2ceb7c4c7881ef7b2f297aa0d61 # Parent 1dda608a1fb1745c53276db52e151b673b030e7b Clip event periods to the view period. diff -r 1dda608a1fb1 -r e288b996492b imiptools/period.py --- a/imiptools/period.py Tue Oct 20 17:44:45 2015 +0200 +++ b/imiptools/period.py Tue Oct 20 18:01:13 2015 +0200 @@ -573,7 +573,7 @@ # Period layout. -def get_scale(periods, tzid): +def get_scale(periods, tzid, view_period=None): """ Return an ordered time scale from the given list of 'periods'. @@ -581,17 +581,23 @@ The given 'tzid' is used to make sure that the times are defined according to the chosen time zone. + An optional 'view_period' is used to constrain the scale to the given + period. + The returned scale is a mapping from time to (starting, ending) tuples, where starting and ending are collections of periods. """ scale = {} + view_start = view_period and to_timezone(view_period.get_start_point(), tzid) or None + view_end = view_period and to_timezone(view_period.get_end_point(), tzid) or None for p in periods: # Add a point and this event to the starting list. start = to_timezone(p.get_start(), tzid) + start = view_start and max(start, view_start) or start if not scale.has_key(start): scale[start] = [], [] scale[start][0].append(p) @@ -599,6 +605,7 @@ # Add a point and this event to the ending list. end = to_timezone(p.get_end(), tzid) + end = view_end and min(end, view_end) or end if not scale.has_key(end): scale[end] = [], [] scale[end][1].append(p) diff -r 1dda608a1fb1 -r e288b996492b imipweb/calendar.py --- a/imipweb/calendar.py Tue Oct 20 17:44:45 2015 +0200 +++ b/imipweb/calendar.py Tue Oct 20 18:01:13 2015 +0200 @@ -390,7 +390,7 @@ # Get the time scale with start and end points. - scale = get_scale(periods, tzid) + scale = get_scale(periods, tzid, view_period) # Get the time slots for the periods. # Time slots are collections of Point objects with lists of active