Sort timezone list by current offset (#2229)

This commit fixes a bug where the timezone list was sorted by the
standard offset, not considering timezone changes. The list was working
properly, but sorting was wrong.
This commit is contained in:
Vinicius Brasil 2022-09-16 04:20:32 -03:00 committed by GitHub
parent be1b72895d
commit dcd1640b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
defmodule Plausible.Timezones do
@spec options() :: [{:key, String.t()}, {:value, String.t()}, {:offset, integer()}]
def options do
Tzdata.zone_list()
|> Enum.map(&build_option/1)
@ -7,7 +8,7 @@ defmodule Plausible.Timezones do
defp build_option(timezone_code) do
timezone_info = Timex.Timezone.get(timezone_code)
offset_in_minutes = div(timezone_info.offset_utc, -60)
offset_in_minutes = timezone_info |> Timex.Timezone.total_offset() |> div(-60)
hhmm_formatted_offset =
timezone_info