Skip to content
Merged
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
42 changes: 42 additions & 0 deletions lib/ical/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defmodule ICal.Application do
@moduledoc false

use Application
require Logger

@impl Application
def start(_type, _args) do
Calendar.get_time_zone_database()
|> check_timezone_availability()

Supervisor.start_link([], strategy: :one_for_one, name: ICal.Application)
end

defp check_timezone_availability(Calendar.UTCOnlyTimeZoneDatabase) do
cond do
Code.ensure_loaded?(Tz) ->
Logger.info(
"ICal has registered the Tz time zone database to ensure full function. Consider adding this to your app config: config :elixir, :time_zone_database, Tz.TimeZoneDatabase"
)

Calendar.put_time_zone_database(Tz.TimeZoneDatabase)
:ok

Code.ensure_loaded?(TimeZoneInfo) ->
Logger.info(
"ICal has registered the TimeZoneInfo time zone database to ensure full function. Consider adding this to your app config: config :elixir, :time_zone_database, TimeZoneInfo.TimeZoneDatabase"
)

Calendar.put_time_zone_database(TimeZoneInfo.TimeZoneDatabase)
:ok

true ->
Logger.error(
"No timezone database is instealled, and neither the Tz nor TimeZoneInfo libraries wer found. Please install one of those as per the ICal documentation to ensure that ICal works correctly. Without a timezone database, no calendaring data with timezones will parse correctly."
)
end
end

# there is a non-default timezone database installed, so ICal is good to go.
defp check_timezone_availability(_), do: :ok
end
8 changes: 8 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ defmodule ICal.Mixfile do
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {ICal.Application, []}
]
end

defp elixirc_paths(:test), do: ["lib", "test/support", "test/data"]
defp elixirc_paths(_), do: ["lib"]

Expand Down
Loading