1
# This script tests our own time zone support functions
5
drop table if exists t1, t2;
6
drop function if exists f1;
11
# Let us first check +HH:MM style timezones
13
create table t1 (ts timestamp);
15
set time_zone='+00:00';
16
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
17
insert into t1 (ts) values ('2003-03-30 02:30:00');
19
set time_zone='+10:30';
20
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
21
insert into t1 (ts) values ('2003-03-30 02:30:00');
23
set time_zone='-10:00';
24
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
25
insert into t1 (ts) values ('2003-03-30 02:30:00');
27
# Here we will get different results
34
# Let us try DB specified time zones
36
select Name from mysql.time_zone_name where Name in
37
('UTC','Universal','MET','Europe/Moscow','leap/Europe/Moscow');
39
create table t1 (i int, ts timestamp);
43
# We check common date time value and non existent or ambiguios values
44
# Normal value without DST
45
insert into t1 (i, ts) values
46
(unix_timestamp('2003-03-01 00:00:00'),'2003-03-01 00:00:00');
47
# Values around and in spring time-gap
48
insert into t1 (i, ts) values
49
(unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'),
50
(unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'),
51
(unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00');
52
# Values around and in spring time-gap
53
insert into t1 (i, ts) values
54
(unix_timestamp(20030330015959),20030330015959),
55
(unix_timestamp(20030330023000),20030330023000),
56
(unix_timestamp(20030330030000),20030330030000);
57
# Normal value with DST
58
insert into t1 (i, ts) values
59
(unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00');
60
# Ambiguos values (also check for determenism)
61
insert into t1 (i, ts) values
62
(unix_timestamp('2003-10-26 01:00:00'),'2003-10-26 01:00:00'),
63
(unix_timestamp('2003-10-26 02:00:00'),'2003-10-26 02:00:00'),
64
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59'),
65
(unix_timestamp('2003-10-26 04:00:00'),'2003-10-26 04:00:00'),
66
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59');
74
# Simple check for 'Europe/Moscow' time zone just for showing that it works
75
set time_zone='Europe/Moscow';
76
insert into t1 (i, ts) values
77
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
78
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
79
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
80
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
86
# Check for time zone with leap seconds
87
# Values in ts column must be the same but values in i column should
88
# differ from corresponding values for Europe/Moscow a bit.
90
set time_zone='leap/Europe/Moscow';
91
insert into t1 (i, ts) values
92
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
93
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
94
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
95
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
98
# Let us test leap jump
99
insert into t1 (i, ts) values
100
(unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'),
101
(unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00');
103
# Additional 60ieth second!
104
select from_unixtime(362793609);
110
# Let us test range for TIMESTAMP
112
create table t1 (ts timestamp);
114
insert into t1 values ('0000-00-00 00:00:00'),('1969-12-31 23:59:59'),
115
('1970-01-01 00:00:00'),('1970-01-01 00:00:01'),
116
('2038-01-19 03:14:07'),('2038-01-19 03:14:08');
119
# MET time zone has range shifted by one hour
121
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 00:30:00'),
122
('1970-01-01 01:00:00'),('1970-01-01 01:00:01'),
123
('2038-01-19 04:14:07'),('2038-01-19 04:14:08');
126
# same for +01:30 time zone
127
set time_zone='+01:30';
128
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 01:00:00'),
129
('1970-01-01 01:30:00'),('1970-01-01 01:30:01'),
130
('2038-01-19 04:44:07'),('2038-01-19 04:44:08');
137
# Test of show variables
139
show variables like 'time_zone';
140
set time_zone = default;
141
show variables like 'time_zone';
145
# Let us try some invalid time zone specifications
150
set time_zone= '0:0';
152
set time_zone= '-20:00';
154
set time_zone= '+20:00';
156
set time_zone= 'Some/Unknown/Time/Zone';
159
# Let us check that aliases for time zones work and they are
161
select convert_tz(now(),'UTC', 'Universal') = now();
162
select convert_tz(now(),'utc', 'UTC') = now();
166
# Let us test CONVERT_TZ function (may be func_time.test is better place).
168
select convert_tz('1917-11-07 12:00:00', 'MET', 'UTC');
169
select convert_tz('1970-01-01 01:00:00', 'MET', 'UTC');
170
select convert_tz('1970-01-01 01:00:01', 'MET', 'UTC');
171
select convert_tz('2003-03-01 00:00:00', 'MET', 'UTC');
172
select convert_tz('2003-03-30 01:59:59', 'MET', 'UTC');
173
select convert_tz('2003-03-30 02:30:00', 'MET', 'UTC');
174
select convert_tz('2003-03-30 03:00:00', 'MET', 'UTC');
175
select convert_tz('2003-05-01 00:00:00', 'MET', 'UTC');
176
select convert_tz('2003-10-26 01:00:00', 'MET', 'UTC');
177
select convert_tz('2003-10-26 02:00:00', 'MET', 'UTC');
178
select convert_tz('2003-10-26 02:59:59', 'MET', 'UTC');
179
select convert_tz('2003-10-26 04:00:00', 'MET', 'UTC');
180
select convert_tz('2038-01-19 04:14:07', 'MET', 'UTC');
181
select convert_tz('2038-01-19 04:14:08', 'MET', 'UTC');
182
select convert_tz('2103-01-01 04:00:00', 'MET', 'UTC');
184
# Let us test variable time zone argument
185
create table t1 (tz varchar(3));
186
insert into t1 (tz) values ('MET'), ('UTC');
187
select tz, convert_tz('2003-12-31 00:00:00',tz,'UTC'), convert_tz('2003-12-31 00:00:00','UTC',tz) from t1 order by tz;
190
# Parameters to CONVERT_TZ() what should give NULL
191
select convert_tz('2003-12-31 04:00:00', NULL, 'UTC');
192
select convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC');
193
select convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone');
194
select convert_tz('2003-12-31 04:00:00', 'MET', NULL);
195
select convert_tz( NULL, 'MET', 'UTC');
198
# Test for bug #4508 "CONVERT_TZ() function with new time zone as param
199
# crashes server." (Was caused by improperly worked mechanism of time zone
200
# dynamical loading).
202
create table t1 (ts timestamp);
203
set timestamp=1000000000;
204
insert into t1 (ts) values (now());
205
select convert_tz(ts, @@time_zone, 'Japan') from t1;
209
# Test for bug #7705 "CONVERT_TZ() crashes with subquery/WHERE on index
210
# column". Queries in which one of time zone arguments of CONVERT_TZ() is
211
# determined as constant only at val() stage (not at fix_fields() stage),
212
# should not crash server.
214
select convert_tz('2005-01-14 17:00:00', 'UTC', custTimeZone) from (select 'UTC' as custTimeZone) as tmp;
217
# Test for bug #7899 "CREATE TABLE .. SELECT .. and CONVERT_TZ() function
218
# does not work well together". The following statement should return only
219
# one NULL row and not result of full join.
221
create table t1 select convert_tz(NULL, NULL, NULL);
228
# Test for bug #11081 "Using a CONVERT_TZ function in a stored function
231
SET GLOBAL log_bin_trust_function_creators = 1;
233
create table t1 (ldt datetime, udt datetime);
234
create function f1(i datetime) returns datetime
235
return convert_tz(i, 'UTC', 'Europe/Moscow');
236
create trigger t1_bi before insert on t1 for each row
237
set new.udt:= convert_tz(new.ldt, 'Europe/Moscow', 'UTC');
238
# This should work without errors
239
insert into t1 (ldt) values ('2006-04-19 16:30:00');
241
# This should work without errors as well
242
select ldt, f1(udt) as ldt2 from t1;
246
SET GLOBAL log_bin_trust_function_creators = 0;
252
# BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
253
# BUG#19339: CONVERT_TZ(): overly aggressive in locking time_zone_name
257
DROP TABLE IF EXISTS t1;
260
CREATE TABLE t1 (t TIMESTAMP);
261
INSERT INTO t1 VALUES (NULL), (NULL);
263
LOCK TABLES t1 WRITE;
265
# The following two queries should not return error that time zone
266
# tables aren't locked. We use IS NULL below to supress timestamp
268
SELECT CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow') IS NULL;
269
UPDATE t1 SET t = CONVERT_TZ(t, 'UTC', 'Europe/Moscow');
276
--echo End of 5.1 tests