Below is the list of changes that have just been committed into a local
5.0 repository of jimw. When jimw 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.2024 05/10/07 10:45:39 jimw@stripped +3 -0
Fix calculation of TIMESTAMPDIFF() around leap years. (Bug #13534)
sql/item_timefunc.cc
1.95 05/10/07 10:45:35 jimw@stripped +9 -2
Fix calculation of TIMESTAMPDIFF() as it relates to leap years.
mysql-test/t/func_time.test
1.38 05/10/07 10:45:35 jimw@stripped +15 -0
Add new regression test
mysql-test/r/func_time.result
1.47 05/10/07 10:45:35 jimw@stripped +30 -0
Add new 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: jimw
# Host: rama.(none)
# Root: /home/jimw/my/mysql-5.0-13534
--- 1.94/sql/item_timefunc.cc 2005-09-14 09:24:30 -07:00
+++ 1.95/sql/item_timefunc.cc 2005-10-07 10:45:35 -07:00
@@ -2724,7 +2724,7 @@
int_type == INTERVAL_MONTH)
{
uint year;
- uint year_beg, year_end, month_beg, month_end;
+ uint year_beg, year_end, month_beg, month_end, day_beg;
uint diff_days= (uint) (seconds/86400L);
uint diff_years= 0;
if (neg == -1)
@@ -2733,6 +2733,7 @@
year_end= ltime1.year;
month_beg= ltime2.month;
month_end= ltime1.month;
+ day_beg= ltime2.day;
}
else
{
@@ -2740,11 +2741,17 @@
year_end= ltime2.year;
month_beg= ltime1.month;
month_end= ltime2.month;
+ day_beg= ltime1.day;
}
/* calc years*/
for (year= year_beg;year < year_end; year++)
{
- uint days=calc_days_in_year(year);
+ /*
+ We only need to consider this year to be 366 days if it is a leap
+ year and the date we are starting from is before 2/29.
+ */
+ uint days= (month_beg < 3 && !(month_beg == 2 && day_beg == 29))
?
+ calc_days_in_year(year) : 365;
if (days > diff_days)
break;
diff_days-= days;
--- 1.46/mysql-test/r/func_time.result 2005-09-14 09:24:30 -07:00
+++ 1.47/mysql-test/r/func_time.result 2005-10-07 10:45:35 -07:00
@@ -760,3 +760,33 @@
@a != @b
1
drop procedure t_sysdate;
+select timestampdiff(month,'2004-09-11','2004-09-11');
+timestampdiff(month,'2004-09-11','2004-09-11')
+0
+select timestampdiff(month,'2004-09-11','2005-09-11');
+timestampdiff(month,'2004-09-11','2005-09-11')
+12
+select timestampdiff(month,'2004-09-11','2006-09-11');
+timestampdiff(month,'2004-09-11','2006-09-11')
+24
+select timestampdiff(month,'2004-09-11','2007-09-11');
+timestampdiff(month,'2004-09-11','2007-09-11')
+36
+select timestampdiff(month,'2005-09-11','2004-09-11');
+timestampdiff(month,'2005-09-11','2004-09-11')
+-12
+select timestampdiff(month,'2005-09-11','2003-09-11');
+timestampdiff(month,'2005-09-11','2003-09-11')
+-24
+select timestampdiff(month,'2004-02-28','2005-02-28');
+timestampdiff(month,'2004-02-28','2005-02-28')
+12
+select timestampdiff(month,'2004-02-29','2005-02-28');
+timestampdiff(month,'2004-02-29','2005-02-28')
+12
+select timestampdiff(month,'2003-02-28','2004-02-29');
+timestampdiff(month,'2003-02-28','2004-02-29')
+12
+select timestampdiff(month,'2003-02-28','2005-02-28');
+timestampdiff(month,'2003-02-28','2005-02-28')
+24
--- 1.37/mysql-test/t/func_time.test 2005-08-24 15:50:54 -07:00
+++ 1.38/mysql-test/t/func_time.test 2005-10-07 10:45:35 -07:00
@@ -404,4 +404,19 @@
call t_sysdate();
drop procedure t_sysdate;
+#
+# Bug #13534: timestampdiff() returned incorrect results across leap years
+#
+select timestampdiff(month,'2004-09-11','2004-09-11');
+select timestampdiff(month,'2004-09-11','2005-09-11');
+select timestampdiff(month,'2004-09-11','2006-09-11');
+select timestampdiff(month,'2004-09-11','2007-09-11');
+select timestampdiff(month,'2005-09-11','2004-09-11');
+select timestampdiff(month,'2005-09-11','2003-09-11');
+
+select timestampdiff(month,'2004-02-28','2005-02-28');
+select timestampdiff(month,'2004-02-29','2005-02-28');
+select timestampdiff(month,'2003-02-28','2004-02-29');
+select timestampdiff(month,'2003-02-28','2005-02-28');
+
# End of 5.0 tests
| Thread |
|---|
| • bk commit into 5.0 tree (jimw:1.2024) BUG#13534 | Jim Winstead | 7 Oct |