Skip to content

Commit 43e4522

Browse files
author
Alexander Barkov
committed
MDEV-8205 timediff returns null when comparing decimal time to time string value
1 parent f69f3db commit 43e4522

File tree

3 files changed

+85
-10
lines changed

3 files changed

+85
-10
lines changed

mysql-test/r/func_time.result

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,3 +2701,45 @@ id date1 date2 DATE_ADD(a.date1,INTERVAL -10 DAY) TO_DAYS(a.date1)-10
27012701
17 NULL NULL NULL NULL
27022702
18 2010-10-13 2010-10-03 2010-10-03 734413
27032703
DROP TABLE t1;
2704+
#
2705+
# Start of 10.0 tests
2706+
#
2707+
#
2708+
# MDEV-8205 timediff returns null when comparing decimal time to time string value
2709+
#
2710+
SELECT
2711+
TIMEDIFF('2014-01-01 00:00:00' , '2014-01-01 01:00:00' ) AS str_str,
2712+
TIMEDIFF('2014-01-01 00:00:00' , 20140101010000.000 ) AS str_dec,
2713+
TIMEDIFF(20140101000000.000 , 20140101010000.000 ) AS dec_dec,
2714+
TIMEDIFF(20140101000000.000 , '2014-01-01 01:00:00' ) AS dec_str;
2715+
str_str str_dec dec_dec dec_str
2716+
-01:00:00 -01:00:00.000 -01:00:00.000 -01:00:00.000
2717+
SELECT
2718+
TIMEDIFF('2014-01-01 00:00:00' , '2014-01-02 01:00:00' ) AS str_str,
2719+
TIMEDIFF('2014-01-01 00:00:00' , 20140102010000.000 ) AS str_dec,
2720+
TIMEDIFF(20140101000000.000 , 20140102010000.000 ) AS dec_dec,
2721+
TIMEDIFF(20140101000000.000 , '2014-01-02 01:00:00' ) AS dec_str;
2722+
str_str str_dec dec_dec dec_str
2723+
-25:00:00 -25:00:00.000 -25:00:00.000 -25:00:00.000
2724+
SELECT
2725+
TIMEDIFF('2014-01-01 00:00:00' , '2014-02-02 01:00:00' ) AS str_str,
2726+
TIMEDIFF('2014-01-01 00:00:00' , 20140202010000.000 ) AS str_dec,
2727+
TIMEDIFF(20140101000000.000 , 20140202010000.000 ) AS dec_dec,
2728+
TIMEDIFF(20140101000000.000 , '2014-02-02 01:00:00' ) AS dec_str;
2729+
str_str str_dec dec_dec dec_str
2730+
-769:00:00 -769:00:00.000 -769:00:00.000 -769:00:00.000
2731+
SELECT
2732+
TIMEDIFF('2014-01-01 00:00:00' , '2014-03-02 01:00:00' ) AS str_str,
2733+
TIMEDIFF('2014-01-01 00:00:00' , 20140302010000.000 ) AS str_dec,
2734+
TIMEDIFF(20140101000000.000 , 20140302010000.000 ) AS dec_dec,
2735+
TIMEDIFF(20140101000000.000 , '2014-03-02 01:00:00' ) AS dec_str;
2736+
str_str str_dec dec_dec dec_str
2737+
-838:59:59 -838:59:59.999 -838:59:59.999 -838:59:59.999
2738+
Warnings:
2739+
Warning 1292 Truncated incorrect time value: '-1441:00:00'
2740+
Warning 1292 Truncated incorrect time value: '-1441:00:00'
2741+
Warning 1292 Truncated incorrect time value: '-1441:00:00'
2742+
Warning 1292 Truncated incorrect time value: '-1441:00:00'
2743+
#
2744+
# End of 10.0 tests
2745+
#

