Changeset: 0f5f568157a3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0f5f568157a3
Modified Files:
        monetdb5/modules/atoms/mtime.c
Branch: Oct2014
Log Message:

Allow adding and subtracting non-positive intervals to dates.
It was even worse: non-positive intervals (i.e. including 0) resulted
in garbage results since the return value was not filled in without
returning an error.


diffs (97 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
@@ -2272,49 +2272,69 @@ MTIMEtzone_extract_minutes(int *ret, con
 str
 MTIMEdate_sub_sec_interval_wrap(date *ret, const date *t, const int *sec)
 {
-       if (*sec > 0) {
-               int delta = -(*sec / 86400);
-
-               return MTIMEdate_adddays(ret, t, &delta);
+       int delta;
+
+       if (*sec == int_nil || *t == date_nil) {
+               *ret = date_nil;
+               return MAL_SUCCEED;
        }
-
-       return MAL_SUCCEED;
+       if (*sec >= 0)
+               delta = -(int) (*sec / 86400);
+       else
+               delta = (int) (-*sec / 86400);
+
+       return MTIMEdate_adddays(ret, t, &delta);
 }
 
 str
 MTIMEdate_sub_msec_interval_lng_wrap(date *ret, const date *t, const lng *msec)
 {
-       if (*msec > 0) {
-               int delta = (int) -(*msec / 86400000);
-
-               return MTIMEdate_adddays(ret, t, &delta);
+       int delta;
+
+       if (*msec == lng_nil || *t == date_nil) {
+               *ret = date_nil;
+               return MAL_SUCCEED;
        }
-
-       return MAL_SUCCEED;
+       if (*msec > 0)
+               delta = -(int) (*msec / 86400000);
+       else
+               delta = (int) (-*msec / 86400000);
+
+       return MTIMEdate_adddays(ret, t, &delta);
 }
 
 str
 MTIMEdate_add_sec_interval_wrap(date *ret, const date *t, const int *sec)
 {
-       if (*sec > 0) {
-               int delta = *sec / 86400;
-
-               return MTIMEdate_adddays(ret, t, &delta);
+       int delta;
+
+       if (*sec == int_nil || *t == date_nil) {
+               *ret = date_nil;
+               return MAL_SUCCEED;
        }
-
-       return MAL_SUCCEED;
+       if (*sec >= 0)
+               delta = (int) (*sec / 86400);
+       else
+               delta = -(int) (-*sec / 86400);
+
+       return MTIMEdate_adddays(ret, t, &delta);
 }
 
 str
 MTIMEdate_add_msec_interval_lng_wrap(date *ret, const date *t, const lng *msec)
 {
-       if (*msec > 0) {
-               int delta = (int) (*msec / 86400000);
-
-               return MTIMEdate_adddays(ret, t, &delta);
+       int delta;
+
+       if (*msec == lng_nil || *t == date_nil) {
+               *ret = date_nil;
+               return MAL_SUCCEED;
        }
-
-       return MAL_SUCCEED;
+       if (*msec > 0)
+               delta = (int) (*msec / 86400000);
+       else
+               delta = -(int) (-*msec / 86400000);
+
+       return MTIMEdate_adddays(ret, t, &delta);
 }
 
 str
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to