diff --git a/calendar_import_ics/tests/sample_files/test_calendar.ics b/calendar_import_ics/tests/sample_files/test_calendar.ics index 5d888fa2..e74ae53b 100644 --- a/calendar_import_ics/tests/sample_files/test_calendar.ics +++ b/calendar_import_ics/tests/sample_files/test_calendar.ics @@ -16,9 +16,9 @@ TRANSP:OPAQUE UID:ed27f2b89f945c7692547a2903c20cbe80de6cc6 END:VEVENT BEGIN:VEVENT -DTEND:20061011T190000Z +DTEND;TZID=America/Denver:20061011T190000 DTSTAMP:20240221T094129Z -DTSTART:20061011T160000Z +DTSTART;TZID=America/Denver:20061011T160000 SEQUENCE:0 SUMMARY:Unavailable TRANSP:OPAQUE diff --git a/calendar_import_ics/wizards/wizard_import_ics.py b/calendar_import_ics/wizards/wizard_import_ics.py index 562b5163..bdd17331 100644 --- a/calendar_import_ics/wizards/wizard_import_ics.py +++ b/calendar_import_ics/wizards/wizard_import_ics.py @@ -4,6 +4,9 @@ import base64 from datetime import datetime +import pytz +from dateutil import parser + from odoo import _, fields, models from odoo.exceptions import ValidationError @@ -42,6 +45,8 @@ def button_import(self): lines = file_str.split("\n") ics_event = {} for line in lines: + if line.startswith(("DTSTART", "DTEND")) and "TZID=" in line: + line = self.convert_date_to_z(line) if line.startswith("BEGIN:VEVENT"): ics_event = {} elif line.startswith("END:VEVENT"): @@ -116,3 +121,16 @@ def _delete_non_imported_events(self, imported_events): non_imported_event.write({"partner_ids": [(3, self.partner_id.id)]}) if not non_imported_events.partner_ids: non_imported_events.unlink() + + def convert_date_to_z(self, line): + split_parts = line.split(":") + event_phase = split_parts[0].split(";TZID=")[0] + tz_id = split_parts[0].split(";TZID=")[1] + date = split_parts[1] + + date_obj = parser.parse(date) + tz = pytz.timezone(tz_id) + + utc_date = tz.localize(date_obj).astimezone(pytz.UTC) + utc_date_string = utc_date.strftime(event_phase + ":%Y%m%dT%H%M%SZ") + return utc_date_string