def limit_timespan(self, start, end, timezone=None): """ Takes the given timespan and moves the start/end date to the closest reservable slot. So if 10:00 - 11:00 is requested it will - on a partly available allocation return 10:00 - 11:00 if the raster allows for that - on a non-partly available allocation return the start/end date of the allocation itself. The resulting times are combined with the allocations start/end date to form a datetime. (time in, datetime out -> maybe not the best idea) """ timezone = timezone or self.timezone if self.partly_available: assert isinstance(start, time) assert isinstance(end, time) s, e = sedate.get_date_range( self.display_start(timezone), start, end ) if self.display_end(timezone) < e: e = self.display_end() if self.display_start(timezone) > s: s = self.display_start() s, e = rasterize_span(s, e, self.raster) return s, e + timedelta(microseconds=1) else: return self.display_start(timezone), self.display_end(timezone)
def test_get_date_range(): assert sedate.get_date_range( sedate.replace_timezone(datetime(2015, 1, 1), 'Europe/Zurich'), datetime(2015, 1, 1, 12, 0).time(), datetime(2015, 1, 2, 11, 0).time(), ) == ( sedate.replace_timezone(datetime(2015, 1, 1, 12, 0), 'Europe/Zurich'), sedate.replace_timezone(datetime(2015, 1, 2, 11, 0), 'Europe/Zurich'), )
def get_date_range(self): if self.allocation.partly_available: return sedate.get_date_range( sedate.to_timezone( self.allocation.start, self.allocation.timezone ), self.start.data, self.end.data ) else: return self.allocation.start, self.allocation.end