Skip to content

Commit

Permalink
Add default value for DTSTAMP
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed Apr 10, 2022
1 parent f1b6e98 commit 4b8d620
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/icalendar/util/kv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ defmodule ICalendar.Util.KV do
"ATTENDEE;CN=James SM;PARTSTAT=ACCEPTED:mailto:james@clockk.com\n"
"""
def build("DTSTAMP", nil) do
"DTSTAMP:#{Value.to_ics(DateTime.utc_now())}Z\n"
end

def build(_, nil) do
""
end
Expand Down
37 changes: 37 additions & 0 deletions test/icalendar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ defmodule ICalendarTest do
%ICalendar.Event{
summary: "Film with Amy and Adam",
dtstart: Timex.to_datetime({{2015, 12, 24}, {8, 30, 00}}),
dtstamp: Timex.to_datetime({{2015, 12, 23}, {19, 00, 00}}),
dtend: Timex.to_datetime({{2015, 12, 24}, {8, 45, 00}}),
description: "Let's go see Star Wars."
},
%ICalendar.Event{
summary: "Morning meeting",
dtstart: Timex.to_datetime({{2015, 12, 24}, {19, 00, 00}}),
dtstamp: Timex.to_datetime({{2015, 12, 24}, {15, 00, 00}}),
dtend: Timex.to_datetime({{2015, 12, 24}, {22, 30, 00}}),
description: "A big long meeting with lots of details."
}
Expand All @@ -53,12 +55,14 @@ defmodule ICalendarTest do
BEGIN:VEVENT
DESCRIPTION:Let's go see Star Wars.
DTEND:20151224T084500Z
DTSTAMP:20151223T190000Z
DTSTART:20151224T083000Z
SUMMARY:Film with Amy and Adam
END:VEVENT
BEGIN:VEVENT
DESCRIPTION:A big long meeting with lots of details.
DTEND:20151224T223000Z
DTSTAMP:20151224T150000Z
DTSTART:20151224T190000Z
SUMMARY:Morning meeting
END:VEVENT
Expand All @@ -71,6 +75,7 @@ defmodule ICalendarTest do
%ICalendar.Event{
summary: "Film with Amy and Adam",
dtstart: Timex.to_datetime({{2015, 12, 24}, {8, 30, 00}}),
dtstamp: Timex.to_datetime({{2015, 12, 24}, {8, 00, 00}}),
dtend: Timex.to_datetime({{2015, 12, 24}, {8, 45, 00}}),
description: "Let's go see Star Wars, and have fun.",
location: "123 Fun Street, Toronto ON, Canada"
Expand All @@ -87,6 +92,7 @@ defmodule ICalendarTest do
BEGIN:VEVENT
DESCRIPTION:Let's go see Star Wars\\, and have fun.
DTEND:20151224T084500Z
DTSTAMP:20151224T080000Z
DTSTART:20151224T083000Z
LOCATION:123 Fun Street\\, Toronto ON\\, Canada
SUMMARY:Film with Amy and Adam
Expand Down Expand Up @@ -131,6 +137,7 @@ defmodule ICalendarTest do
test "Icalender.to_ics/1 with rrule and exdates" do
events = [
%ICalendar.Event{
dtstamp: Timex.to_datetime({{2015, 12, 24}, {8, 00, 00}}),
rrule: %{
byday: ["TH", "WE"],
freq: "WEEKLY",
Expand All @@ -155,6 +162,7 @@ defmodule ICalendarTest do
VERSION:2.0
PRODID:-//Elixir ICalendar//Elixir ICalendar//EN
BEGIN:VEVENT
DTSTAMP:20151224T080000Z
EXDATE;TZID=America/Toronto:20200916T143000
EXDATE;TZID=America/Toronto:20200917T143000
RRULE:FREQ=WEEKLY;BYDAY=TH,WE;BYSETPOS=-1;INTERVAL=-2;UNTIL=20201204T045959
Expand All @@ -163,11 +171,40 @@ defmodule ICalendarTest do
"""
end

test "Icalender.to_ics/1 with default value for DTSTAMP" do
events = [
%ICalendar.Event{
summary: "Film with Amy and Adam",
dtstart: Timex.to_datetime({{2015, 12, 24}, {8, 30, 00}}),
dtend: Timex.to_datetime({{2015, 12, 24}, {8, 45, 00}}),
description: "Let's go see Star Wars, and have fun."
}
]

ics = %ICalendar{events: events} |> ICalendar.to_ics()

assert ics == """
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
PRODID:-//Elixir ICalendar//Elixir ICalendar//EN
BEGIN:VEVENT
DESCRIPTION:Let's go see Star Wars\\, and have fun.
DTEND:20151224T084500Z
DTSTAMP:#{ICalendar.Value.to_ics(DateTime.utc_now())}Z
DTSTART:20151224T083000Z
SUMMARY:Film with Amy and Adam
END:VEVENT
END:VCALENDAR
"""
end

test "ICalender.to_ics/1 -> ICalendar.from_ics/1 and back again" do
events = [
%ICalendar.Event{
summary: "Film with Amy and Adam",
dtstart: Timex.to_datetime({{2015, 12, 24}, {8, 30, 00}}),
dtstamp: Timex.to_datetime({{2015, 12, 24}, {8, 00, 00}}),
dtend: Timex.to_datetime({{2015, 12, 24}, {8, 45, 00}}),
description: "Let's go see Star Wars, and have fun.",
location: "123 Fun Street, Toronto ON, Canada",
Expand Down

0 comments on commit 4b8d620

Please sign in to comment.