Changeset: 27f146dcaa6c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=27f146dcaa6c
Modified Files:
monetdb5/modules/atoms/mtime.c
Branch: Oct2012
Log Message:
Add or subtract number of days in correct month.
We need to adjust the year when wrapping months since some years are
leap years.
This fixes bug 3215.
diffs (33 lines):
diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -1476,7 +1476,7 @@ date_adddays(date *ret, date *v, int *de
}
/* returns the date that comes a number of months after 'v' (or before
- * iff *delta < 0). */
+ * if *delta < 0). */
static str
date_addmonths(date *ret, date *v, int *delta)
{
@@ -1490,14 +1490,18 @@ date_addmonths(date *ret, date *v, int *
while (z > 0) {
z--;
x = MONTHDAYS(m, y);
- if (++m == 13)
+ if (++m == 13) {
m = 1;
+ y++;
+ }
date_adddays(ret, ret, &x);
}
while (z < 0) {
z++;
- if (--m == 0)
+ if (--m == 0) {
m = 12;
+ y--;
+ }
x = -MONTHDAYS(m, y);
date_adddays(ret, ret, &x);
}
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list