diff options
author | Winfried Donkers <winfrieddonkers@libreoffice.org> | 2017-01-29 15:58:05 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-01-30 14:54:35 +0000 |
commit | e7606f1f19b2970f0160075f56d4d97029f1e47a (patch) | |
tree | d847adb5fe240078a5858621d2f3d282aba7942b /sc | |
parent | 1db423338899c71ba70e361af339d7b7e4aff61f (diff) |
tdf#105548 fix incorrect DATEDIF result.
DATEDIF didn't convert datetime values to date before calculating
date differences, which in certain cases produced incorrect results.
Adding use case to unit test document.
Removed 'TODO-comment' after checking what Excel really does.
Change-Id: Icc16413e43f664d1c993d24e31eb4dc6990623e9
Reviewed-on: https://gerrit.libreoffice.org/33662
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/data/functions/date_time/fods/datedif.fods | 31 | ||||
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 11 |
2 files changed, 33 insertions, 9 deletions
diff --git a/sc/qa/unit/data/functions/date_time/fods/datedif.fods b/sc/qa/unit/data/functions/date_time/fods/datedif.fods index 9f13e96684d4..9b09a9bd8535 100644 --- a/sc/qa/unit/data/functions/date_time/fods/datedif.fods +++ b/sc/qa/unit/data/functions/date_time/fods/datedif.fods @@ -2610,6 +2610,33 @@ </table:table-cell> <table:table-cell table:number-columns-repeated="8"/> </table:table-row> + <table:table-row table:style-name="ro5"> + <table:table-cell table:formula="of:=DATEDIF([.F112];[.G112];[.H112])" office:value-type="float" office:value="2" calcext:value-type="float"> + <text:p>2</text:p> + </table:table-cell> + <table:table-cell office:value-type="float" office:value="2" calcext:value-type="float"> + <text:p>2</text:p> + </table:table-cell> + <table:table-cell table:style-name="ce11" table:formula="of:=[.A112]=[.B112]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean"> + <text:p>PRAVDA</text:p> + </table:table-cell> + <table:table-cell table:formula="of:=FORMULA([.A112])" office:value-type="string" office:string-value="=DATEDIF(F112;G112;H112)" calcext:value-type="string"> + <text:p>=DATEDIF(F112;G112;H112)</text:p> + </table:table-cell> + <table:table-cell office:value-type="string" calcext:value-type="string"> + <text:p>tdf#105548</text:p> + </table:table-cell> + <table:table-cell table:style-name="ce40" office:value-type="date" office:date-value="2017-01-01T08:00:00" calcext:value-type="date"> + <text:p>01/01/2017 08:00 AM</text:p> + </table:table-cell> + <table:table-cell table:style-name="ce40" office:value-type="date" office:date-value="2017-01-03T07:00:00" calcext:value-type="date"> + <text:p>01/03/17 07:00 AM</text:p> + </table:table-cell> + <table:table-cell office:value-type="string" calcext:value-type="string"> + <text:p>d</text:p> + </table:table-cell> + <table:table-cell table:number-columns-repeated="8"/> + </table:table-row> <table:table-row table:style-name="ro6" table:number-rows-repeated="1048464"> <table:table-cell table:number-columns-repeated="16"/> </table:table-row> @@ -2617,7 +2644,7 @@ <table:table-cell table:number-columns-repeated="16"/> </table:table-row> <calcext:conditional-formats> - <calcext:conditional-format calcext:target-range-address="Sheet2.C2:Sheet2.C111"> + <calcext:conditional-format calcext:target-range-address="Sheet2.C2:Sheet2.C112"> <calcext:condition calcext:apply-style-name="1true" calcext:value="=TRUE()" calcext:base-cell-address="Sheet2.C2"/> <calcext:condition calcext:apply-style-name="0false" calcext:value="!=TRUE()" calcext:base-cell-address="Sheet2.C2"/> </calcext:conditional-format> @@ -2643,4 +2670,4 @@ </table:named-expressions> </office:spreadsheet> </office:body> -</office:document>
\ No newline at end of file +</office:document> diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 469ea7188911..85f2307cdf2b 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -783,8 +783,8 @@ void ScInterpreter::ScGetDateDif() if ( MustHaveParamCount( GetByte(), 3 ) ) { OUString aInterval = GetString().getString(); - double nDate2 = GetDouble(); - double nDate1 = GetDouble(); + long nDate2 = ::rtl::math::approxFloor( GetDouble() ); + long nDate1 = ::rtl::math::approxFloor( GetDouble() ); if (nGlobalError != FormulaError::NONE) { @@ -811,12 +811,12 @@ void ScInterpreter::ScGetDateDif() sal_uInt16 d1, m1, d2, m2; sal_Int16 y1, y2; Date aDate1( *( pFormatter->GetNullDate())); - aDate1 += (long) ::rtl::math::approxFloor( nDate1 ); + aDate1 += nDate1; y1 = aDate1.GetYear(); m1 = aDate1.GetMonth(); d1 = aDate1.GetDay(); Date aDate2( *( pFormatter->GetNullDate())); - aDate2 += (long) ::rtl::math::approxFloor( nDate2 ); + aDate2 += nDate2; y2 = aDate2.GetYear(); m2 = aDate2.GetMonth(); d2 = aDate2.GetDay(); @@ -905,9 +905,6 @@ void ScInterpreter::ScGetDateDif() { // Return number of days, excluding years. - /* TODO: check what Excel really does, though this seems to be - * reasonable */ - // Condition corresponds with "y". if (m2 > m1 || (m2 == m1 && d2 >= d1)) aDate1.SetYear( y2 ); |