Packages
tzdata
0.1.0
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.1
1.0.0-rc.0
0.5.22
0.5.21
0.5.20
0.5.19
0.5.18
0.5.17
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.1.201805
0.1.201605
0.1.201603
0.1.201601
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.2
0.0.1
Tzdata is a parser and library for the tz database.
Current section
Files
Jump to
Current section
Files
lib/tzdata/table_parser.ex
defmodule Tzdata.TableParser do
@moduledoc false
# Parsing of the table file zone1970.tab
import Tzdata.Util
@file_name "zone1970.tab"
def read_file(dir_prepend \\ "source_data", file_name \\ @file_name) do
File.stream!("#{dir_prepend}/#{file_name}")
|> process_file
end
def process_file(file_stream) do
file_stream
|> filter_comment_lines
|> filter_empty_lines
|> Stream.map(&(strip_comment(&1))) # Strip comments at line end. Like this comment.
|> Stream.map(&(process_line(&1)))
end
@line_regex ~r/(?<country_codes>[^\s]+)[\s]+(?<latlong>[^\s]+)[\s]+(?<timezone>[^\s]+)[\s]+(?<comments>[^\n]+)?/
defp process_line(line) do
map = Regex.named_captures(@line_regex, line)
map = %{map | "country_codes" => split_country_codes(map["country_codes"]) }
map
end
defp split_country_codes(string) do
String.split(string, ",")
end
end