Skip to content

Commit

Permalink
Fix bugs in fantasy league calendar download
Browse files Browse the repository at this point in the history
  • Loading branch information
axelclark committed Oct 7, 2024
1 parent 62099d2 commit 824b915
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
14 changes: 10 additions & 4 deletions lib/ex338/fantasy_leagues.ex
Original file line number Diff line number Diff line change
Expand Up @@ -227,26 +227,26 @@ defmodule Ex338.FantasyLeagues do
championship_date =
%Ex338.ICalendar.Event{
summary: "338 Championship: #{championship.title}",
dtstart: DateTime.to_date(championship_at)
dtstart: to_pst_date(championship_at)
}

if DateTime.compare(trade_deadline_at, waiver_deadline_at) == :eq do
[
%Ex338.ICalendar.Event{
summary: "#{championship.title} 338 Waiver and Trade Deadline",
dtstart: DateTime.to_date(championship.waiver_deadline_at)
dtstart: to_pst_date(championship.waiver_deadline_at)
},
championship_date
]
else
[
%Ex338.ICalendar.Event{
summary: "#{championship.title} 338 Waiver Deadline",
dtstart: DateTime.to_date(championship.waiver_deadline_at)
dtstart: to_pst_date(championship.waiver_deadline_at)
},
%Ex338.ICalendar.Event{
summary: "#{championship.title} 338 Trade Deadline",
dtstart: DateTime.to_date(championship.trade_deadline_at)
dtstart: to_pst_date(championship.trade_deadline_at)
},
championship_date
]
Expand All @@ -256,4 +256,10 @@ defmodule Ex338.FantasyLeagues do
defp add_uid_and_dtstamp(event) do
%{event | uid: Ecto.UUID.generate(), dtstamp: DateTime.utc_now()}
end

defp to_pst_date(datetime) do
datetime
|> DateTime.shift_zone!("America/Los_Angeles")
|> DateTime.to_date()
end
end
17 changes: 10 additions & 7 deletions lib/ex338/icalendar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ defmodule Ex338.ICalendar do
def to_ics(events) when is_list(events) do
events = Enum.map(events, &to_ics/1)

"""
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
PRODID:-//Ex338 ICalendar//EN
#{events}END:VCALENDAR
"""
calendar =
"""
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
PRODID:-//Ex338 ICalendar//EN
#{events}END:VCALENDAR
"""

String.replace(calendar, "\n", "\r\n")
end

def to_ics(event) do
Expand Down

0 comments on commit 824b915

Please sign in to comment.