[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kspread/functions
From: Sebastian Sauer <mail () dipe ! org>
Date: 2010-04-16 18:29:13
Message-ID: 20100416182913.33CADAC898 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1115529 by sebsauer:
forwaort-port r1115527
Fix the remaining issues with the 30/360 US calculation.
see for the testcase that passes now \
http://plugtest.opendocsociety.org/doku.php?id=scenarios:20100415:yearfrac see \
http://qa.openoffice.org/issues/show_bug.cgi?id=74069 for the matching (still open) \
for the oocalc bugreport
M +25 -17 helper.cpp
M +1 -1 helper.h
--- trunk/koffice/kspread/functions/helper.cpp #1115528:1115529
@@ -135,26 +135,34 @@
return -1;
}
+// the days360 method does implement the 30/360days method as used in e.g. the \
YEARFRAC function int KSpread::days360(int day1, int month1, int year1, bool \
leapYear1,
- int day2, int month2, int year2,
+ int day2, int month2, int year2, bool leapYear2,
bool usaMethod)
{
- if (day1 == 31)
- day1--;
- else if (usaMethod && (month1 == 2 && (day1 == 29 || (day1 == 28 && ! \
leapYear1))))
- day1 = 30;
-
- if (day2 == 31) {
- if (usaMethod && day1 != 30) {
- // date2 += 1
- day2 = 1;
- if (month2 == 12) {
- year2++;
- month2 = 1;
- } else
- month2++;
- } else
+ 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;
}
@@ -173,7 +181,7 @@
month2 = _date2.month();
year2 = _date2.year();
- return days360(day1, month1, year1, QDate::isLeapYear(_date1.year()), day2, \
month2, year2, !european); + return days360(day1, month1, year1, \
QDate::isLeapYear(_date1.year()), day2, month2, year2, \
QDate::isLeapYear(_date2.year()), !european); }
--- trunk/koffice/kspread/functions/helper.h #1115528:1115529
@@ -46,7 +46,7 @@
// ODF
KSPREAD_EXPORT int days360(const QDate& _date1, const QDate& _date2, bool european);
-KSPREAD_EXPORT int days360(int day1, int month1, int year1, bool leapYear1, int \
day2, int month2, int year2, bool usa); +KSPREAD_EXPORT int days360(int day1, int \
month1, int year1, bool leapYear1, int day2, int month2, int year2, bool leapYear2, \
bool usa); KSPREAD_EXPORT long double yearFrac(const QDate& refDate, const QDate& \
startDate, const QDate& endDate, int basis); KSPREAD_EXPORT long double \
duration(const QDate& refDate, const QDate& settlement, const QDate& maturity, const \
long double& coup_, const long double& yield_, const int& freq, const int& basis, \
const long double& numOfCoups); KSPREAD_EXPORT long double pow1p(const long double& \
x, const long double& y);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic