From 79f2ed4f69232da021a216754fd3f437fe323df8 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 3 Apr 2019 16:22:26 +0200 Subject: [PATCH] Dates shouldn't have TZID when UTC > The "TZID" property parameter MUST NOT be applied to DATE properties and DATE-TIME or TIME properties whose time values are specified in UTC. https://icalendar.org/iCalendar-RFC-5545/3-2-19-time-zone-identifier.html Signed-off-by: Thomas Citharel --- lib/icalendar/util/kv.ex | 4 ++++ test/icalendar/event_test.exs | 4 ++-- test/icalendar_test.exs | 28 ++++++++++++++-------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/icalendar/util/kv.ex b/lib/icalendar/util/kv.ex index 60c4015..6f5cc8a 100644 --- a/lib/icalendar/util/kv.ex +++ b/lib/icalendar/util/kv.ex @@ -52,6 +52,10 @@ defmodule ICalendar.Util.KV do "#{key}:#{lat};#{lon}\n" end + def build(key, date = %DateTime{time_zone: "Etc/UTC"}) do + "#{key}:#{Value.to_ics(date)}\n" + end + def build(key, date = %DateTime{}) do "#{key};TZID=#{date.time_zone}:#{Value.to_ics(date)}\n" end diff --git a/test/icalendar/event_test.exs b/test/icalendar/event_test.exs index 756aa67..3fb2877 100644 --- a/test/icalendar/event_test.exs +++ b/test/icalendar/event_test.exs @@ -56,8 +56,8 @@ defmodule ICalendar.EventTest do assert ics == """ BEGIN:VEVENT - DTEND;TZID=Etc/UTC:20151224T084500 - DTSTART;TZID=Etc/UTC:20151224T083000 + DTEND:20151224T084500 + DTSTART:20151224T083000 END:VEVENT """ end diff --git a/test/icalendar_test.exs b/test/icalendar_test.exs index bfef409..626a73f 100644 --- a/test/icalendar_test.exs +++ b/test/icalendar_test.exs @@ -36,14 +36,14 @@ defmodule ICalendarTest do VERSION:2.0 BEGIN:VEVENT DESCRIPTION:Let's go see Star Wars. - DTEND;TZID=Etc/UTC:20151224T084500 - DTSTART;TZID=Etc/UTC:20151224T083000 + DTEND:20151224T084500 + DTSTART:20151224T083000 SUMMARY:Film with Amy and Adam END:VEVENT BEGIN:VEVENT DESCRIPTION:A big long meeting with lots of details. - DTEND;TZID=Etc/UTC:20151224T223000 - DTSTART;TZID=Etc/UTC:20151224T190000 + DTEND:20151224T223000 + DTSTART:20151224T190000 SUMMARY:Morning meeting END:VEVENT END:VCALENDAR @@ -69,8 +69,8 @@ defmodule ICalendarTest do VERSION:2.0 BEGIN:VEVENT DESCRIPTION:Let's go see Star Wars\\, and have fun. - DTEND;TZID=Etc/UTC:20151224T084500 - DTSTART;TZID=Etc/UTC:20151224T083000 + DTEND:20151224T084500 + DTSTART:20151224T083000 LOCATION:123 Fun Street\\, Toronto ON\\, Canada SUMMARY:Film with Amy and Adam END:VEVENT @@ -123,14 +123,14 @@ defmodule ICalendarTest do VERSION:2.0 BEGIN:VEVENT DESCRIPTION:Let's go see Star Wars. - DTEND;TZID=Etc/UTC:20151224T084500 - DTSTART;TZID=Etc/UTC:20151224T083000 + DTEND:20151224T084500 + DTSTART:20151224T083000 SUMMARY:Film with Amy and Adam END:VEVENT BEGIN:VEVENT DESCRIPTION:A big long meeting with lots of details. - DTEND;TZID=Etc/UTC:20151224T223000 - DTSTART;TZID=Etc/UTC:20151224T190000 + DTEND:20151224T223000 + DTSTART:20151224T190000 SUMMARY:Morning meeting END:VEVENT END:VCALENDAR @@ -163,14 +163,14 @@ defmodule ICalendarTest do VERSION:2.0 BEGIN:VEVENT DESCRIPTION:Let's go see Star Wars. - DTEND;TZID=Etc/UTC:20151224T084500 - DTSTART;TZID=Etc/UTC:20151224T083000 + DTEND:20151224T084500 + DTSTART:20151224T083000 SUMMARY:Film with Amy and Adam END:VEVENT BEGIN:VEVENT DESCRIPTION:A big long meeting with lots of details. - DTEND;TZID=Etc/UTC:20151224T223000 - DTSTART;TZID=Etc/UTC:20151224T190000 + DTEND:20151224T223000 + DTSTART:20151224T190000 SUMMARY:Morning meeting END:VEVENT END:VCALENDAR