summaryrefslogtreecommitdiff
path: root/sql/item_timefunc.cc
diff options
context:
space:
mode:
authorunknown <dlenev@brandersnatch.localdomain>2005-01-12 12:18:36 +0300
committerunknown <dlenev@brandersnatch.localdomain>2005-01-12 12:18:36 +0300
commitd853e732b9f598671283064fef6d11ea9db1d8ca (patch)
tree07b776f621873f4093ad754c602dd1f08262a197 /sql/item_timefunc.cc
parent39ee25b3742188026dcc0bcee60951668a4a2275 (diff)
downloadmariadb-git-d853e732b9f598671283064fef6d11ea9db1d8ca.tar.gz
Fix for bug #7586 "TIMEDIFF for sec+microsec not working properly".
mysql-test/r/func_sapdb.result: Added test for bug #7586 "TIMEDIFF for sec+microsec not working properly". Corrected previously wrong results of couple other statements. mysql-test/t/func_sapdb.test: Added test for bug #7586 "TIMEDIFF for sec+microsec not working properly". sql/item_timefunc.cc: Item_func_timediff::val_str(): Use simplier and less error-prone implementation. Now we are counting difference between time values in microseconds and convert it to time value (instead of using seconds and taking difference in "second_part"s into account).
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r--sql/item_timefunc.cc30
1 files changed, 10 insertions, 20 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 0d652a431cb..f9c9d1f013d 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2432,8 +2432,7 @@ void Item_func_add_time::print(String *str)
String *Item_func_timediff::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- longlong seconds;
- long microseconds;
+ longlong microseconds;
long days;
int l_sign= 1;
TIME l_time1 ,l_time2, l_time3;
@@ -2457,32 +2456,23 @@ String *Item_func_timediff::val_str(String *str)
(uint) l_time2.month,
(uint) l_time2.day));
- microseconds= l_time1.second_part - l_sign*l_time2.second_part;
- seconds= ((longlong) days*86400L + l_time1.hour*3600L +
- l_time1.minute*60L + l_time1.second + microseconds/1000000L -
- (longlong)l_sign*(l_time2.hour*3600L+l_time2.minute*60L+
- l_time2.second));
+ microseconds= ((longlong)days*86400L +
+ l_time1.hour*3600L + l_time1.minute*60L + l_time1.second -
+ (longlong)l_sign*(l_time2.hour*3600L + l_time2.minute*60L +
+ l_time2.second))*1000000 +
+ l_time1.second_part - l_sign*l_time2.second_part;
l_time3.neg= 0;
- if (seconds < 0)
- {
- seconds= -seconds;
- l_time3.neg= 1;
- }
- else if (seconds == 0 && microseconds < 0)
+ if (microseconds < 0)
{
microseconds= -microseconds;
l_time3.neg= 1;
}
- if (microseconds < 0)
- {
- microseconds+= 1000000L;
- seconds--;
- }
- if ((l_time2.neg == l_time1.neg) && l_time1.neg)
+ if ((l_time2.neg == l_time1.neg) && l_time1.neg && microseconds)
l_time3.neg= l_time3.neg ? 0 : 1;
- calc_time_from_sec(&l_time3, (long) seconds, microseconds);
+ calc_time_from_sec(&l_time3, (long)(microseconds/1000000),
+ (long)(microseconds%1000000));
if (!make_datetime(l_time1.second_part || l_time2.second_part ?
TIME_MICROSECOND : TIME_ONLY,