When I run mix phx.gen.live ...
with :time_zone_database
set in config.exs
the task will raise with the following error:
** (ArgumentError) cannot add -86400 second to ~U[2021-09-30 19:07:00Z] (with time zone database Tzdata.TimeZoneDatabase), reason: :time_zone_not_found
(elixir 1.12.3) lib/calendar/datetime.ex:1391: DateTime.add/4
lib/mix/phoenix/schema.ex:195: anonymous fn/2 in Mix.Phoenix.Schema.params/2
(elixir 1.12.3) lib/enum.ex:1582: Enum."-map/2-lists^map/1-0-"/2
(elixir 1.12.3) lib/enum.ex:1582: Enum."-map/2-lists^map/1-0-"/2
(elixir 1.12.3) lib/enum.ex:1485: Enum.into/3
lib/mix/phoenix/schema.ex:95: Mix.Phoenix.Schema.new/4
lib/mix/tasks/phx.gen.context.ex:116: Mix.Tasks.Phx.Gen.Context.build/2
lib/mix/tasks/phx.gen.live.ex:93: Mix.Tasks.Phx.Gen.Live.run/1
In my config.exs
I have:
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
If I comment out that line, the mix task will succeed.
At first I thought it maybe it was something in my project causing the issue. To rule it out I created a new Phoenix 1.6 project with mix phx.new date_test
and added {:tzdata, "~> 1.1"}
as a dependency in mix.exs
, added the :time_zone_database
in config.exs
, ran mix deps.get
, and then started the server to make sure that tzdata
fetched the timezone info etc.
I shut down the server and ran the following mix task which raised with the error above:
$ mix phx.gen.live Tests Test tests title:string test_date:utc_datetime
Commenting the line in config.exs
will allow it to succeed.
I don’t use the Phoenix generators very often, but in this case I was working on a quick project idea when I came across this issue. Am I just missing something here; or is this a possible bug?