@@ -31,21 +31,21 @@ defmodule Tzdata do
3131 zone_list provides a list of all the zone names that can be used with
3232 DateTime. This includes aliases.
3333 """
34- @ spec zone_list ( ) :: [ Calendar . time_zone ]
35- def zone_list , do: Tzdata.ReleaseReader . zone_and_link_list
34+ @ spec zone_list ( ) :: [ Calendar . time_zone ( ) ]
35+ def zone_list , do: Tzdata.ReleaseReader . zone_and_link_list ( )
3636
3737 @ doc """
3838 Like zone_list, but excludes aliases for zones.
3939 """
40- @ spec canonical_zone_list ( ) :: [ Calendar . time_zone ]
41- def canonical_zone_list , do: Tzdata.ReleaseReader . zone_list
40+ @ spec canonical_zone_list ( ) :: [ Calendar . time_zone ( ) ]
41+ def canonical_zone_list , do: Tzdata.ReleaseReader . zone_list ( )
4242
4343 @ doc """
4444 A list of aliases for zone names. For instance Europe/Jersey
4545 is an alias for Europe/London. Aliases are also known as linked zones.
4646 """
47- @ spec zone_alias_list ( ) :: [ Calendar . time_zone ]
48- def zone_alias_list , do: Tzdata.ReleaseReader . link_list
47+ @ spec zone_alias_list ( ) :: [ Calendar . time_zone ( ) ]
48+ def zone_alias_list , do: Tzdata.ReleaseReader . link_list ( )
4949
5050 @ doc """
5151 Takes the name of a zone. Returns true if zone exists. Otherwise false.
@@ -57,7 +57,7 @@ defmodule Tzdata do
5757 iex> Tzdata.zone_exists? "Europe/Jersey"
5858 true
5959 """
60- @ spec zone_exists? ( String . t ) :: boolean ( )
60+ @ spec zone_exists? ( String . t ( ) ) :: boolean ( )
6161 def zone_exists? ( name ) , do: Enum . member? ( zone_list ( ) , name )
6262
6363 @ doc """
@@ -69,7 +69,7 @@ defmodule Tzdata do
6969 iex> Tzdata.canonical_zone? "Europe/Jersey"
7070 false
7171 """
72- @ spec canonical_zone? ( Calendar . time_zone ) :: boolean ( )
72+ @ spec canonical_zone? ( Calendar . time_zone ( ) ) :: boolean ( )
7373 def canonical_zone? ( name ) , do: Enum . member? ( canonical_zone_list ( ) , name )
7474
7575 @ doc """
@@ -81,7 +81,7 @@ defmodule Tzdata do
8181 iex> Tzdata.zone_alias? "Europe/London"
8282 false
8383 """
84- @ spec zone_alias? ( Calendar . time_zone ) :: boolean ( )
84+ @ spec zone_alias? ( Calendar . time_zone ( ) ) :: boolean ( )
8585 def zone_alias? ( name ) , do: Enum . member? ( zone_alias_list ( ) , name )
8686
8787 @ doc """
@@ -90,16 +90,16 @@ defmodule Tzdata do
9090 iex> Tzdata.links["Europe/Jersey"]
9191 "Europe/London"
9292 """
93- @ spec links ( ) :: % { Calendar . time_zone => Calendar . time_zone }
94- def links , do: Tzdata.ReleaseReader . links
93+ @ spec links ( ) :: % { Calendar . time_zone ( ) => Calendar . time_zone ( ) }
94+ def links , do: Tzdata.ReleaseReader . links ( )
9595
9696 @ doc """
9797 Returns a map with keys being group names and the values lists of
9898 time zone names. The group names mirror the file names used by the tzinfo
9999 database.
100100 """
101- @ spec zone_lists_grouped ( ) :: % { atom ( ) => [ Calendar . time_zone ] }
102- def zone_lists_grouped , do: Tzdata.ReleaseReader . by_group
101+ @ spec zone_lists_grouped ( ) :: % { atom ( ) => [ Calendar . time_zone ( ) ] }
102+ def zone_lists_grouped , do: Tzdata.ReleaseReader . by_group ( )
103103
104104 @ doc """
105105 Returns tzdata release version as a string.
@@ -109,8 +109,8 @@ defmodule Tzdata do
109109 Tzdata.tzdata_version
110110 "2014i"
111111 """
112- @ spec tzdata_version ( ) :: String . t
113- def tzdata_version , do: Tzdata.ReleaseReader . release_version
112+ @ spec tzdata_version ( ) :: String . t ( )
113+ def tzdata_version , do: Tzdata.ReleaseReader . release_version ( )
114114
115115 @ doc """
116116 Returns a list of periods for the `zone_name` provided as an argument.
@@ -138,12 +138,14 @@ defmodule Tzdata do
138138 iex> Tzdata.periods("Not existing")
139139 {:error, :not_found}
140140 """
141- @ spec periods ( Calendar . time_zone ) :: { :ok , [ time_zone_period ] } | { :error , atom ( ) }
141+ @ spec periods ( Calendar . time_zone ( ) ) :: { :ok , [ time_zone_period ] } | { :error , atom ( ) }
142142 def periods ( zone_name ) do
143143 { tag , p } = Tzdata.ReleaseReader . periods_for_zone_or_link ( zone_name )
144+
144145 case tag do
145146 :ok ->
146- mapped_p = for { _ , f_utc , f_wall , f_std , u_utc , u_wall , u_std , utc_off , std_off , zone_abbr } <- p do
147+ mapped_p =
148+ for { _ , f_utc , f_wall , f_std , u_utc , u_wall , u_std , utc_off , std_off , zone_abbr } <- p do
147149 % {
148150 std_off: std_off ,
149151 utc_off: utc_off ,
@@ -152,8 +154,11 @@ defmodule Tzdata do
152154 zone_abbr: zone_abbr
153155 }
154156 end
157+
155158 { :ok , mapped_p }
156- _ -> { :error , p }
159+
160+ _ ->
161+ { :error , p }
157162 end
158163 end
159164
@@ -191,15 +196,18 @@ defmodule Tzdata do
191196 iex> Tzdata.periods_for_time("Europe/Copenhagen", 63594816000, :wall)
192197 []
193198 """
194- @ spec periods_for_time ( Calendar . time_zone , gregorian_seconds , :standard | :wall | :utc ) :: [ time_zone_period ] | { :error , term }
199+ @ spec periods_for_time ( Calendar . time_zone ( ) , gregorian_seconds , :standard | :wall | :utc ) ::
200+ [ time_zone_period ] | { :error , term }
195201 def periods_for_time ( zone_name , time_point , time_type ) do
196202 case possible_periods_for_zone_and_time ( zone_name , time_point , time_type ) do
197203 { :ok , periods } ->
198204 match_fn = fn % { from: from , until: until } ->
199205 smaller_than_or_equals ( Map . get ( from , time_type ) , time_point ) &&
200206 bigger_than ( Map . get ( until , time_type ) , time_point )
201207 end
208+
202209 do_consecutive_matching ( periods , match_fn , [ ] , false )
210+
203211 { :error , _ } = error ->
204212 error
205213 end
@@ -210,49 +218,62 @@ defmodule Tzdata do
210218 # remaining list.
211219 defp do_consecutive_matching ( [ ] , _fun , [ ] , _did_last_match ) , do: [ ]
212220 defp do_consecutive_matching ( [ ] , _fun , matched , _did_last_match ) , do: matched
221+
213222 defp do_consecutive_matching ( _list , _fun , matched , false ) when matched != [ ] do
214223 # If there are matches and previous did not match then the matches are no
215224 # long consecutive. So we return the result.
216- matched |> Enum . reverse
225+ matched |> Enum . reverse ( )
217226 end
218- defp do_consecutive_matching ( [ h | t ] , fun , matched , _did_last_match ) do
227+
228+ defp do_consecutive_matching ( [ h | t ] , fun , matched , _did_last_match ) do
219229 if fun . ( h ) == true do
220- do_consecutive_matching ( t , fun , [ h | matched ] , true )
230+ do_consecutive_matching ( t , fun , [ h | matched ] , true )
221231 else
222232 do_consecutive_matching ( t , fun , matched , false )
223233 end
224234 end
225235
226236 # Use dynamic periods for points in time that are about 40 years into the future
227237 @ years_in_the_future_where_precompiled_periods_are_used 40
228- @ point_from_which_to_use_dynamic_periods :calendar . datetime_to_gregorian_seconds { { ( :calendar . universal_time |> elem ( 0 ) |> elem ( 0 ) ) + @ years_in_the_future_where_precompiled_periods_are_used , 1 , 1 } , { 0 , 0 , 0 } }
229- defp possible_periods_for_zone_and_time ( zone_name , time_point , time_type ) when time_point >= @ point_from_which_to_use_dynamic_periods do
238+ @ point_from_which_to_use_dynamic_periods :calendar . datetime_to_gregorian_seconds (
239+ { { ( :calendar . universal_time ( ) |> elem ( 0 ) |> elem ( 0 ) ) +
240+ @ years_in_the_future_where_precompiled_periods_are_used ,
241+ 1 , 1 } , { 0 , 0 , 0 } }
242+ )
243+ defp possible_periods_for_zone_and_time ( zone_name , time_point , time_type )
244+ when time_point >= @ point_from_which_to_use_dynamic_periods do
230245 if Tzdata.FarFutureDynamicPeriods . zone_in_30_years_in_eternal_period? ( zone_name ) do
231246 periods ( zone_name )
232247 else
233- link_status = Tzdata.ReleaseReader . links |> Map . get ( zone_name )
248+ link_status = Tzdata.ReleaseReader . links ( ) |> Map . get ( zone_name )
249+
234250 if link_status == nil do
235251 Tzdata.FarFutureDynamicPeriods . periods_for_point_in_time ( time_point , zone_name )
236252 else
237253 possible_periods_for_zone_and_time ( link_status , time_point , time_type )
238254 end
239255 end
240256 end
257+
241258 defp possible_periods_for_zone_and_time ( zone_name , time_point , time_type ) do
242- { :ok , periods } = Tzdata.ReleaseReader . periods_for_zone_time_and_type ( zone_name , time_point , time_type )
243- mapped_periods = periods
244- |> Enum . sort_by ( fn { _ , from_utc , _ , _ , _ , _ , _ , _ , _ , _ } -> - ( from_utc |> Tzdata.ReleaseReader . delimiter_to_number ) end )
245- |> Enum . map (
246- fn { _ , f_utc , f_wall , f_std , u_utc , u_wall , u_std , utc_off , std_off , zone_abbr } ->
247- % {
248- std_off: std_off ,
249- utc_off: utc_off ,
250- from: % { utc: f_utc , wall: f_wall , standard: f_std } ,
251- until: % { utc: u_utc , standard: u_std , wall: u_wall } ,
252- zone_abbr: zone_abbr
253- }
254- end
255- )
259+ { :ok , periods } =
260+ Tzdata.ReleaseReader . periods_for_zone_time_and_type ( zone_name , time_point , time_type )
261+
262+ mapped_periods =
263+ periods
264+ |> Enum . sort_by ( fn { _ , from_utc , _ , _ , _ , _ , _ , _ , _ , _ } ->
265+ - ( from_utc |> Tzdata.ReleaseReader . delimiter_to_number ( ) )
266+ end )
267+ |> Enum . map ( fn { _ , f_utc , f_wall , f_std , u_utc , u_wall , u_std , utc_off , std_off , zone_abbr } ->
268+ % {
269+ std_off: std_off ,
270+ utc_off: utc_off ,
271+ from: % { utc: f_utc , wall: f_wall , standard: f_std } ,
272+ until: % { utc: u_utc , standard: u_std , wall: u_wall } ,
273+ zone_abbr: zone_abbr
274+ }
275+ end )
276+
256277 { :ok , mapped_periods }
257278 end
258279
@@ -270,7 +291,7 @@ defmodule Tzdata do
270291 """
271292 @ spec leap_seconds_with_tai_diff ( ) :: [ % { date_time: :calendar . datetime ( ) , tai_diff: integer } ]
272293 def leap_seconds_with_tai_diff do
273- leap_seconds_data = Tzdata.ReleaseReader . leap_sec_data
294+ leap_seconds_data = Tzdata.ReleaseReader . leap_sec_data ( )
274295 leap_seconds_data . leap_seconds
275296 end
276297
@@ -305,7 +326,7 @@ defmodule Tzdata do
305326 """
306327 @ spec leap_second_data_valid_until ( ) :: :calendar . datetime ( )
307328 def leap_second_data_valid_until do
308- leap_seconds_data = Tzdata.ReleaseReader . leap_sec_data
329+ leap_seconds_data = Tzdata.ReleaseReader . leap_sec_data ( )
309330 leap_seconds_data . valid_until
310331 end
311332
0 commit comments