summaryrefslogtreecommitdiff
path: root/scaddins
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2018-12-09 11:52:18 +0100
committerEike Rathke <erack@redhat.com>2018-12-12 15:58:53 +0100
commit22be500b1624753decec43c0de4ccb1c5f7a21d4 (patch)
tree1436d6e8988b0a951f496a508b7d418239a84694 /scaddins
parent12edea426a31f57a9d5b1c65b34fb1336c5534e9 (diff)
tdf#69569 implement proposed change to ODF1.2 part 2 §4.11.7.7
Calculating the number of days in a year in AddIn function GetDaysInYear() for basis 1 (actual/actual) gave wrong results. Now the results are correct and the same as in Excel. Extended the unit test document for function YEARFRAC and corrected the unit test document for function AMORDEGRC (verified the results with Excel). Change-Id: Ic68f108496f41dec71b3616095dff80512a64c31 Reviewed-on: https://gerrit.libreoffice.org/64837 Tested-by: Jenkins Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'scaddins')
-rw-r--r--scaddins/source/analysis/analysishelper.cxx78
1 files changed, 27 insertions, 51 deletions
diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx
index 3baf6d70cb46..1a21ecbb0b31 100644
--- a/scaddins/source/analysis/analysishelper.cxx
+++ b/scaddins/source/analysis/analysishelper.cxx
@@ -442,8 +442,7 @@ sal_Int32 GetDaysInYear( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nMode )
}
-//fdo40100 toDo: make function fully compliant with ODFF1.2
-// LEM: I fixed case nMode==1; anything else to fix?
+// tdf69569 making code compliant with change request for ODFF1.2 par 4.11.7.7
/**
* Function GetYearFrac implements YEARFRAC as defined in:
* Open Document Format for Office Applications version 1.2 Part 2, par. 6.10.24
@@ -543,62 +542,39 @@ double GetYearFrac( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDat
nDaysInYear = static_cast<double>(nDayCount) / static_cast<double>( nYear2 - nYear1 + 1 );
}
- // we take advantage of the fact that (ODFv1.2 part 2) 4.11.7.7.9
- // 4.11.7.7.10 can be permuted without changing the end result
- // ODFv1.2 part 2 section 4.11.7.7.8 and 4.11.7.7.10
- else if ( ( isYearDifferent && IsLeapYear( nYear1 ) ) ||
- ( nMonth2 == 2 && nDay2 == 29) )
- {
- nDaysInYear = 366;
- }
else
{
- // ODFv1.2 part 2 section 4.11.7.7.9:
- // we need to determine whether there is a 29 February
- // between nDate1 and nDate2
- // LEM FIXME: I have a doubt concerning nDate1 == "29 February YYYY"
- // In this case, is the "29 February YYYY" between nDate1 and nDate2
- // in the meaning of ODFv1.2 part 2, section 4.11.7.7.9?
- // I assume "no", since if "between" is to be understood as "inclusive"
- // then 4.11.7.7.10 has no point.
- // OTOH, it could theoretically be possible that "between"
- // is to be understood as "inclusive the lower bound, exclusive in upper bound".
-
- assert(nYear1 == nYear2 || nYear1 + 1 == nYear2);
- // as a consequence, nYearDifferent iff nYear2 == nYear + 1, and
- // there are only two possible 29 Februaries to consider:
- // "29 February nYear1" and "29 February nYear2"
-
- // nDate2=="29 February YYYY" is handled above and the following conditions
- // rely on that for simplification.
- assert( ! (nMonth2 == 2 && nDay2 == 29));
-
- if( IsLeapYear( nYear1 ) )
- assert(nYear1 == nYear2);
-
- // is 29/2/nYear1 between nDate1 and nDate2?
- // that is only possible if IsLeapYear( nYear1 ),
- // which implies nYear1 == nYear2
- if( IsLeapYear( nYear1 ) &&
- ( nMonth1 == 1 || ( nMonth1 == 2 && nDay1 <= 28 )) &&
- nMonth2 > 2 )
- {
- nDaysInYear = 366;
- }
- // is 29/2/nYear2 between nDate1 and nDate2?
- // if nYear1==nYear2, then that is adequately tested by the previous test,
- // so no need to retest it here.
- else if(isYearDifferent && nMonth2 > 2 && IsLeapYear( nYear2 ))
+ // as a consequence, !isYearDifferent or
+ // nYear2 == nYear + 1 and (nMonth1 > nMonth2 or
+ // (nMonth1 == nMonth2 and nDay1 >= nDay2))
+ assert( ( !isYearDifferent ||
+ ( nYear1 + 1 == nYear2 &&
+ ( nMonth1 > nMonth2 ||
+ ( nMonth1 == nMonth2 || nDay1 >= nDay2 ) ) ) ) );
+
+ // ODFv1.2 part 2 section 4.11.7.7.8 (CHANGE REQUEST PENDING, see tdf6959)
+ if ( !isYearDifferent && IsLeapYear( nYear1 ) )
{
nDaysInYear = 366;
}
else
{
- assert( !( IsLeapYear( nYear2 ) &&
- nYear1 == nYear2 &&
- (nMonth1 == 1 || (nMonth1==2 && nDay1 <= 28)) &&
- nMonth2 > 2));
- nDaysInYear = 365;
+ // ODFv1.2 part 2 section 4.11.7.7.9/10 (CHANGE REQUEST PENDING, see tdf69569)
+ // we need to determine whether there is a 29 February
+ // between nDate1 (inclusive) and nDate2 (inclusive)
+ // the case of nYear1 == nYear2 is adequately tested in previous test
+ if( isYearDifferent &&
+ ( ( IsLeapYear( nYear1 ) &&
+ ( ( nMonth1 < 2 ) || ( ( nMonth1 == 2 ) && ( nDay1 <= 29 ) ) ) ) ||
+ ( IsLeapYear( nYear2 ) &&
+ ( nMonth2 > 2 || ( ( nMonth2 == 2 ) && ( nDay2 == 29 ) ) ) ) ) )
+ {
+ nDaysInYear = 366;
+ }
+ else
+ {
+ nDaysInYear = 365;
+ }
}
}
}