MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Claudio Cherubino Date:November 28 2007 10:14am
Subject:Patch for bug #32770
View as plain text  
When the LAST_DAY() function takes a DATETIME as parameter it also
copies its time part (i.e. hours, minutes and seconds).

Therefore we just need to zero those values, adding this line before
returning the output:

ltime->hour= ltime->minute= ltime->second= 0;

I'm attaching the patch and a test case I prepared. The patch is based
on version 5.1.23-rc.

a) PATCH
diff -urN sql/item_timefunc.cc.orig sql/item_timefunc.cc
--- item_timefunc.cc.orig    2007-11-27 20:15:41.000000000 +0100
+++ item_timefunc.cc    2007-11-27 20:02:30.000000000 +0100
@@ -3340,6 +3340,7 @@
   ltime->day= days_in_month[month_idx];
   if ( month_idx == 1 && calc_days_in_year(ltime->year) == 366)
     ltime->day= 29;
+  ltime->hour= ltime->minute= ltime->second= 0;
   ltime->time_type= MYSQL_TIMESTAMP_DATE;
   return 0;
 }

b) TEST
#
# Bug #32770: LAST_DAY() returns a DATE, but somehow internally keeps
track of the TIME.
#
SELECT LAST_DAY(NOW())-INTERVAL 1
SECOND=DATE(LAST_DAY(NOW()))-INTERVAL 1 SECOND AS test;

c) RESULT
SELECT LAST_DAY(NOW())-INTERVAL 1
SECOND=DATE(LAST_DAY(NOW()))-INTERVAL 1 SECOND AS test;
test
1

Please tell me if I'm working well, since this is my first MySQL bug
fix and I'd like to go on :)
Thanks

Claudio
Thread
Patch for bug #32770Claudio Cherubino28 Nov