dolt icon indicating copy to clipboard operation
dolt copied to clipboard

Date and time functions should check for overflow/underflow

Open fulghum opened this issue 1 year ago • 1 comments

Date functions such as subdate, date_sub, and date_add should check for overflow/underflow conditions when creating new date objects, otherwise we can return incorrect values. MySQL detects this and returns NULL in these cases.

MySQL:

select date_add("4444-01-01", interval 5400000 day);
+----------------------------------------------+
| date_add("4444-01-01", interval 5400000 day) |
+----------------------------------------------+
| NULL                                         |
+----------------------------------------------+

select subdate('2008-01-02', 12e10);
+------------------------------+
| subdate('2008-01-02', 12e10) |
+------------------------------+
| NULL                         |
+------------------------------+

Dolt:

select date_add("4444-01-01", interval 5400000 day);
+----------------------------------------------+
| date_add("4444-01-01", interval 5400000 day) |
+----------------------------------------------+
| 4614-11-06 10:35:57.261209                   |
+----------------------------------------------+

select date_sub('2008-01-02', interval 12e10 day);
+--------------------------------------------+
| date_sub('2008-01-02', interval 12e10 day) |
+--------------------------------------------+
| 1770-07-19 03:54:13.485772                 |
+--------------------------------------------+

fulghum avatar Jan 11 '24 17:01 fulghum

Additionally, certain intervals are not NULL in MySQL, but cause overflows in time.Duration dolt.

MySQL:

mysql> select date_add("2008-01-02", interval 1000000 day);
+----------------------------------------------+
| date_add("2008-01-02", interval 1000000 day) |
+----------------------------------------------+
| 4745-11-29                                   |
+----------------------------------------------+
1 row in set (0.0004 sec)

Dolt:

tmp/main> select date_add("2008-01-02", interval 1000000 day);
+----------------------------------------------+
| date_add("2008-01-02", interval 1000000 day) |
+----------------------------------------------+
| 1823-02-21 02:07:11.452241                   |
+----------------------------------------------+
1 row in set (0.00 sec)

jycor avatar Apr 15 '24 21:04 jycor