Пример #1
0
    def on(self,
           instant: DatetimeLike,
           strict: bool = False) -> Iterator[Event]:
        """
        Iterates (in chronological order) over all events that occurs on `day`.

        :param strict: if True events will be returned only if they are strictly *included* in `day`
        """
        begin = floor_datetime_to_midnight(ensure_datetime(instant))
        end = ceil_datetime_to_midnight(
            ensure_datetime(instant) + timedelta(seconds=1))
        query = self.__normalize_timespan(begin, end)
        if strict:
            return self.included(query)
        else:
            return self.overlapping(query)
Пример #2
0
    def make_all_day(self) -> "Timespan":
        if self.is_all_day():
            return self  # Do nothing if we already are a all day timespan

        begin = self.begin_time
        if begin is not None:
            begin = floor_datetime_to_midnight(begin).replace(tzinfo=None)

        end = self.get_effective_end()
        if end is not None:
            end = ceil_datetime_to_midnight(end).replace(tzinfo=None)
            if end == begin:  # we also add another day if the duration would be 0 otherwise
                end = end + TIMEDELTA_DAY

        if self.get_end_representation() == "duration":
            assert end is not None
            assert begin is not None
            return self.replace(begin, None, end - begin, "day")
        else:
            return self.replace(begin, end, None, "day")