python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

all-day event exceeds from one day

Open agn-7 opened this issue 3 years ago • 3 comments

When I'm going to create a new all-day event using the following lines it creates that for two days!

...
event = self.calendar.new_event()
event.subject = kwargs.get("summary", "Orangery")
event.location = kwargs.get("location", "Germany")

event.start = datetime.combine(start_date, datetime.min.time())  # coverts date to datetime
event.end = event.start + timedelta(hours=24)
event.is_all_day = True
print(event.start, event.end)

Out:

2022-09-30 00:00:00+03:00 2022-10-01 00:00:00+03:00

Screenshot:

2022-09-30_17-35

agn-7 avatar Sep 30 '22 14:09 agn-7

Seems like a bug

alejcas avatar Oct 06 '22 13:10 alejcas

This is the code on is_all_day:

    @is_all_day.setter
    def is_all_day(self, value):
        self.__is_all_day = value
        if value:
            # Api requirement: start and end must be set to midnight
            # is_all_day needs event.start included in the request on updates
            # is_all_day needs event.end included in the request on updates
            start = self.__start or dt.date.today()
            end = self.__end or dt.date.today()

            if (start + dt.timedelta(hours=24)) > end:
                # Api requires that under is_all_day=True start and
                # end must be at least 24 hours away
                end = start + dt.timedelta(hours=24)

            # set to midnight
            start = dt.datetime(start.year, start.month, start.day)
            end = dt.datetime(end.year, end.month, end.day)

            self.start = start
            self.end = end
        self._track_changes.add(self._cc('isAllDay'))

alejcas avatar Oct 06 '22 13:10 alejcas