~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/date_formats.test

  • Committer: Jay Pipes
  • Date: 2009-01-30 04:01:12 UTC
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090130040112-svbn774guj98pwi4
To remain in compatibility with MySQL, added ability to interpret
decimal arguments as datetime strings for temporal functions.

Fixed YEAR(), MONTH(), DAYOFMONTH(), DAYOFYEAR(), HOUR(), MINUTE(), SECOND(), and MICROSECOND()
to accept decimal parameters and interpret them the same way as MySQL.

Fixed an issue with the TemporalFormat::matches() method which was 
incorrectly assuming all microsecond arguments were specified as 6 digits.
Added power of 10 multiplier to usecond calculation. This fixes issues with
failures in type_date and func_sapdb test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
drop table if exists t1;
7
7
--enable_warnings
8
8
 
 
9
--replace_result ROW <format> STATEMENT <format> MIXED <format>
 
10
SHOW GLOBAL VARIABLES LIKE "%e_format";
 
11
--replace_result ROW <format> STATEMENT <format> MIXED <format>
 
12
SHOW SESSION VARIABLES LIKE "%e_format";
 
13
 
 
14
#
 
15
# Test setting a lot of different formats to see which formats are accepted and
 
16
# which aren't
 
17
#
 
18
 
 
19
SET time_format='%H%i%s';
 
20
SET time_format='%H:%i:%s.%f';
 
21
SET time_format='%h-%i-%s.%f%p';
 
22
SET time_format='%h:%i:%s.%f %p';
 
23
SET time_format='%h:%i:%s%p';
 
24
 
 
25
SET date_format='%Y%m%d';
 
26
SET date_format='%Y.%m.%d';
 
27
SET date_format='%d.%m.%Y';
 
28
SET date_format='%m-%d-%Y';
 
29
 
 
30
set datetime_format= '%Y%m%d%H%i%s';
 
31
set datetime_format= '%Y-%m-%d %H:%i:%s';
 
32
set datetime_format= '%m-%d-%y %H:%i:%s.%f';
 
33
set datetime_format= '%d-%m-%Y %h:%i:%s%p';
 
34
set datetime_format= '%H:%i:%s %Y-%m-%d';
 
35
set datetime_format= '%H:%i:%s.%f %m-%d-%Y';
 
36
set datetime_format= '%h:%i:%s %p %Y-%m-%d';
 
37
set datetime_format= '%h:%i:%s.%f %p %Y-%m-%d';
 
38
 
 
39
--replace_result ROW <format> STATEMENT <format> MIXED <format>
 
40
SHOW SESSION VARIABLES LIKE "%e_format";
 
41
 
 
42
--error 1231
 
43
SET time_format='%h:%i:%s';
 
44
--error 1231
 
45
SET time_format='%H %i:%s';
 
46
--error 1231
 
47
SET time_format='%H::%i:%s';
 
48
--error 1231
 
49
SET time_format='%H:%i:%s%f';
 
50
--error 1231
 
51
SET time_format='%H:%i.%f:%s';
 
52
--error 1231
 
53
SET time_format='%H:%i:%s%p';
 
54
--error 1231
 
55
SET time_format='%h:%i:%s.%f %p %Y-%m-%d';
 
56
--error 1231
 
57
SET time_format='%H%i%s.%f';
 
58
--error 1231
 
59
SET time_format='%H:%i-%s.%f';
 
60
--error 1231
 
61
SET date_format='%d.%m.%d';
 
62
--error 1231
 
63
SET datetime_format='%h.%m.%y %d.%i.%s';
 
64
--error 1231
 
65
set datetime_format= '%H:%i:%s.%f %p %Y-%m-%d';
 
66
 
 
67
#
 
68
# Test GLOBAL values
 
69
 
 
70
set GLOBAL datetime_format= '%H:%i:%s %Y-%m-%d';
 
71
SET SESSION datetime_format=default;
 
72
select @@global.datetime_format, @@session.datetime_format;
 
73
SET GLOBAL datetime_format=default;
 
74
SET SESSION datetime_format=default;
 
75
select @@global.datetime_format, @@session.datetime_format;
 
76
 
 
77
SET GLOBAL date_format=default;
 
78
SET GLOBAL time_format=default;
 
79
SET GLOBAL datetime_format=default;
 
80
SET time_format=default;
 
81
SET date_format=default;
 
82
SET datetime_format=default;
 
83
 
9
84
#
10
85
# The following tests will work only when we at some point will enable
11
86
# dynamic changing of formats
42
117
# SET time_format='%i:%s:%H';
43
118
# select cast(str_to_date('15-01-2001 12:59:59', '%d-%m-%Y %H:%i:%S') as TIME);
44
119
 
45
 
explain extended select makedate(1997,1), microsecond("1997-12-31 23:59:59.000001");
 
