Skip to content

Commit bbcfde6

Browse files
Added version upgrade tests for datename_tzoffset
Added datename_tzoffset-before-16_10-or-17_6-vu-prepare/verify/cleanup test files to represent the difference in DATENAME output format before function update. Previously, timezone offset output was numeric, now it is in an offset string format '+/- HH:MM'. Task: BABEL-5846 Signed-off-by: Manisha Deshpande <mmdeshp@amazon.com>
1 parent 513bc9d commit bbcfde6

10 files changed

+849
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DROP TABLE datename_tzoffset_test_cases;
2+
GO
3+
4+
DROP TABLE datename_stability_test;
5+
GO
6+
7+
DROP VIEW datename_tzoffset_no_offset_tests_view;
8+
GO
9+
10+
DROP TABLE datename_tzoffset_different_test_scenarios;
11+
GO
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
CREATE TABLE datename_tzoffset_test_cases (
2+
date_value VARCHAR(50),
3+
offset_value NVARCHAR(100)
4+
);
5+
GO
6+
7+
-- Create view for date inputs without offset specified
8+
CREATE VIEW datename_tzoffset_no_offset_tests_view AS
9+
SELECT
10+
datename(TZOFFSET, '2025-06-03 14:30:15.1234567') AS datetime2_offset,
11+
datename(TZOFFSET, '2025-06-03') AS date_offset,
12+
datename(TZOFFSET, '14:30:15.1234567') AS timestamp_offset,
13+
datename(TZOFFSET, '') AS empty_string_offset;
14+
GO
15+
16+
-- Create table for stability testing of DATENAME
17+
-- to store results under different configurations
18+
CREATE TABLE datename_stability_test (
19+
config_type VARCHAR(20),
20+
config_value VARCHAR(30),
21+
test_date VARCHAR(50),
22+
datepart VARCHAR(20),
23+
result NVARCHAR(100)
24+
);
25+
GO
26+
27+
28+
-- Testing SET LANGUAGE stability
29+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
30+
VALUES ('Initial', 'default', '2025-06-30', 'weekday', DATENAME(weekday, '2025-06-30'));
31+
GO
32+
~~ROW COUNT: 1~~
33+
34+
35+
-- SET LANGUAGE 'us_english' (default)
36+
SET LANGUAGE 'us_english';
37+
GO
38+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
39+
VALUES ('LANGUAGE', 'us_english', '2025-06-30', 'weekday', DATENAME(weekday, '2025-06-30'));
40+
GO
41+
~~ROW COUNT: 1~~
42+
43+
44+
-- SET LANGUAGE 'French' (not fully supported but test anyway)
45+
SET LANGUAGE 'French';
46+
GO
47+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
48+
VALUES ('LANGUAGE', 'French', '2025-06-30', 'weekday', DATENAME(weekday, '2025-06-30'));
49+
GO
50+
~~ROW COUNT: 1~~
51+
52+
53+
-- Restore default language
54+
SET LANGUAGE 'us_english';
55+
GO
56+
57+
58+
-- Testing SET DATEFIRST stability
59+
-- SET DATEFIRST 7 (default - Sunday)
60+
SET DATEFIRST 7;
61+
GO
62+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
63+
VALUES ('DATEFIRST', '7', '2025-01-05', 'week', DATENAME(week, '2025-01-05'));
64+
GO
65+
~~ROW COUNT: 1~~
66+
67+
68+
-- SET DATEFIRST 1 (Monday)
69+
SET DATEFIRST 1;
70+
GO
71+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
72+
VALUES ('DATEFIRST', '1', '2025-01-05', 'week', DATENAME(week, '2025-01-05'));
73+
GO
74+
~~ROW COUNT: 1~~
75+
76+
77+
-- Restore default
78+
SET DATEFIRST 7;
79+
GO
80+
81+
82+
-- Testing SET DATEFORMAT stability
83+
-- SET DATEFORMAT mdy (default)
84+
SET DATEFORMAT mdy;
85+
GO
86+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
87+
VALUES ('DATEFORMAT', 'mdy', '03-06-2025', 'month', DATENAME(month, '03-06-2025'));
88+
GO
89+
~~ROW COUNT: 1~~
90+
91+
92+
-- SET DATEFORMAT dmy (not supported, treated as mdy)
93+
SET DATEFORMAT dmy;
94+
GO
95+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
96+
VALUES ('DATEFORMAT', 'dmy', '03-06-2025', 'month', DATENAME(month, '03-06-2025'));
97+
GO
98+
~~ROW COUNT: 1~~
99+
100+
101+
102+
-- SET DATEFORMAT ymd
103+
SET DATEFORMAT ymd;
104+
GO
105+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
106+
VALUES ('DATEFORMAT', 'ymd', '2025-03-06', 'month', DATENAME(month, '2025-03-06'));
107+
GO
108+
~~ROW COUNT: 1~~
109+
110+
111+
-- SET DATEFORMAT ydm (not supported, treated as ymd)
112+
SET DATEFORMAT ydm;
113+
GO
114+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
115+
VALUES ('DATEFORMAT', 'ydm', '2025-03-06', 'month', DATENAME(month, '2025-03-06'));
116+
GO
117+
~~ROW COUNT: 1~~
118+
119+
120+
121+
-- SET DATEFORMAT myd (not supported currently)
122+
SET DATEFORMAT myd;
123+
GO
124+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
125+
VALUES ('DATEFORMAT', 'myd', '06-2025-03', 'month', DATENAME(month, '06-2025-03'));
126+
GO
127+
~~ERROR (Code: 33557097)~~
128+
129+
~~ERROR (Message: date/time field value out of range: "06-2025-03")~~
130+
131+
132+
-- SET DATEFORMAT dym (not supported currently)
133+
SET DATEFORMAT dym;
134+
GO
135+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
136+
VALUES ('DATEFORMAT', 'dym', '06-2025-03', 'month', DATENAME(month, '06-2025-03'));
137+
GO
138+
~~ERROR (Code: 33557097)~~
139+
140+
~~ERROR (Message: date/time field value out of range: "06-2025-03")~~
141+
142+
143+
-- Restore default
144+
SET DATEFORMAT mdy;
145+
GO
146+
147+
148+
-- Testing SET_CONFIG('TIMEZONE') stability
149+
-- Set timezone to UTC
150+
SELECT set_config('timezone', 'UTC', false);
151+
GO
152+
~~START~~
153+
text
154+
UTC
155+
~~END~~
156+
157+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
158+
VALUES
159+
('TIMEZONE', 'UTC', '2025-06-30 12:00:00', 'hour', DATENAME(hour, '2025-06-30 12:00:00')),
160+
('TIMEZONE', 'UTC', '2025-01-01 05:30:45', 'hour', DATENAME(hour, '2025-01-01 05:30:45'));
161+
GO
162+
~~ROW COUNT: 2~~
163+
164+
165+
-- Set timezone to a different value
166+
SELECT set_config('timezone', 'Africa/Nairobi', false)
167+
GO
168+
~~START~~
169+
text
170+
Africa/Nairobi
171+
~~END~~
172+
173+
INSERT INTO datename_stability_test (config_type, config_value, test_date, datepart, result)
174+
VALUES
175+
('TIMEZONE', 'Africa/Nairobi', '2025-06-30 12:00:00', 'hour', DATENAME(hour, '2025-06-30 12:00:00')),
176+
('TIMEZONE', 'Africa/Nairobi', '2025-01-01 05:30:45', 'hour', DATENAME(hour, '2025-01-01 05:30:45'));
177+
GO
178+
~~ROW COUNT: 2~~
179+
180+
181+
-- Reset timezone to UTC
182+
SELECT set_config('timezone', 'UTC', false);
183+
GO
184+
~~START~~
185+
text
186+
UTC
187+
~~END~~
188+
189+
190+
191+
-- Test table insertion
192+
INSERT INTO datename_tzoffset_test_cases (date_value, offset_value)
193+
VALUES
194+
('2025-06-03 14:30:15 +01:30', DATENAME(TZOFFSET, '2025-06-03 14:30:15 +01:30')),
195+
('2025-06-03 14:30:15 -05:00', DATENAME(TZOFFSET, '2025-06-03 14:30:15 -05:00')),
196+
('2016-12-26 23:30:05.523456+08:00', DATENAME(TZOFFSET, '2016-12-26 23:30:05.523456+08:00')),
197+
('2016-12-26 23:30:05.523456+8', DATENAME(TZOFFSET, CAST('2016-12-26 23:30:05.523456+8' AS DATETIMEOFFSET)));
198+
GO
199+
~~ROW COUNT: 4~~
200+
201+
202+
CREATE TABLE datename_tzoffset_different_test_scenarios (
203+
test_description VARCHAR(100),
204+
test_input VARCHAR(100),
205+
test_result TEXT
206+
);
207+
GO
208+
209+
INSERT INTO datename_tzoffset_different_test_scenarios (test_description, test_input, test_result)
210+
VALUES ('DATE type',
211+
'datename(TZOFFSET, CAST(''2025-06-03 14:30:15 +01:30'' AS DATE))',
212+
datename(TZOFFSET, CAST('2025-06-03 14:30:15 +01:30' AS DATE))),
213+
('TIME type',
214+
'datename(TZOFFSET, CAST(''14:30:15'' AS TIME))',
215+
datename(TZOFFSET, CAST('14:30:15' AS TIME))),
216+
('DATETIME type',
217+
'datename(TZOFFSET, CAST(''2025-06-03 14:30:15'' AS DATETIME))',
218+
datename(TZOFFSET, CAST('2025-06-03 14:30:15' AS DATETIME))),
219+
('SMALLDATETIME type',
220+
'datename(TZOFFSET, CAST(''2025-06-03 14:30:15'' AS SMALLDATETIME))',
221+
datename(TZOFFSET, CAST('2025-06-03 14:30:15' AS SMALLDATETIME)));
222+
GO
223+
~~ROW COUNT: 4~~
224+
225+
226+
INSERT INTO datename_tzoffset_different_test_scenarios (test_description, test_input, test_result)
227+
VALUES ('DATETIME2 type',
228+
'datename(TZOFFSET, CAST(''2025-06-03 14:30:15'' AS DATETIME2))',
229+
datename(TZOFFSET, CAST('2025-06-03 14:30:15' AS DATETIME2))),
230+
('DATETIMEOFFSET type',
231+
'datename(TZOFFSET, CAST(''2025-06-03 14:30:15'' AS DATETIMEOFFSET))',
232+
datename(TZOFFSET, CAST('2025-06-03 14:30:15' AS DATETIMEOFFSET)));
233+
GO
234+
~~ROW COUNT: 2~~
235+
236+
237+
INSERT INTO datename_tzoffset_different_test_scenarios (test_description, test_input, test_result)
238+
VALUES ('out of range positive',
239+
'DATENAME(TZOFFSET, CAST(''2025-06-03 14:30:15 +14:01'' AS DATETIMEOFFSET))',
240+
DATENAME(TZOFFSET, CAST('2025-06-03 14:30:15 +14:01' AS DATETIMEOFFSET))),
241+
('out of range negative',
242+
'DATENAME(TZOFFSET, ''2025-06-03 14:30:15 -14:01'')',
243+
DATENAME(TZOFFSET, '2025-06-03 14:30:15 -14:01'));
244+
GO
245+
~~ROW COUNT: 2~~
246+
247+
248+
INSERT INTO datename_tzoffset_different_test_scenarios (test_description, test_input, test_result)
249+
VALUES ('boundary max value',
250+
'DATENAME(TZOFFSET, CAST(''2025-06-03 14:30:15 +14:00'' AS DATETIMEOFFSET))',
251+
DATENAME(TZOFFSET, CAST('2025-06-03 14:30:15 +14:00' AS DATETIMEOFFSET))),
252+
('boundary min value',
253+
'DATENAME(TZOFFSET, CAST(''2025-06-03 14:30:15 -14:00'' AS DATETIMEOFFSET))',
254+
DATENAME(TZOFFSET, CAST('2025-06-03 14:30:15 -14:00' AS DATETIMEOFFSET)));
255+
GO
256+
~~ROW COUNT: 2~~
257+

0 commit comments

Comments
 (0)