Tzdata.Util

Summary

day_count_for_month(year, month)
day_of_the_week(year, month, day)
first_weekday_of_month_at_least(year, month, weekday, minimum_date)
last_weekday_of_month(year, month, weekday)

Provide a certain day number (eg. 1 for monday, 2 for tuesday) or downcase 3 letter abbreviation eg. “mon” for monday and a year and month. Get the last day of that type of the specified month. Eg 2014, 8, 5 for the last friday of August 2014. Will return 29

month_number_for_month_name(string)
period_abbrevation(zone_abbr, std_off, letter)

Takes a zone abbreviation, a standard offset integer and a “letter” as found in a the letter column of a tz rule. Depending on whether the standard offset is 0 or not, an suitable abbreviation will be returned

rule_applies_for_year(rule, year)

Takes rule and year and returns true or false depending on whether the rule applies for the year

rules_for_year(rules, year)

Takes a list of rules and a year. Returns the same list of rules except the rules that do not apply for the year

string_amount_to_secs(string)

Take strings of amounts and convert them to ints of seconds. For instance useful for strings from TZ gmt offsets

time_for_rule(rule, year)

Takes a rule and a year. Returns the date and time of when the rule goes into effect

time_modifier(string)

Takes a string and returns a time modifier if the string contains z u or g it’s UTC if it contains s it’s standard otherwise it’s walltime

to_int(string)
transform_rule_at(string)

Given a string of a Rule “AT” column return a tupple of a erlang style time tuple and a modifier that can be either :wall, :standard or :utc

transform_until_datetime(input_date_string)
transform_until_datetime(atom1, map)
tz_day_to_int(year, month, day)

Takes a year and month int and a day that is a string. The day string can be either a number e.g. “5” or TZ data style definition such as “lastSun” or sun>=8

weekday_string_to_number!(parm)

Functions

day_count_for_month(year, month)
day_of_the_week(year, month, day)
first_weekday_of_month_at_least(year, month, weekday, minimum_date)
last_weekday_of_month(year, month, weekday)

Provide a certain day number (eg. 1 for monday, 2 for tuesday) or downcase 3 letter abbreviation eg. “mon” for monday and a year and month. Get the last day of that type of the specified month. Eg 2014, 8, 5 for the last friday of August 2014. Will return 29

iex> last_weekday_of_month(2014, 8, 5) 29

month_number_for_month_name(string)
period_abbrevation(zone_abbr, std_off, letter)

Takes a zone abbreviation, a standard offset integer and a “letter” as found in a the letter column of a tz rule. Depending on whether the standard offset is 0 or not, an suitable abbreviation will be returned.

Examples

iex> period_abbrevation("CE%sT", 0, "-")
"CET"
iex> period_abbrevation("CE%sT", 3600, "S")
"CEST"
iex> period_abbrevation("GMT/BST", 0, "-")
"GMT"
iex> period_abbrevation("GMT/BST", 3600, "S")
"BST"
rule_applies_for_year(rule, year)

Takes rule and year and returns true or false depending on whether the rule applies for the year.

Examples

iex> rule_applies_for_year(%{at: "23:00", from: 1916, in: 5, letter: "S", name: "Denmark", on: "14", record_type: :rule, save: 3600, to: :only, type: "-"}, 1916)
true
iex> rule_applies_for_year(%{at: "23:00", from: 1916, in: 5, letter: "S", name: "Denmark", on: "14", record_type: :rule, save: "1:00", to: :only, type: "-"}, 2000)
false
iex> rule_applies_for_year(%{at: "2:00", from: 1993, in: "Oct", letter: "S", name: "Thule", on: "lastSun", record_type: :rule, save: "0", to: 2006, type: "-"}, 1993)
true
iex> rule_applies_for_year(%{at: "2:00", from: 1994, in: "Oct", letter: "S", name: "Thule", on: "lastSun", record_type: :rule, save: "0", to: 2006, type: "-"}, 1994)
true
iex> rule_applies_for_year(%{at: "2:00", from: 1994, in: "Oct", letter: "S", name: "Thule", on: "lastSun", record_type: :rule, save: "0", to: 2006, type: "-"}, 2006)
true
iex> rule_applies_for_year(%{at: "2:00", from: 1994, in: "Oct", letter: "S", name: "Thule", on: "lastSun", record_type: :rule, save: "0", to: 2006, type: "-"}, 2007)
false
iex> rule_applies_for_year(%{at: "1:00u", from: 1981, in: "Mar", letter: "S", name: "EU", on: "lastSun", record_type: :rule, save: "1:00", to: :max, type: "-"}, 2014)
true
iex> rule_applies_for_year(%{at: "1:00u", from: 1981, in: "Mar", letter: "S", name: "EU", on: "lastSun", record_type: :rule, save: "1:00", to: :max, type: "-"}, 1981)
true
iex> rule_applies_for_year(%{at: "1:00u", from: 1981, in: "Mar", letter: "S", name: "EU", on: "lastSun", record_type: :rule, save: "1:00", to: :max, type: "-"}, 1980)
false
rules_for_year(rules, year)

Takes a list of rules and a year. Returns the same list of rules except the rules that do not apply for the year.

string_amount_to_secs(string)

Take strings of amounts and convert them to ints of seconds. For instance useful for strings from TZ gmt offsets.

iex> string_amount_to_secs(“0”) 0 iex> string_amount_to_secs(“10”) 36000 iex> string_amount_to_secs(“1:00”) 3600 iex> string_amount_to_secs(“-0:01:15”) -75 iex> string_amount_to_secs(“-2:00”) -7200 iex> string_amount_to_secs(“-1:30”) -5400 iex> string_amount_to_secs(“0:50:20”) 3020

time_for_rule(rule, year)

Takes a rule and a year. Returns the date and time of when the rule goes into effect.

time_modifier(string)

Takes a string and returns a time modifier if the string contains z u or g it’s UTC if it contains s it’s standard otherwise it’s walltime

Examples

iex> time_modifier("10:20u")
:utc
iex> time_modifier("10:20")
:wall
iex> time_modifier("10:20 S")
:standard
to_int(string)
transform_rule_at(string)

Given a string of a Rule “AT” column return a tupple of a erlang style time tuple and a modifier that can be either :wall, :standard or :utc

Examples

iex> transform_rule_at("2:20u")
{{2,20,0}, :utc}
iex> transform_rule_at("2:00s")
{{2,0,0}, :standard}
iex> transform_rule_at("2:00")
{{2,0,0}, :wall}
iex> transform_rule_at("0")
{{0,0,0}, :wall}
transform_until_datetime(input_date_string)
transform_until_datetime(atom1, map)
tz_day_to_int(year, month, day)

Takes a year and month int and a day that is a string. The day string can be either a number e.g. “5” or TZ data style definition such as “lastSun” or sun>=8

weekday_string_to_number!(parm)