120
#
 
121
# Test of str_to_date
 
122
#
 
123
 
 
124
# PS doesn't support fraction of a seconds
 
125
--disable_ps_protocol
 
126
select str_to_date(concat('15-01-2001',' 2:59:58.999'),
 
127
                   concat('%d-%m-%Y',' ','%H:%i:%s.%f'));
 
128
select STR_TO_DATE('2004.12.12 22.30.61','%Y.%m.%d %T');
 
129
--enable_ps_protocol
 
130
 
 
131
create table t1 (date char(30), format char(30) not null);
 
132
insert into t1 values
 
133
('2003-01-02 10:11:12', '%Y-%m-%d %H:%i:%S'),
 
134
('03-01-02 8:11:2.123456', '%y-%m-%d %H:%i:%S.%#'),
 
135
('0003-01-02 8:11:2.123456', '%Y-%m-%d %H:%i:%S.%#'),
 
136
('03-01-02 8:11:2.123456',   '%Y-%m-%d %H:%i:%S.%#'),
 
137
('2003-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p'),
 
138
('2003-01-02 01:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f%p'),
 
139
('2003-01-02 02:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f %p'),
 
140
('2003-01-02 12:11:12.12345 am', '%Y-%m-%d %h:%i:%S.%f%p'),
 
141
('2003-01-02 11:11:12Pm', '%Y-%m-%d %h:%i:%S%p'),
 
142
('10:20:10', '%H:%i:%s'),
 
143
('10:20:10', '%h:%i:%s.%f'),
 
144
('10:20:10', '%T'),
 
145
('10:20:10AM', '%h:%i:%s%p'),
 
146
('10:20:10AM', '%r'),
 
147
('10:20:10.44AM', '%h:%i:%s.%f%p'),
 
148
('15-01-2001 12:59:58', '%d-%m-%Y %H:%i:%S'),
 
149
('15 September 2001', '%d %M %Y'),
 
150
('15 SEPTEMB 2001', '%d %M %Y'),
 
151
('15 MAY 2001', '%d %b %Y'),
 
152
('15th May 2001', '%D %b %Y'),
 
153
('Sunday 15 MAY 2001', '%W %d %b %Y'),
 
154
('Sund 15 MAY 2001', '%W %d %b %Y'),
 
155
('Tuesday 00 2002', '%W %U %Y'),
 
156
('Thursday 53 1998', '%W %u %Y'),
 
157
('Sunday 01 2001', '%W %v %x'),
 
158
('Tuesday 52 2001', '%W %V %X'),
 
159
('060 2004', '%j %Y'),
 
160
('4 53 1998', '%w %u %Y'),
 
161
('15-01-2001', '%d-%m-%Y %H:%i:%S'),
 
162
('15-01-20', '%d-%m-%y'),
 
163
('15-2001-1', '%d-%Y-%c');
 
164
 
 
165
# PS doesn't support fractional seconds
 
166
--disable_ps_protocol
 
167
select date,format,str_to_date(date, format) as str_to_date from t1;
 
168
# Use as a string
 
169
select date,format,concat('',str_to_date(date, format)) as con from t1;
 
170
# Use as datetime
 
171
select date,format,cast(str_to_date(date, format) as datetime) as datetime from t1;
 
172
select date,format,DATE(str_to_date(date, format)) as date2 from t1;
 
173
select date,format,TIME(str_to_date(date, format)) as time from t1;
 
174
select date,format,concat(TIME(str_to_date(date, format))) as time2 from t1;
 
175
# Test small bug in %f handling
 
176
select concat('',str_to_date('8:11:2.123456 03-01-02','%H:%i:%S.%f %y-%m-%d'));
 
177
 
 
178
# Test wrong dates or converion specifiers
 
179
 
 
180
truncate table t1;
 
181
insert into t1 values
 
182
('2003-01-02 10:11:12 PM', '%Y-%m-%d %H:%i:%S %p'),
 
183
('2003-01-02 10:11:12.123456', '%Y-%m-%d %h:%i:%S %p'),
 
184
('2003-01-02 10:11:12AM', '%Y-%m-%d %h:%i:%S.%f %p'),
 
185
('2003-01-02 10:11:12AN', '%Y-%m-%d %h:%i:%S%p'),
 
186
('2003-01-02 10:11:12 PM', '%y-%m-%d %H:%i:%S %p'),
 
187
('10:20:10AM', '%H:%i:%s%p'),
 
188
('15 Septembei 2001', '%d %M %Y'),
 
189
('15 Ju 2001', '%d %M %Y'),
 
190
('Sund 15 MA', '%W %d %b %Y'),
 
191
('Thursdai 12 1998', '%W %u %Y'),
 
192
('Sunday 01 2001', '%W %v %X'),
 
