Commit af8cbbae authored by unknown's avatar unknown

Fix '%h', '%I', and '%l' format specifiers in TIME_FORMAT()

to handle large time values as documented. (Bug #10590)


mysql-test/r/func_time.result:
  Add new results
mysql-test/t/func_time.test:
  Add new regression test
sql/item_timefunc.cc:
  Fix handling of '%h', '%I', and '%l' format specifiers
  for TIME_FORMAT() to handle large time values correctly.
parent 9b07cafe
...@@ -688,3 +688,6 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -688,3 +688,6 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1003 select timestamp_diff(WEEK,_latin1'2001-02-01',_latin1'2001-05-01') AS `a1`,timestamp_diff(SECOND_FRAC,_latin1'2001-02-01 12:59:59.120000',_latin1'2001-05-01 12:58:58.119999') AS `a2` Note 1003 select timestamp_diff(WEEK,_latin1'2001-02-01',_latin1'2001-05-01') AS `a1`,timestamp_diff(SECOND_FRAC,_latin1'2001-02-01 12:59:59.120000',_latin1'2001-05-01 12:58:58.119999') AS `a2`
select time_format('100:00:00', '%H %k %h %I %l');
time_format('100:00:00', '%H %k %h %I %l')
100 100 04 04 4
...@@ -336,3 +336,9 @@ DROP TABLE t1; ...@@ -336,3 +336,9 @@ DROP TABLE t1;
explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1,
timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2;
#
# Bug #10590: %h, %I, and %l format specifies should all return results in
# the 0-11 range
#
select time_format('100:00:00', '%H %k %h %I %l');
...@@ -497,7 +497,6 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, ...@@ -497,7 +497,6 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time,
timestamp_type type, String *str) timestamp_type type, String *str)
{ {
char intbuff[15]; char intbuff[15];
uint days_i;
uint hours_i; uint hours_i;
uint weekday; uint weekday;
ulong length; ulong length;
...@@ -600,8 +599,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, ...@@ -600,8 +599,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time,
break; break;
case 'h': case 'h':
case 'I': case 'I':
days_i= l_time->hour/24; hours_i= (l_time->hour%24 + 11)%12+1;
hours_i= (l_time->hour%24 + 11)%12+1 + 24*days_i;
length= int10_to_str(hours_i, intbuff, 10) - intbuff; length= int10_to_str(hours_i, intbuff, 10) - intbuff;
str->append_with_prefill(intbuff, length, 2, '0'); str->append_with_prefill(intbuff, length, 2, '0');
break; break;
...@@ -622,8 +620,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time, ...@@ -622,8 +620,7 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time,
str->append_with_prefill(intbuff, length, 1, '0'); str->append_with_prefill(intbuff, length, 1, '0');
break; break;
case 'l': case 'l':
days_i= l_time->hour/24; hours_i= (l_time->hour%24 + 11)%12+1;
hours_i= (l_time->hour%24 + 11)%12+1 + 24*days_i;
length= int10_to_str(hours_i, intbuff, 10) - intbuff; length= int10_to_str(hours_i, intbuff, 10) - intbuff;
str->append_with_prefill(intbuff, length, 1, '0'); str->append_with_prefill(intbuff, length, 1, '0');
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment