Skip to content

Commit 371af61

Browse files
committed
Update timezones.json
1 parent 962a318 commit 371af61

File tree

9 files changed

+109
-31
lines changed

9 files changed

+109
-31
lines changed

ldml2json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ java -DCLDR_DIR=$CLDR_STAGING \
6969
cp $CLDR_REPO/common/supplemental/units.xml $CLDR_PRODUCTION
7070
cp $CLDR_REPO/common/supplemental/pluralRanges.xml $CLDR_PRODUCTION/plural_ranges.xml
7171
cp $CLDR_REPO/common/supplemental/subdivisions.xml $CLDR_PRODUCTION
72-
cp $CLDR_REPO/common/bcp47/timezone.xml $CLDR_PRODUCTION/timezones.xml
7372

7473
mkdir -p $CLDR_PRODUCTION/subdivisions
7574
cp $CLDR_STAGING/common/subdivisions/* $CLDR_PRODUCTION/subdivisions

lib/cldr/config/config.ex

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,8 @@ defmodule Cldr.Config do
15171517
Path.join(cldr_data_dir(), @timezones_file)
15181518
|> File.read!()
15191519
|> Cldr.Config.json_library().decode!
1520-
|> Enum.reject(fn {_k, v} -> v == [""] end)
1520+
|> Cldr.Map.atomize_keys(level: 2)
1521+
|> Cldr.Map.atomize_values(only: :territory)
15211522
|> Map.new()
15221523
end
15231524

@@ -1557,7 +1558,40 @@ defmodule Cldr.Config do
15571558
Path.join(cldr_data_dir(), @metazone_file)
15581559
|> File.read!()
15591560
|> json_library().decode!()
1560-
|> Cldr.Map.atomize_keys(filter: ["from", "to"])
1561+
|> Cldr.Map.deep_map(fn
1562+
s when is_binary(s) ->
1563+
maybe_datetime(s)
1564+
other ->
1565+
other
1566+
end)
1567+
|> Enum.map(&reverse_date_list/1)
1568+
|> Map.new()
1569+
end
1570+
1571+
defp maybe_datetime(string) do
1572+
maybe_datetime =
1573+
string
1574+
|> String.replace(" ", "T")
1575+
|> Kernel.<>(":00Z")
1576+
|> DateTime.from_iso8601()
1577+
1578+
case maybe_datetime do
1579+
{:ok, datetime, _} -> datetime
1580+
_error -> string
1581+
end
1582+
end
1583+
1584+
defp reverse_date_list({k, v}) when is_list(v) do
1585+
{k, Enum.reverse(v)}
1586+
end
1587+
1588+
defp reverse_date_list({k, v}) when is_map(v) do
1589+
{k, reverse_date_list(v)}
1590+
end
1591+
1592+
defp reverse_date_list(map) when is_map(map) do
1593+
Enum.map(map, fn m -> reverse_date_list(m) end)
1594+
|> Map.new()
15611595
end
15621596

15631597
@doc """

lib/cldr/locale.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ defmodule Cldr.Locale do
13431343
iex> Cldr.Locale.timezone_from_locale "en-AU"
13441344
{:error,
13451345
{Cldr.AmbiguousTimezoneError,
1346-
"Cannot determine the timezone since the territory :AU has 24 timezone IDs"}}
1346+
"Cannot determine the timezone since the territory :AU has 13 timezone IDs"}}
13471347
13481348
"""
13491349

@@ -1394,7 +1394,7 @@ defmodule Cldr.Locale do
13941394
iex> Cldr.Locale.timezone_from_locale :"en-AU", TestBackend.Cldr
13951395
{:error,
13961396
{Cldr.AmbiguousTimezoneError,
1397-
"Cannot determine the timezone since the territory :AU has 24 timezone IDs"}}
1397+
"Cannot determine the timezone since the territory :AU has 13 timezone IDs"}}
13981398
13991399
"""
14001400

lib/cldr/timezone.ex

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,31 @@ defmodule Cldr.Timezone do
1212
releases.
1313
1414
"""
15+
alias Cldr.Locale
16+
17+
@type timezone :: %{
18+
aliases: [String.t(), ...],
19+
preferred: nil | Locale.territory_code(),
20+
territory: Locale.territory_code()
21+
}
1522
@unknown_zone "Etc/Unknown"
1623

1724
@timezones Cldr.Config.timezones()
1825

1926
@timezones_by_territory @timezones
20-
|> Enum.group_by(fn {k, _v} -> String.slice(k, 0, 2) end, fn {_k, v} ->
21-
v
27+
|> Enum.group_by(
28+
fn {_k, v} -> v.territory end,
29+
fn {k, v} -> Map.put(v, :short_zone, k)
2230
end)
23-
|> Enum.map(fn {k, v} ->
24-
case Cldr.validate_territory(k) do
25-
{:ok, territory} -> {territory, Elixir.List.flatten(v)}
26-
{:error, _} -> nil
27-
end
31+
|> Enum.map(fn
32+
{nil, _} ->
33+
nil
34+
{:UT = territory, v} ->
35+
{territory, Elixir.List.flatten(v)}
36+
{k, v} ->
37+
case Cldr.validate_territory(k) do
38+
{:ok, territory} -> {territory, Elixir.List.flatten(v)}
39+
end
2840
end)
2941
|> Enum.reject(&is_nil/1)
3042
|> Map.new()
@@ -34,7 +46,7 @@ defmodule Cldr.Timezone do
3446
IANA timezone names.
3547
3648
"""
37-
@spec timezones() :: %{(zone_name :: String.t()) => [iana_name :: String.t(), ...]}
49+
@spec timezones() :: %{(zone_name :: String.t()) => timezone()}
3850
def timezones do
3951
@timezones
4052
end
@@ -65,7 +77,7 @@ defmodule Cldr.Timezone do
6577

6678
@doc false
6779
def timezones_for_territory(territory) do
68-
timezones_for_territory()
80+
timezones_by_territory()
6981
|> Map.fetch(territory)
7082
end
7183

@@ -79,13 +91,17 @@ defmodule Cldr.Timezone do
7991
### Examples
8092
8193
iex> Cldr.Timezone.get_short_zone("ausyd")
82-
["Australia/Sydney", "Australia/ACT", "Australia/Canberra", "Australia/NSW"]}
94+
%{
95+
preferred: nil,
96+
aliases: ["Australia/Sydney", "Australia/ACT", "Australia/Canberra", "Australia/NSW"],
97+
territory: :AU
98+
}
8399
84100
iex> Cldr.Timezone.get_short_zone("nope")
85101
nil
86102
87103
"""
88-
@spec get_short_zone(String.t(), String.t() | nil) :: [String.t()] | nil
104+
@spec get_short_zone(String.t(), String.t() | nil) :: map() | nil
89105
def get_short_zone(short_zone, default \\ nil) do
90106
Map.get(timezones(), short_zone, default)
91107
end
@@ -105,14 +121,20 @@ defmodule Cldr.Timezone do
105121
### Example
106122
107123
iex> Cldr.Timezone.fetch_short_zone("ausyd")
108-
{:ok,
109-
["Australia/Sydney", "Australia/ACT", "Australia/Canberra", "Australia/NSW"]}
124+
{
125+
:ok,
126+
%{
127+
preferred: nil,
128+
aliases: ["Australia/Sydney", "Australia/ACT", "Australia/Canberra", "Australia/NSW"],
129+
territory: :AU
130+
}
131+
}
110132
111133
iex> Cldr.Timezone.fetch_short_zone("nope")
112134
:error
113135
114136
"""
115-
@spec fetch_short_zone(String.t()) :: {:ok, [String.t()]} | :error
137+
@spec fetch_short_zone(String.t()) :: {:ok, map()} | :error
116138
def fetch_short_zone(short_zone) do
117139
Map.fetch(timezones(), short_zone)
118140
end
@@ -133,7 +155,7 @@ defmodule Cldr.Timezone do
133155
@spec validate_short_zone(String.t()) :: {:ok, String.t()} | {:error, String.t()}
134156
def validate_short_zone(short_zone) do
135157
case fetch(short_zone) do
136-
{:ok, [first_zone | _others]} ->
158+
{:ok, %{aliases: [first_zone | _others]}} ->
137159
{:ok, first_zone}
138160

139161
:error ->

mix/support/consolidate.ex

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -614,27 +614,36 @@ defmodule Cldr.Consolidate do
614614
meta =
615615
Enum.map(metazones, fn
616616
%{"usesMetazone" => %{"metazone" => metazone, "from" => from, "to" => to}} ->
617-
%{metazone => %{from: from, to: to}}
617+
[metazone, from, to]
618618

619619
%{"usesMetazone" => %{"metazone" => metazone, "from" => from}} ->
620-
%{metazone => %{from: from, to: nil}}
620+
[metazone, from, nil]
621621

622622
%{"usesMetazone" => %{"metazone" => metazone, "to" => to}} ->
623-
%{metazone => %{from: nil, to: to}}
623+
[metazone, nil, to]
624624

625625
%{"usesMetazone" => %{"metazone" => metazone}} ->
626-
%{metazone => %{from: nil, to: nil}}
626+
[metazone, nil, nil]
627627

628628
{subzone, zones} when is_list(zones)->
629629
%{subzone => zones}
630630
|> map_metazones()
631631
|> Map.new()
632632
end)
633-
{zone, meta}
633+
634+
if is_subzone?(meta) do
635+
{zone, Cldr.Map.merge_map_list(meta)}
636+
else
637+
{zone, meta}
638+
end
634639
end)
635640
|> Map.new()
636641
end
637642

643+
defp is_subzone?(meta) when is_list(meta) do
644+
is_map(hd(meta))
645+
end
646+
638647
@doc false
639648
def save_territories do
640649
path = Path.join(consolidated_output_dir(), "territories.json")
@@ -929,11 +938,24 @@ defmodule Cldr.Consolidate do
929938
|> File.read!()
930939
|> String.replace(~r/<!DOCTYPE.*>\n/, "")
931940
|> xpath(~x"//key"l,
932-
timezones: [~x"./type"l, name: ~x"./@name"s, alias: ~x"./@alias"s]
941+
timezones: [
942+
~x"./type"l,
943+
name: ~x"./@name"s,
944+
alias: ~x"./@alias"s,
945+
region: ~x"./@region"s,
946+
preferred: ~x"./@preferred"s
947+
]
933948
)
934949

935-
Enum.map(timezones, fn %{alias: aliases, name: name} ->
936-
{name, String.split(aliases, " ")}
950+
Enum.map(timezones, fn
951+
%{alias: aliases, name: name, region: "", preferred: ""} ->
952+
region = String.slice(name, 0, 2) |> String.upcase() |> String.to_atom()
953+
{name, %{aliases: String.split(aliases, " "), territory: region, preferred: nil}}
954+
%{alias: aliases, name: name, region: region, preferred: ""} ->
955+
region = String.to_atom(region)
956+
{name, %{aliases: String.split(aliases, " "), territory: region, preferred: nil}}
957+
%{name: name, preferred: preferred} ->
958+
{name, %{aliases: nil, territory: nil, preferred: preferred}}
937959
end)
938960
|> Map.new()
939961
|> save_file(path)

priv/cldr/metazone_mapping.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

priv/cldr/metazones.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)