Files
email-tracker/external/duckdb/test/sql/timezone/test_icu_calendar.test
2025-10-24 19:21:19 -05:00

124 lines
3.3 KiB
SQL

# name: test/sql/timezone/test_icu_calendar.test
# description: Test the ICU calendar interface
# group: [timezone]
require icu
# Normalise the testing locale
statement ok
SET Calendar = 'gregorian';
statement ok
SET TimeZone = 'America/Los_Angeles';
query I
SELECT name FROM icu_calendar_names()
GROUP BY 1
ORDER BY 1;
----
buddhist
chinese
coptic
dangi
ethiopic
ethiopic-amete-alem
gregorian
hebrew
indian
islamic
islamic-civil
islamic-rgsa
islamic-tbla
islamic-umalqura
iso8601
japanese
persian
roc
query IIIII
SELECT name, value, description, input_type, scope FROM duckdb_settings() WHERE name = 'Calendar';
----
Calendar gregorian The current calendar VARCHAR LOCAL
statement error
SET Calendar = 'fnord';
----
#
# Japanese calendar testing
#
# Create the table before changing calendars
# Otherwise the parser will assume they are Japanese dates
statement ok
SET TimeZone = 'Asia/Tokyo';
statement ok
CREATE TABLE timestamps AS SELECT ts::TIMESTAMPTZ AS ts, era FROM (VALUES
('0645-06-30 00:00:00+00', 'Taika'),
('1867-01-01 00:00:00+00', 'Keiou'),
('1868-09-07 00:00:00+00', 'Keiou'),
('1868-09-08 00:00:00+00', 'Meiji'),
('1912-07-29 00:00:00+00', 'Meiji'),
('1912-07-30 00:00:00+00', 'Taisho'),
('1926-12-24 00:00:00+00', 'Taisho'),
('1926-12-25 00:00:00+00', 'Showa'),
('1989-01-06 00:00:00+00', 'Showa'),
('1989-01-08 00:00:00+00', 'Heisei'),
('2019-05-01 00:00:00+00', 'Reiwa'),
('2022-01-01 00:00:00+00', 'Reiwa')
) tbl(ts, era);
statement ok
SET Calendar = 'japanese';
query IIIII
SELECT name, value, description, input_type, scope FROM duckdb_settings() WHERE name = 'Calendar';
----
Calendar japanese The current calendar VARCHAR LOCAL
# See http://www.meijigakuin.ac.jp/~watson/ref/mtsh.html for details on recent era boundaries.
query III
SELECT era, ts, DATE_PART(['era', 'year', 'month', 'day'], ts)
FROM timestamps
ORDER BY 2
----
Taika 0645-06-27 09:18:59+09:18 {'era': 0, 'year': 1, 'month': 6, 'day': 27}
Keiou 1867-01-01 09:18:59+09:18 {'era': 231, 'year': 3, 'month': 1, 'day': 1}
Keiou 1868-09-07 09:18:59+09:18 {'era': 231, 'year': 4, 'month': 9, 'day': 7}
Meiji 1868-09-08 09:18:59+09:18 {'era': 232, 'year': 1, 'month': 9, 'day': 8}
Meiji 1912-07-29 09:00:00+09 {'era': 232, 'year': 45, 'month': 7, 'day': 29}
Taisho 1912-07-30 09:00:00+09 {'era': 233, 'year': 1, 'month': 7, 'day': 30}
Taisho 1926-12-24 09:00:00+09 {'era': 233, 'year': 15, 'month': 12, 'day': 24}
Showa 1926-12-25 09:00:00+09 {'era': 234, 'year': 1, 'month': 12, 'day': 25}
Showa 1989-01-06 09:00:00+09 {'era': 234, 'year': 64, 'month': 1, 'day': 6}
Heisei 1989-01-08 09:00:00+09 {'era': 235, 'year': 1, 'month': 1, 'day': 8}
Reiwa 2019-05-01 09:00:00+09 {'era': 236, 'year': 1, 'month': 5, 'day': 1}
Reiwa 2022-01-01 09:00:00+09 {'era': 236, 'year': 4, 'month': 1, 'day': 1}
# Issue #5234
statement ok
SET CALENDAR='islamic-umalqura';
statement ok
SELECT strftime(TIMESTAMPTZ '-260722-3-4 0:3:52',TIMESTAMP '-285441-5-3 8:3:4'::VARCHAR);
# Issue #5235
statement ok
SET CALENDAR='indian';
query I
SELECT TIMESTAMPTZ '-276069-9-30 0:0:00 America/Whitehorse';
----
276070-10-01 (BC) 18:19:11+09:18
# Issue #5237
statement ok
PRAGMA CALENDAR='japanese';
# The TIMETZ cast is not valid (checked against PG)
statement error
SELECT strftime(TIMESTAMPTZ '-23831-1-15 2:5:17 America/La_Paz',TIMETZ '0:8:29 America/Cayman'::VARCHAR);
----
time field value out of range