Skip to content

Commit

Permalink
feat: add timezone.get/3
Browse files Browse the repository at this point in the history
Closes #653
  • Loading branch information
bitwalker committed Apr 4, 2021
1 parent 695eef8 commit a67c58b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/timezone/timezone.ex
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ defmodule Timex.Timezone do
end
end

@doc """
Same as `get/2`, but allows specifying whether to obtain the TimezoneInfo based
on utc time or wall time manually (`:utc` or `:wall` respectively).
"""
def get(:utc, _, _), do: %TimezoneInfo{}
def get(:local, datetime, _), do: local(datetime)

def get(tz, datetime, utc_or_wall) do
case name_of(tz) do
{:error, _} = err ->
err

name ->
get_info(name, datetime, utc_or_wall)
end
end

defp get_info(timezone, datetime, utc_or_wall)

defp get_info("Etc/UTC", _datetime, _utc_or_wall),
Expand Down

0 comments on commit a67c58b

Please sign in to comment.