Skip to content

Commit

Permalink
Makes time_zone_database configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
brianberlin committed Jan 30, 2024
1 parent bfe967a commit f01d916
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/cocktail/schedule_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ defmodule Cocktail.ScheduleState do
%__MODULE__{
recurrence_rules: schedule.recurrence_rules |> Enum.map(&RuleState.new/1),
recurrence_times: recurrence_times_after_current_time,
exception_times: schedule.exception_times |> Enum.uniq() |> Enum.sort(&(Cocktail.Time.compare(&1, &2) in [:lt, :eq])),
exception_times:
schedule.exception_times |> Enum.uniq() |> Enum.sort(&(Cocktail.Time.compare(&1, &2) in [:lt, :eq])),
start_time: schedule.start_time,
current_time: current_time,
duration: schedule.duration
Expand Down
3 changes: 1 addition & 2 deletions lib/cocktail/time.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ defmodule Cocktail.Time do
end
end


defp new_coerced_datetime(year, month, day, hour, minute, second, microsecond, timezone) do
days_in_month_b = :calendar.last_day_of_the_month(year, month)

Expand Down Expand Up @@ -340,6 +339,6 @@ defmodule Cocktail.Time do
def parse(_, _), do: {:error, :invalid_format}

defp get_time_zone_datebase do
Application.get_env(:elixir, :time_zone_database, Tzdata.TimeZoneDatabase)
Application.get_env(:elixir, :time_zone_database)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule Cocktail.Mixfile do
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.23", only: :dev, runtime: false},
{:excoveralls, "~> 0.10", only: :test},
{:tzdata, "~> 1.1"}
{:tzdata, "~> 1.1", only: :test}
]
end
end
14 changes: 7 additions & 7 deletions test/cocktail/monthly_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ defmodule Cocktail.MonthlyTest do
|> Schedule.add_recurrence_rule(:monthly, interval: 3)

assert first_n_occurrences(schedule, 7) == [
~U[2017-01-02 06:00:00Z],
~U[2017-03-02 06:00:00Z],
~U[2017-04-02 06:00:00Z],
~U[2017-05-02 06:00:00Z],
~U[2017-07-02 06:00:00Z],
~U[2017-09-02 06:00:00Z],
~U[2017-10-02 06:00:00Z]
~Y[2017-01-02 06:00:00 Etc/UTC],
~Y[2017-03-02 06:00:00 Etc/UTC],
~Y[2017-04-02 06:00:00 Etc/UTC],
~Y[2017-05-02 06:00:00 Etc/UTC],
~Y[2017-07-02 06:00:00 Etc/UTC],
~Y[2017-09-02 06:00:00 Etc/UTC],
~Y[2017-10-02 06:00:00 Etc/UTC]
]

assert_icalendar_preserved(schedule)
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ExUnit.configure(exclude: [pending: true], formatters: [ExUnit.CLIFormatter, ExUnitNotifier])
ExUnit.start()

Application.put_env(:elixir, :time_zone_database, Tzdata.TimeZoneDatabase)
Code.require_file("test/support/datetime_sigil.ex")

0 comments on commit f01d916

Please sign in to comment.