mysql-test/t/func_time.test

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,3 +1649,44 @@ INSERT INTO t1 VALUES (17, NULL);
16491649
INSERT INTO t1 VALUES (18, '2010-10-13');
16501650
SELECT a.id,a.date1,FROM_DAYS(TO_DAYS(a.date1)-10) as date2, DATE_ADD(a.date1,INTERVAL -10 DAY),TO_DAYS(a.date1)-10 FROM t1 a ORDER BY a.id;
16511651
DROP TABLE t1;
1652+
1653+
1654+
--echo #
1655+
--echo # Start of 10.0 tests
1656+
--echo #
1657+
1658+
--echo #
1659+
--echo # MDEV-8205 timediff returns null when comparing decimal time to time string value
1660+
--echo #
1661+
1662+
# 1h difference
1663+
SELECT
1664+
TIMEDIFF('2014-01-01 00:00:00' , '2014-01-01 01:00:00' ) AS str_str,
1665+
TIMEDIFF('2014-01-01 00:00:00' , 20140101010000.000 ) AS str_dec,
1666+
TIMEDIFF(20140101000000.000 , 20140101010000.000 ) AS dec_dec,
1667+
TIMEDIFF(20140101000000.000 , '2014-01-01 01:00:00' ) AS dec_str;
1668+
1669+
# 1D1h difference
1670+
SELECT
1671+
TIMEDIFF('2014-01-01 00:00:00' , '2014-01-02 01:00:00' ) AS str_str,
1672+
TIMEDIFF('2014-01-01 00:00:00' , 20140102010000.000 ) AS str_dec,
1673+
TIMEDIFF(20140101000000.000 , 20140102010000.000 ) AS dec_dec,
1674+
TIMEDIFF(20140101000000.000 , '2014-01-02 01:00:00' ) AS dec_str;
1675+
1676+
# 1M1D1h difference
1677+
SELECT
1678+
TIMEDIFF('2014-01-01 00:00:00' , '2014-02-02 01:00:00' ) AS str_str,
1679+
TIMEDIFF('2014-01-01 00:00:00' , 20140202010000.000 ) AS str_dec,
1680+
TIMEDIFF(20140101000000.000 , 20140202010000.000 ) AS dec_dec,
1681+
TIMEDIFF(20140101000000.000 , '2014-02-02 01:00:00' ) AS dec_str;
1682+
1683+
# 2M1D1h difference
1684+
SELECT
1685+
TIMEDIFF('2014-01-01 00:00:00' , '2014-03-02 01:00:00' ) AS str_str,
1686+
TIMEDIFF('2014-01-01 00:00:00' , 20140302010000.000 ) AS str_dec,
1687+
TIMEDIFF(20140101000000.000 , 20140302010000.000 ) AS dec_dec,
1688+
TIMEDIFF(20140101000000.000 , '2014-03-02 01:00:00' ) AS dec_str;
1689+
1690+
--echo #
1691+
--echo # End of 10.0 tests
1692+
--echo #

sql-common/my_time.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,16 +1314,8 @@ int number_to_time(my_bool neg, ulonglong nr, ulong sec_part,
13141314
MYSQL_TIME *ltime, int *was_cut)
13151315
{
13161316
if (nr > 9999999 && nr < 99991231235959ULL && neg == 0)
1317-
{
1318-
if (number_to_datetime(nr, sec_part, ltime,
1319-
TIME_INVALID_DATES, was_cut) < 0)
1320-
return -1;
1321-
1322-
ltime->year= ltime->month= ltime->day= 0;
1323-
ltime->time_type= MYSQL_TIMESTAMP_TIME;
1324-
*was_cut= MYSQL_TIME_NOTE_TRUNCATED;
1325-
return 0;
1326-
}
1317+
return number_to_datetime(nr, sec_part, ltime,
1318+
TIME_INVALID_DATES, was_cut) < 0 ? -1 : 0;
13271319

13281320
*was_cut= 0;
13291321
ltime->year= ltime->month= ltime->day= 0;

0 commit comments

Comments
 (0)