193
('Tuesday 52 2001', '%W %V %x'),
 
194
('Tuesday 52 2001', '%W %V %Y'),
 
195
('Tuesday 52 2001', '%W %u %x'),
 
196
('7 53 1998', '%w %u %Y'),
 
197
(NULL, get_format(DATE,'USA'));
 
198
select date,format,str_to_date(date, format) as str_to_date from t1;
 
199
select date,format,concat(str_to_date(date, format),'') as con from t1;
 
200
 
 
201
# Test 'maybe' date formats and 'strange but correct' results
 
202
 
 
203
truncate table t1;
 
204
insert into t1 values
 
205
('10:20:10AM', '%h:%i:%s'),
 
206
('2003-01-02 10:11:12', '%Y-%m-%d %h:%i:%S'),
 
207
('03-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p');
 
208
 
 
209
select date,format,str_to_date(date, format) as str_to_date from t1;
 
210
select date,format,concat(str_to_date(date, format),'') as con from t1;
 
211
 
 
212
drop table t1;
 
213
--enable_ps_protocol
 
214
 
 
215
#
 
216
# Test of get_format
 
217
#
 
218
 
 
219
select get_format(DATE, 'USA') as a;
 
220
select get_format(TIME, 'internal') as a;
 
221
select get_format(DATETIME, 'eur') as a;
 
222
select get_format(TIMESTAMP, 'eur') as a;
 
223
select get_format(DATE, 'TEST') as a;
 
224
select str_to_date('15-01-2001 12:59:59', GET_FORMAT(DATE,'USA'));
 
225
 
 
226
explain extended select makedate(1997,1), addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM"),cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME), maketime(23,11,12),microsecond("1997-12-31 23:59:59.000001");
46
227
 
47
228
#
48
229
# Test of date_format()
53
234
select date_format(d,"%d") from t1 order by 1;
54
235
drop table t1;
55
236
 
 
237
# PS doesn't support fractional seconds
 
238
--disable_ps_protocol
 
239
select str_to_date("2003-....01ABCD-02 10:11:12.0012", "%Y-%.%m%@-%d %H:%i:%S.%f") as a;
 
240
 
 
241
 
 
242
create table t1 select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
 
243
                        str_to_date("10:11:12.0012", "%H:%i:%S.%f") as f2,
 
244
                        str_to_date("2003-01-02", "%Y-%m-%d") as f3,
 
245
                        str_to_date("02", "%d") as f4, str_to_date("02 10", "%d %H") as f5;
 
246
describe t1;
 
247
select * from t1;
 
248
drop table t1;
 
249
 
 
250
create table t1 select "02 10" as a, "%d %H" as b;
 
251
select str_to_date(a,b) from t1;
 
252
create table t2 select str_to_date(a,b) from t1;
 
253
describe t2;
 
254
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
 
255
       str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S") as f2,
 
256
       str_to_date("2003-01-02", "%Y-%m-%d") as f3,
 
257
       str_to_date("02 10:11:12", "%d %H:%i:%S.%f") as f4,
 
258
       str_to_date("02 10:11:12", "%d %H:%i:%S") as f5,
 
259
       str_to_date("02 10", "%d %f") as f6;
 
260
drop table t1, t2;
 
261
--error 1686 # These are bad datetimes...
 
262
select str_to_date("2003-01-02 10:11:12.0012ABCD", "%Y-%m-%d %H:%i:%S.%f") as f1,
 
263
       addtime("-01:01:01.01 GGG", "-23:59:59.1") as f2,
 
264
       microsecond("1997-12-31 23:59:59.01XXXX") as f3;
 
265
 
 
266
select str_to_date("2003-04-05  g", "%Y-%m-%d") as f1,
 
267
       str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2;
 
268
--enable_ps_protocol
 
269
 
56
270
#
57
271
# Bug #14016 
58
272
#
63
277
drop table t1;
64
278
 
65
279
#
 
280
# Bug #15828
 
281
#
 
282
select str_to_date( 1, NULL );
 
283
select str_to_date( NULL, 1 );
 
284
select str_to_date( 1, IF(1=1,NULL,NULL) );
 
285
 
 
286
#
66
287
# Bug#11326
67
288
# TIME_FORMAT using "%r" returns wrong hour using 24:00:00 in TIME column
68
289
#
97
318
#
98
319
SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896);
99
320
 
 
321
#
 
322
# Bug #22029: str_to_date returning NULL
 
323
#
 
324
 
 
325
select str_to_date('04 /30/2004', '%m /%d/%Y');
 
326
select str_to_date('04/30 /2004', '%m /%d /%Y');
 
327
select str_to_date('04/30/2004 ', '%m/%d/%Y ');
 
328
 
100
329
--echo "End of 4.1 tests"