Skip to content

Commit

Permalink
Fix %z abbreviation in 2024b. Bump included ETS file to 2024b. (#147)
Browse files Browse the repository at this point in the history
* Fix zone abbreviation %z in 2024b.
Also include 2024b release ets file.
* Update changelog
  • Loading branch information
lau authored Sep 10, 2024
1 parent ba42b76 commit 00b38af
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 12 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog for Tzdata

## Dev

### Fixed

- Can handle months being spelled out instead of abbreveated to 3 letters as happened in one place in 2024b. (Moxley Stratton)

### Changed

- tzdata release version shipped with this library is now 2024b instead of 2021e.

## [1.1.1] - 2021-10-31

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions lib/tzdata/far_future_dynamic_periods.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defmodule Tzdata.FarFutureDynamicPeriods do
utc_off: utc_off,
from: %{utc: from, wall: from_wall_time, standard: from_standard_time},
until: %{standard: until_standard_time, wall: until_wall_time, utc: until_utc},
zone_abbr: Util.period_abbrevation(zone_line.format, std_off, begin_rule.letter)
zone_abbr: Util.period_abbrevation(zone_line.format, std_off, utc_off, begin_rule.letter)
}

{{until_year_wall, _, _}, _} = :calendar.gregorian_seconds_to_datetime(until_wall_time)
Expand Down Expand Up @@ -100,7 +100,7 @@ defmodule Tzdata.FarFutureDynamicPeriods do
utc_off: utc_off,
from: %{utc: from, wall: from_wall_time, standard: from_standard_time},
until: %{standard: until_standard_time, wall: until_wall_time, utc: until_utc},
zone_abbr: Util.period_abbrevation(zone_line.format, std_off, letter)
zone_abbr: Util.period_abbrevation(zone_line.format, std_off, utc_off, letter)
}
%{period: period, rules: rules, zone_line: zone_line, rule_name: rule_name}
end
Expand Down
10 changes: 5 additions & 5 deletions lib/tzdata/period_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Tzdata.PeriodBuilder do
utc_off: utc_off,
from: %{utc: from, wall: from_wall_time, standard: from_standard_time},
until: %{standard: until_standard_time, wall: until_wall_time, utc: until_utc},
zone_abbr: zone_line_hd.format
zone_abbr: TzUtil.period_abbrevation(zone_line_hd.format, std_off, utc_off, letter)
}

h_calc_next_zone_line(btz_data, period, until_utc, zone_line_tl, letter)
Expand Down Expand Up @@ -134,7 +134,7 @@ defmodule Tzdata.PeriodBuilder do
utc_off: utc_off,
from: %{utc: from, wall: from_wall_time, standard: from_standard_time},
until: %{standard: until_standard_time, wall: until_wall_time, utc: until_utc},
zone_abbr: zone_line_hd.format
zone_abbr: TzUtil.period_abbrevation(zone_line_hd.format, std_off, utc_off, letter)
}

h_calc_next_zone_line(btz_data, period, until_utc, zone_line_tl, letter)
Expand Down Expand Up @@ -177,7 +177,7 @@ defmodule Tzdata.PeriodBuilder do
utc_off: utc_off,
from: %{utc: from, wall: from_wall_time, standard: from_standard_time},
until: %{standard: :max, wall: :max, utc: :max},
zone_abbr: TzUtil.period_abbrevation(zone_line.format, std_off, letter)
zone_abbr: TzUtil.period_abbrevation(zone_line.format, std_off, utc_off, letter)
}

[period]
Expand Down Expand Up @@ -208,7 +208,7 @@ defmodule Tzdata.PeriodBuilder do
utc_off: utc_off,
from: %{utc: from, wall: from_wall_time, standard: from_standard_time},
until: %{standard: until_standard_time, wall: until_wall_time, utc: until_utc},
zone_abbr: TzUtil.period_abbrevation(zone_line.format, std_off, letter)
zone_abbr: TzUtil.period_abbrevation(zone_line.format, std_off, utc_off, letter)
}

[ period | tail ]
Expand Down Expand Up @@ -305,7 +305,7 @@ defmodule Tzdata.PeriodBuilder do
utc_off: utc_off,
from: %{utc: from, wall: from_wall_time, standard: from_standard_time},
until: %{standard: until_standard_time, wall: until_wall_time, utc: until_utc},
zone_abbr: TzUtil.period_abbrevation(zone_line.format, std_off, letter)
zone_abbr: TzUtil.period_abbrevation(zone_line.format, std_off, utc_off, letter)
}

