Skip to content

Commit

Permalink
fix allday event bug in calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Oct 5, 2023
1 parent d6365db commit ed1f774
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions ldaptrombipy/caldav_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from datetime import datetime, timedelta

from ics import Calendar

# from ics import Calendar

from flask import Blueprint, request
from caldav import DAVClient
from ldaptrombipy.config import CALDAV_PASSWORD, CALDAV_SERVER, CALDAV_USERNAME
from flask import Blueprint, request
from ics import Calendar
from flask.json import jsonify

from ldaptrombipy.config import CALDAV_PASSWORD, CALDAV_SERVER, CALDAV_USERNAME

blueprint = Blueprint("caldav", __name__)


Expand Down Expand Up @@ -41,19 +40,29 @@ def user_cal(email):
calender_with_all_events.events.add(event)
r = []
for e in calender_with_all_events.events:
begin = None
end = None
# for all day event the date is in UTC - make bug the calendar
# only start date is mandatory
if e.all_day:
begin = e.end
else:
begin = e.begin
end = e.end
event_as_dict = {
"title": e.name,
"id": e.uid,
"description": e.description,
"start": str(e.begin),
"end": str(e.end),
"start": str(begin),
"end": str(end),
"begin_str": e.begin.datetime.strftime("%d/%m/%Y %H:%M"),
"end_str": e.end.datetime.strftime("%d/%m/%Y %H:%M"),
"allDay": e.all_day,
"editable": False,
"location": e.location,
"organizer": f"{e.organizer.common_name if e.organizer else None}",
"attendees": [f"{att.common_name} ({att.email})" for att in e.attendees]
"attendees": [f"{att.common_name} ({att.email})" for att in e.attendees],
}
r.append(event_as_dict)

return jsonify(r)

0 comments on commit ed1f774

Please sign in to comment.