Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal #582: Remove utc_offset Dependency #9521

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions extension/icu/icu-timezone.cpp
Expand Up @@ -81,6 +81,9 @@ static void ICUTimeZoneFunction(ClientContext &context, TableFunctionInput &data
break;
}

// What PG reports is the total offset for today,
// which is the ICU total offset (i.e., "raw") plus the DST offset.
raw_offset_ms += dst_offset_ms;
output.SetValue(2, index, Value::INTERVAL(Interval::FromMicro(raw_offset_ms * Interval::MICROS_PER_MSEC)));
output.SetValue(3, index, Value(dst_offset_ms != 0));
++index;
Expand Down
154 changes: 126 additions & 28 deletions test/sql/function/timestamp/test_icu_strptime.test
Expand Up @@ -74,43 +74,141 @@ SELECT '1582-10-10'::TIMESTAMPTZ AS ts;
# Same date, multiple TZ names
#

# We can't use the offsets in pg_timezone_names()
# because they change with the date
# So hard code the original values
# The important point is that these cover all the GMT offsets.
statement ok
CREATE TABLE zones AS (
SELECT median(name) as tz_name
FROM pg_timezone_names()
GROUP BY utc_offset
ORDER BY utc_offset
FROM (VALUES
('Etc/GMT-14'),
('NZ-CHAT'),
('Pacific/Auckland'),
('Pacific/Enderbury'),
('Australia/LHI'),
('Australia/Melbourne'),
('Pacific/Efate'),
('Australia/Darwin'),
('Asia/Tokyo'),
('Australia/Eucla'),
('Asia/Shanghai'),
('Asia/Novosibirsk'),
('Asia/Yangon'),
('Asia/Omsk'),
('Asia/Kathmandu'),
('Asia/Colombo'),
('Asia/Oral'),
('Asia/Kabul'),
('Europe/Astrakhan'),
('Asia/Tehran'),
('Asia/Kuwait'),
('Asia/Nicosia'),
('Europe/Budapest'),
('Etc/GMT-0'),
('Atlantic/Azores'),
('America/Cayenne'),
('America/Nuuk'),
('CNT'),
('America/Martinique'),
('America/Louisville'),
('America/Rainy_River'),
('America/Shiprock'),
('Mexico/BajaNorte'),
('America/Sitka'),
('Pacific/Marquesas'),
('Pacific/Johnston'),
('Pacific/Niue'),
('Etc/GMT+12'),
) tbl(tz_name)
);

statement ok
CREATE TABLE abbrevs AS (
SELECT median(abbrev) as tz_name
FROM pg_timezone_names()
GROUP BY utc_offset
ORDER BY utc_offset
FROM (VALUES
('Etc/GMT-14'),
('NZ-CHAT'),
('NZ'),
('Pacific/Enderbury'),
('Australia/Hobart'),
('Australia/LHI'),
('Pacific/Efate'),
('Australia/Adelaide'),
('Etc/GMT-9'),
('Australia/Eucla'),
('CTT'),
('Asia/Phnom_Penh'),
('Asia/Yangon'),
('Asia/Thimbu'),
('Asia/Kathmandu'),
('IST'),
('Asia/Qyzylorda'),
('Asia/Kabul'),
('Europe/Samara'),
('Iran'),
('EAT'),
('CAT'),
('Europe/Bratislava'),
('GMT'),
('Atlantic/Azores'),
('America/Cayenne'),
('America/Nuuk'),
('CNT'),
('PRT'),
('America/Panama'),
('America/Rankin_Inlet'),
('Canada/Yukon'),
('PST'),
('America/Nome'),
('Pacific/Marquesas'),
('Pacific/Johnston'),
('Pacific/Niue'),
('Etc/GMT+12'),
) tbl(tz_name)
);

statement ok
CREATE TABLE offsets AS (
SELECT
CASE WHEN EXTRACT(MINUTE FROM utc_offset) <> 0
THEN
CASE WHEN utc_offset < INTERVAL 0 SECOND
THEN LEFT(utc_offset, 6)
ELSE '+' || LEFT(utc_offset, 5)
END
ELSE
CASE WHEN utc_offset < INTERVAL 0 SECOND
THEN LEFT(utc_offset, 3)
ELSE '+' || LEFT(utc_offset, 2)
END
END AS utc_offset
FROM (
SELECT DISTINCT utc_offset
FROM pg_timezone_names()
ORDER BY ALL
) z
);
CREATE TABLE offsets AS
FROM (VALUES
('+14'),
('+13'),
('+12:45'),
('+12'),
('+11'),
('+10:30'),
('+10'),
('+09:30'),
('+09'),
('+08:45'),
('+08'),
('+07'),
('+06:30'),
('+06'),
('+05:45'),
('+05:30'),
('+05'),
('+04:30'),
('+04'),
('+03:30'),
('+03'),
('+02'),
('+01'),
('+00'),
('-01'),
('-02'),
('-03'),
('-03:30'),
('-04'),
('-05'),
('-06'),
('-07'),
('-08'),
('-09'),
('-09:30'),
('-10'),
('-11'),
('-12'),
) tbl(utc_offset)
;

foreach func strptime try_strptime

Expand Down