To comment on the following update, log in, then open the issue:
http://www.openoffice.org/issues/show_bug.cgi?id=74069





------- Additional comments from [email protected] Fri Apr 16 18:22:49 
+0000 2010 -------
I can confirm the bug in oocalc and we just fixed it in KSpread.

What we do is something like;

    switch (basis) {
    case 1: {
        nYears = date2.year() - date1.year() + 1;
        for (int y = date1.year(); y <= date2.year(); ++y)
            peryear += QDate::isLeapYear(y) ? 366 : 365;
        if (QDate(date1.year() + 1, date1.month(), date1.day()) >= date2) {
            nYears = 1;
            peryear = 365;
            if (QDate::isLeapYear(date1.year()) && date1.month() <= 2) peryear
= 366;
            else if (QDate::isLeapYear(date2.year()) && date2.month() > 2)
peryear = 366;
            else if (date2.month() == 2 && date2.day() == 29) peryear = 366;
        }
        peryear = peryear / (long double) nYears;
        nYears = 0;
        break;
    } break;
    case 2: {
        peryear = 360;
    } break;
    case 3: {
        peryear = 365;
    } break;
    case 4: {
        days = days360(date1, date2, 1);
        peryear = 360;
    } break;
    default: {
        days = days360(date1, date2, 0);
        peryear = 360;
    }
    }

int days360(int day1, int month1, int year1, bool leapYear1, int day2, int
month2, int year2, bool leapYear2, bool usaMethod)
{
    if (usaMethod) { // US method
        if (day1 == 31) {
            day1 = 30;
            if (day2 == 31)
                day2 = 30;
        }
        else if (day1 == 30 && day2 == 31)
            day2 = 30;
        else if (month1 == 2 && (day1 == 29 || (day1 == 28 && ! leapYear1))) {
            day1 = 30;
            if (month2 == 2 && (day2 == 29 || (day2 == 28 && ! leapYear2)))
                day2 = 30;
        }
    } else { // European method
        if (day1 == 31) {
            day1 = 30;
        }
        if (day2 == 31) {
            day2 = 30;
        }
    }
    return day2 + month2 * 30 + year2 * 360 - day1 - month1 * 30 - year1 * 360;
}


---------------------------------------------------------------------
Please do not reply to this automatically generated notification from
Issue Tracker. Please log onto the website and enter your comments.
http://qa.openoffice.org/issue_handling/project_issues.html#notification

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to