Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions lib/icalendar/util/deserialize.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,7 @@ defmodule ICalendar.Util.Deserialize do
def to_date(date_string, %{"TZID" => timezone}) do
# Microsoft Outlook calendar .ICS files report times in Greenwich Standard Time (UTC +0)
# so just convert this to UTC
timezone =
if Regex.match?(~r/\//, timezone) do
timezone
else
Timex.Timezone.Utils.to_olson(timezone)
end
timezone = parse_timezone(timezone)

date_string =
case String.last(date_string) do
Expand All @@ -264,6 +259,21 @@ defmodule ICalendar.Util.Deserialize do
to_date(date_string, %{"TZID" => "Etc/UTC"})
end

defp parse_timezone(timezone) do
tz =
if Regex.match?(~r/\//, timezone) do
timezone
else
Timex.Timezone.Utils.to_olson(timezone)
end

if is_nil(tz) do
"Etc/UTC"
else
tz
end
end

defp to_geo(geo) do
geo
|> desanitized()
Expand Down
13 changes: 13 additions & 0 deletions test/icalendar/deserialize_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ defmodule ICalendar.DeserializeTest do
assert event.dtend.time_zone == "America/Chicago"
end

test "with unrecognized Timezone" do
ics = """
BEGIN:VEVENT
DTEND;TZID=GMT-0500:22221224T084500
DTSTART;TZID=GMT-0500:22221224T083000
END:VEVENT
"""

[event] = ICalendar.from_ics(ics)
assert event.dtstart.time_zone == "Etc/UTC"
assert event.dtend.time_zone == "Etc/UTC"
end

test "with CR+LF line endings" do
ics = """
BEGIN:VEVENT
Expand Down