MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Ian Greenhoe Date:June 23 2006 5:38am
Subject:bk commit into 5.0 tree (igreenhoe:1.2206) BUG#16226
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of greenman. When greenman does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2206 06/06/22 22:38:12 igreenhoe@stripped +3 -0
  Fix for bug #16226 (TIMESTAMPDIFF has problem with time intervals
  greater than a week)
  
  Problem:  Truncation of info leading to midnight-to-midnight
  comparison of days when using timestamp info if comparing in terms
  of months, quarters, or years.
  
  Solution:  Add in the seconds and microseconds after midnight,
  allowing us to do a more fine-grained comparison.
  
  Additional tests include the specific example mentioned in the
  bug report.

  sql/item_timefunc.cc
    1.115 06/06/22 22:38:00 igreenhoe@stripped +17 -0
    Added in seconds and microseconds after midnight to enable better
    comparisons for month/quarter/year.

  mysql-test/t/func_time.test
    1.47 06/06/22 22:37:59 igreenhoe@stripped +31 -0
    Additional test cases (including test case listed in bug report)

  mysql-test/r/func_time.result
    1.57 06/06/22 22:37:59 igreenhoe@stripped +72 -0
    Additional test results

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	igreenhoe
# Host:	anubis.greendragongames.com
# Root:	/home/greenman/workspace-mysql/mysql/bug-5.0-16226

--- 1.114/sql/item_timefunc.cc	2006-06-16 15:52:46 -07:00
+++ 1.115/sql/item_timefunc.cc	2006-06-22 22:38:00 -07:00
@@ -2865,6 +2865,8 @@
   {
     uint year_beg, year_end, month_beg, month_end, day_beg, day_end;
     uint years= 0;
+    uint second_beg, second_end, microsecond_beg, microsecond_end;
+
     if (neg == -1)
     {
       year_beg= ltime2.year;
@@ -2873,6 +2875,10 @@
       month_end= ltime1.month;
       day_beg= ltime2.day;
       day_end= ltime1.day;
+      second_beg= ltime2.hour * 3600 + ltime2.minute * 60 + ltime2.second;
+      second_end= ltime1.hour * 3600 + ltime1.minute * 60 + ltime1.second;
+      microsecond_beg= ltime2.second_part;
+      microsecond_end= ltime1.second_part;
     }
     else
     {
@@ -2882,6 +2888,10 @@
       month_end= ltime2.month;
       day_beg= ltime1.day;
       day_end= ltime2.day;
+      second_beg= ltime1.hour * 3600 + ltime1.minute * 60 + ltime1.second;
+      second_end= ltime2.hour * 3600 + ltime2.minute * 60 + ltime2.second;
+      microsecond_beg= ltime1.second_part;
+      microsecond_end= ltime2.second_part;
     }
 
     /* calc years */
@@ -2897,6 +2907,13 @@
       months+= (month_end - month_beg);
     if (day_end < day_beg)
       months-= 1;
+    else if (day_end == day_beg)
+    {
+    if (second_end < second_beg)
+      months-= 1;
+    else if (second_end == second_beg && microsecond_end < microsecond_beg)
+      months-= 1;
+    }
   }
 
   switch (int_type) {

--- 1.56/mysql-test/r/func_time.result	2006-06-22 11:23:16 -07:00
+++ 1.57/mysql-test/r/func_time.result	2006-06-22 22:37:59 -07:00
@@ -661,6 +661,78 @@
 timestampdiff(SQL_TSI_DAY, '2000-02-01', '2000-03-01') as a4;
 a1	a2	a3	a4
 28	28	29	29
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27');
+TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27')
+0
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28');
+TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28')
+1
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29');
+TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29')
+1
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27');
+TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27')
+1
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28');
+TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28')
+2
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29');
+TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29')
+2
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27');
+TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27')
+0
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28');
+TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28')
+1
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29');
+TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29')
+1
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27');
+TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27')
+1
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28');
+TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28')
+2
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29');
+TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29')
+2
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27');
+TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27')
+0
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28');
+TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28')
+1
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29');
+TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29')
+1
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27');
+TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27')
+1
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28');
+TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28')
+2
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29');
+TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29')
+2
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27');
+TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27')
+0
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28');
+TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28')
+1
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29');
+TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29')
+1
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27');
+TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27')
+1
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28');
+TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28')
+2
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29');
+TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29')
+2
 select date_add(time,INTERVAL 1 SECOND) from t1;
 date_add(time,INTERVAL 1 SECOND)
 NULL

--- 1.46/mysql-test/t/func_time.test	2006-06-22 11:23:16 -07:00
+++ 1.47/mysql-test/t/func_time.test	2006-06-22 22:37:59 -07:00
@@ -314,6 +314,37 @@
        timestampdiff(SQL_TSI_DAY, '1996-02-01', '1996-03-01') as a3,
        timestampdiff(SQL_TSI_DAY, '2000-02-01', '2000-03-01') as a4;
 
+# bug 16226
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27');
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28');
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29');
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27');
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28');
+SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29');
+
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27');
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28');
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29');
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27');
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28');
+SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29');
+
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27');
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28');
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29');
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27');
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28');
+SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29');
+
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27');
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28');
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29');
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27');
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28');
+SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29');
+
+# end of bug
+
 select date_add(time,INTERVAL 1 SECOND) from t1;
 drop table t1;
 
Thread
bk commit into 5.0 tree (igreenhoe:1.2206) BUG#16226Ian Greenhoe23 Jun