Packages
tz_extra
0.33.0
0.45.0
0.44.0
0.43.0
0.42.0
0.41.0
0.40.0
0.39.0
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.0
0.32.0
0.31.0
0.30.0
0.29.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.0
0.23.0
0.22.1
0.22.0
0.21.1
0.21.0
0.20.1
0.20.0
0.17.0
0.16.7
0.16.6
0.16.5
0.16.3
0.16.2
0.16.1
0.16.0
0.15.1
0.15.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
Time zone-related utilities
Current section
Files
Jump to
Current section
Files
lib/json_dumper.ex
if Code.ensure_loaded?(Jason) do
defmodule TzExtra.JsonDumper do
@moduledoc false
def dump_countries(filename \\ "countries.json") do
json =
TzExtra.countries()
|> Enum.map(&camelize_map_keys(&1))
|> Jason.encode!()
file_path = Path.join(:code.priv_dir(:tz_extra), filename)
File.write!(file_path, json, [:write])
end
def dump_countries_time_zones(filename \\ "countries_time_zones.json") do
json =
TzExtra.countries_time_zones()
|> Enum.map(&camelize_map_keys(&1))
|> Jason.encode!()
file_path = Path.join(:code.priv_dir(:tz_extra), filename)
File.write!(file_path, json, [:write])
end
defp camelize_map_keys(map) do
for {key, val} <- map, into: %{}, do: {camelize(to_string(key)), val}
end
defp camelize(string) do
String.split(string, "_")
|> Enum.map(&String.capitalize(&1))
|> Enum.join()
|> uncapitalize()
end
defp uncapitalize(string) do
{first, rest} = String.split_at(string, 1)
String.downcase(first) <> rest
end
end
end