1defmodule TzParserTest do 2 use ExUnit.Case, async: true 3 alias Tzdata.Parser, as: TzParser 4 5 test "process rule" do 6 zone_text = "Rule EU 1977 1980 - Apr Sun>=1 1:00u 1:00 S\n" 7 processed = TzParser.process_rule(zone_text) 8 assert processed == %{at: {{1,0,0}, :utc}, from: 1977, in: 4, letter: "S", name: "EU", on: "Sun>=1", record_type: :rule, save: 3600, 9 to: 1980, type: "-"} 10 end 11 12 test "process link" do 13 text = "Link Europe/London Europe/Jersey\n" 14 processed = TzParser.process_link(text) 15 assert processed == %{record_type: :link, from: "Europe/London", to: "Europe/Jersey"} 16 end 17 18 test "process zone" do 19 zone_text = """ 20 Zone Europe/London -0:01:15 - LMT 1847 Dec 1 0:00s 21 0:00 GB-Eire %s 1968 Oct 27 22 1:00 - BST 1971 Oct 31 2:00u 23 0:00 GB-Eire %s 1996 24 0:00 EU GMT/BST 25 """ 26 zone_list = String.split(zone_text, "\n") 27 processed = TzParser.process_zone(zone_list) 28 assert hd(processed) == %{name: "Europe/London", record_type: :zone, 29 zone_lines: [%{format: "LMT", gmtoff: -75, rules: nil, until: {{{1847, 12, 1}, {0, 0, 0}}, :standard}}, 30 %{format: "%s", gmtoff: 0, rules: {:named_rules, "GB-Eire"}, until: {{{1968, 10, 27}, {0, 0, 0}}, :wall}}, 31 %{format: "BST", gmtoff: 3600, rules: nil, until: {{{1971, 10, 31}, {2, 0, 0}}, :utc}}, 32 %{format: "%s", gmtoff: 0, rules: {:named_rules, "GB-Eire"}, until: {{{1996, 1, 1}, {0, 0, 0}}, :wall}}, 33 %{format: "GMT/BST", gmtoff: 0, rules: {:named_rules, "EU"}}]} 34 end 35 36 test "process zone - map lines - continuation with until" do 37 line = "1:00 - BST 1971 Oct 31 2:00u\n" 38 result = TzParser.zone_mapped(line) 39 assert elem(result,0) == :continuation_with_until 40 end 41 42 test "remove a comment from the end of a line" do 43 line = "6:30 - MMT # Myanmar Time\n" 44 assert Tzdata.Util.strip_comment(line) == "6:30 - MMT\n" 45 end 46end 47