From 056190b68d614f1566ed254b2b31e18344c374c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Thu, 25 Feb 2016 23:09:51 +0000 Subject: [PATCH] [INTERPRETER] * BUG: DateDiff() correctly returns zero when asking for the number of days between two timestamps having the same date. git-svn-id: svn://localhost/gambas/trunk@7612 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_date.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/main/gbx/gbx_date.c b/main/gbx/gbx_date.c index cc2ec7272..4a0f841b6 100644 --- a/main/gbx/gbx_date.c +++ b/main/gbx/gbx_date.c @@ -764,10 +764,14 @@ int DATE_diff(VALUE *date1, VALUE *date2, int period) { case DP_DAY: case DP_WEEK: + fprintf(stderr, "DATE_diff: (%d %d) -> (%d %d)\n", date2->_date.date, date2->_date.time, date1->_date.date, date1->_date.time); diff = date1->_date.date - date2->_date.date; - sdiff = lsgn(date1->_date.time - date2->_date.time); - if (sdiff != lsgn(diff)) - diff += sdiff; + if (diff) + { + sdiff = lsgn(date1->_date.time - date2->_date.time); + if (sdiff != lsgn(diff)) + diff += sdiff; + } break; case DP_MILLISECOND: @@ -787,9 +791,12 @@ int DATE_diff(VALUE *date1, VALUE *date2, int period) case DP_WEEKDAY: diff = date1->_date.date - date2->_date.date; - sdiff = lsgn(date1->_date.time - date2->_date.time); - if (sdiff != lsgn(diff)) - diff += sdiff; + if (diff) + { + sdiff = lsgn(date1->_date.time - date2->_date.time); + if (sdiff != lsgn(diff)) + diff += sdiff; + } ds1 = *DATE_split(date1); ds2 = *DATE_split(date2); break;