no_more_rules = rules_tail == []
Expand Down
41 changes: 36 additions & 5 deletions lib/tzdata/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,26 @@ defmodule Tzdata.Util do
abbreviation will be returned.
## Examples
iex> period_abbrevation("CE%sT", 0, "-")
iex> period_abbrevation("CE%sT", 0, 0, "-")
"CET"
iex> period_abbrevation("CE%sT", 3600, "S")
iex> period_abbrevation("CE%sT", 3600, 0, "S")
"CEST"
iex> period_abbrevation("GMT/BST", 0, "-")
iex> period_abbrevation("GMT/BST", 0, 0, "-")
"GMT"
iex> period_abbrevation("GMT/BST", 3600, "S")
iex> period_abbrevation("GMT/BST", 3600, 0, "S")
"BST"
iex> period_abbrevation("%z", 39600, 0, "-")
"+11"
iex> period_abbrevation("%z", 7200, 0, "-")
"+02"
iex> period_abbrevation("%z", -9000, 0, "-")
"-0230"
"""
def period_abbrevation(zone_abbr, std_off, letter) do
def period_abbrevation("%z", std_off, utc_off, _) do
seconds_to_percentagez_string(std_off + utc_off)
end

def period_abbrevation(zone_abbr, std_off, _utc_off, letter) do
if Regex.match?(~r/\//, zone_abbr) do
period_abbrevation_h(:slash, zone_abbr, std_off, letter)
else
Expand Down Expand Up @@ -509,6 +519,27 @@ defmodule Tzdata.Util do
zone_abbr
end

defp seconds_to_percentagez_string(seconds) when is_integer(seconds) do
string = case rem(seconds, 3600) do
0 ->
"#{lpad_zero(floor(abs(seconds/3600.0)))}"
remaining_seconds ->
"#{lpad_zero(floor(abs(seconds/3600.0)))}"<>"#{lpad_zero(floor(abs(remaining_seconds/60)))}"
end
case seconds do
seconds when seconds > 0 ->
"+" <> "#{string}"
seconds when seconds < 0 ->
"-" <> "#{string}"
_ ->
string
end
end

defp lpad_zero(arg) do
String.pad_leading("#{arg}", 2, "0")
end

def strip_comment(line), do: Regex.replace(~r/[\s]*#.+/, line, "")

def filter_comment_lines(input) do
Expand Down
Binary file removed priv/release_ets/2021e.v2.ets
Binary file not shown.
Binary file added priv/release_ets/2024b.v2.ets
Binary file not shown.
67 changes: 67 additions & 0 deletions test/tz_time_zone_database_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,71 @@ defmodule Tzdata.TimeZoneDatabaseTest do
)
end
end

test "Zones that use %z for abbreveation" do
assert {:ok,
%{
zone_abbr: "-12",
utc_offset: -43200,
std_offset: 0,
from_wall: :min,
until_wall: :max
}} ==
TimeZoneDatabase.time_zone_periods_from_wall_datetime(
~N[2019-03-31 02:59:59],
"Etc/GMT+12"
)

assert {:ok,
%{
from_wall: ~N[1937-01-01 00:15:00],
std_offset: 0,
until_wall: ~N[1942-08-01 00:00:00],
utc_offset: 9900,
zone_abbr: "+0245"
}} ==
TimeZoneDatabase.time_zone_periods_from_wall_datetime(
~N[1940-01-01 10:59:59],
"Africa/Nairobi"
)

assert {:ok,
%{
from_wall: ~N[1978-10-15 02:00:00],
std_offset: 0,
until_wall: ~N[1983-07-31 02:00:00],
utc_offset: 10800,
zone_abbr: "+03"
}} ==
TimeZoneDatabase.time_zone_periods_from_wall_datetime(
~N[1983-01-01 10:59:59],
"Europe/Istanbul"
)

assert {:ok,
%{
from_wall: ~N[1983-07-31 03:00:00],
std_offset: 3600,
until_wall: ~N[1983-10-02 02:00:00],
utc_offset: 10800,
zone_abbr: "+04"
}} ==
TimeZoneDatabase.time_zone_periods_from_wall_datetime(
~N[1983-09-01 10:59:59],
"Europe/Istanbul"
)

assert {:ok,
%{
from_wall: ~N[2015-10-04 01:30:00],
std_offset: 0,
until_wall: ~N[2019-07-01 00:00:00],
utc_offset: 39600,
zone_abbr: "+11"
}} ==
TimeZoneDatabase.time_zone_periods_from_wall_datetime(
~N[2019-01-01 10:59:59],
"Pacific/Norfolk"
)
end
end

0 comments on commit 00b38af

Please sign in to comment.