diff options
author | Eike Rathke <erack@redhat.com> | 2016-07-08 17:08:47 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-07-08 20:41:02 +0000 |
commit | 6d4f2dcc7cbba771e9d9b00de50368db4a88ef1b (patch) | |
tree | 0301896941b955ffa79ef3e96b874ebdad78662c /sc | |
parent | 06287b9c348281612854d67c4eb2e7a38dc722ca (diff) |
Resolves: tdf#100452 class Date full (BCE,CE) proleptic Gregorian calendar
... implementing signed years with year 0 gap.
Date(31,12,-1) last day BCE
Date(1,1,1) first day CE
New class Date member functions:
* AddYears(sal_Int16) to be used instead of
aDate.SetYear(aDate.GetYear()+sal_Int16) to handle year 0 gap.
* convenience GetNextYear() to be used insted of GetYear()+1
* convenience GetPrevYear() to be used insted of GetYear()-1
* AddMonths(sal_Int32)
* operator=(const css::util::Date&)
New class DateTime member functions:
* operator=(const css::util::DateTime&)
Made some conversion ctors explicit, specifically Date(sal_Int32)
Adapted hopefully all places that used a sal_uInt16 year to use
sal_Int16 where appropriate.
Eliminated some quirks in date handling found on the fly.
Added era handling to i18npool icu calendar setting interface, which
missing was responsible for 0001-01-01 entered in Calc being set as
-0001-01-01, hence subtracting one day resulted in -0002-12-31.
Change-Id: I77b39fba9599ebd5067d7864f6c9ebe01f6f578f
Reviewed-on: https://gerrit.libreoffice.org/27049
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/docoptio.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/conditio.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/poolhelp.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/tool/chgviset.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/docoptio.cxx | 8 | ||||
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 11 | ||||
-rw-r--r-- | sc/source/ui/cctrl/checklistmenu.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/optdlg/tpcalc.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/unoobj/optuno.cxx | 3 |
9 files changed, 28 insertions, 15 deletions
diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx index a5f3bbfdc298..529135bb9a37 100644 --- a/sc/inc/docoptio.hxx +++ b/sc/inc/docoptio.hxx @@ -73,9 +73,9 @@ public: double GetIterEps() const { return fIterEps; } void SetIterEps( double fEps ) { fIterEps = fEps; } - void GetDate( sal_uInt16& rD, sal_uInt16& rM, sal_uInt16& rY ) const + void GetDate( sal_uInt16& rD, sal_uInt16& rM, sal_Int16& rY ) const { rD = nDay; rM = nMonth; rY = nYear;} - void SetDate (sal_uInt16 nD, sal_uInt16 nM, sal_uInt16 nY) + void SetDate (sal_uInt16 nD, sal_uInt16 nM, sal_Int16 nY) { nDay = nD; nMonth = nM; nYear = nY; } sal_uInt16 GetTabDistance() const { return nTabDistance;} void SetTabDistance( sal_uInt16 nTabDist ) {nTabDistance = nTabDist;} diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 684498c8616c..cf7af863c188 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -1692,7 +1692,7 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const case condformat::LASTMONTH: if( rActDate.GetMonth() == 1 ) { - if( aCellDate.GetMonth() == 12 && rActDate.GetYear() == aCellDate.GetYear() + 1 ) + if( aCellDate.GetMonth() == 12 && rActDate.GetYear() == aCellDate.GetNextYear() ) return true; } else if( rActDate.GetYear() == aCellDate.GetYear() ) @@ -1721,7 +1721,7 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const } break; case condformat::LASTYEAR: - if( rActDate.GetYear() == aCellDate.GetYear() + 1 ) + if( rActDate.GetYear() == aCellDate.GetNextYear() ) return true; break; case condformat::THISYEAR: diff --git a/sc/source/core/data/poolhelp.cxx b/sc/source/core/data/poolhelp.cxx index 40bae0aa690f..b469155f6968 100644 --- a/sc/source/core/data/poolhelp.cxx +++ b/sc/source/core/data/poolhelp.cxx @@ -78,7 +78,8 @@ void ScPoolHelper::UseDocOptions() const { if (pFormTable) { - sal_uInt16 d,m,y; + sal_uInt16 d,m; + sal_Int16 y; aOpt.GetDate( d,m,y ); pFormTable->ChangeNullDate( d,m,y ); pFormTable->ChangeStandardPrec( (sal_uInt16)aOpt.GetStdPrecision() ); @@ -102,7 +103,8 @@ SvNumberFormatter* ScPoolHelper::CreateNumberFormatter() const p->SetColorLink( LINK(m_pSourceDoc, ScDocument, GetUserDefinedColor) ); p->SetEvalDateFormat(NF_EVALDATEFORMAT_INTL_FORMAT); - sal_uInt16 d,m,y; + sal_uInt16 d,m; + sal_Int16 y; aOpt.GetDate(d, m, y); p->ChangeNullDate(d, m, y); p->ChangeStandardPrec(aOpt.GetStdPrecision()); diff --git a/sc/source/core/tool/chgviset.cxx b/sc/source/core/tool/chgviset.cxx index 50a784f8b390..938c26591e62 100644 --- a/sc/source/core/tool/chgviset.cxx +++ b/sc/source/core/tool/chgviset.cxx @@ -146,7 +146,7 @@ void ScChangeViewSettings::AdjustDateMode( const ScDocument& rDoc ) aFirstDateTime.SetTime( 0 ); } aLastDateTime = Date( Date::SYSTEM ); - aLastDateTime.SetYear( aLastDateTime.GetYear() + 100 ); + aLastDateTime.AddYears( 100 ); } break; default: diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx index c8ee49a93795..a84f8ae15a48 100644 --- a/sc/source/core/tool/docoptio.cxx +++ b/sc/source/core/tool/docoptio.cxx @@ -212,7 +212,8 @@ ScDocCfg::ScDocCfg() : Sequence<Any> aValues; const Any* pValues = nullptr; - sal_uInt16 nDateDay, nDateMonth, nDateYear; + sal_uInt16 nDateDay, nDateMonth; + sal_Int16 nDateYear; GetDate( nDateDay, nDateMonth, nDateYear ); aNames = GetCalcPropertyNames(); @@ -246,7 +247,7 @@ ScDocCfg::ScDocCfg() : if (pValues[nProp] >>= nIntVal) nDateMonth = (sal_uInt16) nIntVal; break; case SCCALCOPT_DATE_YEAR: - if (pValues[nProp] >>= nIntVal) nDateYear = (sal_uInt16) nIntVal; + if (pValues[nProp] >>= nIntVal) nDateYear = (sal_Int16) nIntVal; break; case SCCALCOPT_DECIMALS: if (pValues[nProp] >>= nIntVal) SetStdPrecision( (sal_uInt16) nIntVal ); @@ -310,7 +311,8 @@ IMPL_LINK_NOARG_TYPED(ScDocCfg, CalcCommitHdl, ScLinkConfigItem&, void) Sequence<Any> aValues(aNames.getLength()); Any* pValues = aValues.getArray(); - sal_uInt16 nDateDay, nDateMonth, nDateYear; + sal_uInt16 nDateDay, nDateMonth; + sal_Int16 nDateYear; GetDate( nDateDay, nDateMonth, nDateYear ); for(int nProp = 0; nProp < aNames.getLength(); nProp++) diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index fe4331431c02..cc735270d4fd 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -807,7 +807,8 @@ void ScInterpreter::ScGetDateDif() } // split dates in day, month, year for use with formats other than "d" - sal_uInt16 d1, m1, y1, d2, m2, y2; + sal_uInt16 d1, m1, d2, m2; + sal_Int16 y1, y2; Date aDate1( *( pFormatter->GetNullDate())); aDate1 += (long) ::rtl::math::approxFloor( nDate1 ); y1 = aDate1.GetYear(); @@ -819,6 +820,12 @@ void ScInterpreter::ScGetDateDif() m2 = aDate2.GetMonth(); d2 = aDate2.GetDay(); + // Close the year 0 gap to calculate year difference. + if (y1 < 0 && y2 > 0) + ++y1; + else if (y1 > 0 && y2 < 0) + ++y2; + if ( aInterval.equalsIgnoreAsciiCase( "m" ) ) { // Return number of months. @@ -871,7 +878,7 @@ void ScInterpreter::ScGetDateDif() { if (m2 == 1) { - aDate1.SetYear( y2 - 1 ); + aDate1.SetYear( y2 == 1 ? -1 : y2 - 1 ); aDate1.SetMonth( 12 ); } else diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx index 32e2e11364fa..93f9aef01da0 100644 --- a/sc/source/ui/cctrl/checklistmenu.cxx +++ b/sc/source/ui/cctrl/checklistmenu.cxx @@ -1442,7 +1442,7 @@ void ScCheckListMenuWindow::addDateMember(const OUString& rsName, double nVal, b Date aDate = *(pFormatter->GetNullDate()); aDate += static_cast<long>(rtl::math::approxFloor(nVal)); - sal_uInt16 nYear = aDate.GetYear(); + sal_Int16 nYear = aDate.GetYear(); sal_uInt16 nMonth = aDate.GetMonth(); sal_uInt16 nDay = aDate.GetDay(); diff --git a/sc/source/ui/optdlg/tpcalc.cxx b/sc/source/ui/optdlg/tpcalc.cxx index 9cf30a177009..a9834f4e69aa 100644 --- a/sc/source/ui/optdlg/tpcalc.cxx +++ b/sc/source/ui/optdlg/tpcalc.cxx @@ -112,7 +112,8 @@ VclPtr<SfxTabPage> ScTpCalcOptions::Create( vcl::Window* pParent, const SfxItemS void ScTpCalcOptions::Reset( const SfxItemSet* /* rCoreAttrs */ ) { - sal_uInt16 d,m,y; + sal_uInt16 d,m; + sal_Int16 y; *pLocalOptions = *pOldOptions; diff --git a/sc/source/ui/unoobj/optuno.cxx b/sc/source/ui/unoobj/optuno.cxx index 925af4e63c26..ff479fe92677 100644 --- a/sc/source/ui/unoobj/optuno.cxx +++ b/sc/source/ui/unoobj/optuno.cxx @@ -162,7 +162,8 @@ uno::Any ScDocOptionsHelper::getPropertyValue( break; case PROP_UNO_NULLDATE: { - sal_uInt16 nD, nM, nY; + sal_uInt16 nD, nM; + sal_Int16 nY; rOptions.GetDate( nD, nM, nY ); util::Date aDate( nD, nM, nY ); aRet <<= aDate; |