diff options
author | Noel Grandin <noel@peralex.com> | 2015-01-11 13:35:38 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-01-13 15:24:04 +0000 |
commit | c32a5a3b8e2e3a49ac9f1fd3f2872b00612676b7 (patch) | |
tree | cb2de3eab8dbbcff359d367177d91b67725e1b69 /sc/source | |
parent | 86db1702d72a103ffeafc69dcaa63318539c147a (diff) |
simplify Date/Time/DateTime conversion code
add constructors to Date/DateTime/Time,
that take the css::util counterparts,
to simplify code converting between these type
Change-Id: I4b03da02c63f65b6ec18cb4d6ecc3859bdef1ff7
Reviewed-on: https://gerrit.libreoffice.org/13855
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/filter/oox/revisionfragment.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLConverter.cxx | 22 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLConverter.hxx | 2 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlexprt.cxx | 7 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh8.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/sharedocdlg.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/unoobj/fielduno.cxx | 2 |
9 files changed, 12 insertions, 44 deletions
diff --git a/sc/source/filter/oox/revisionfragment.cxx b/sc/source/filter/oox/revisionfragment.cxx index 45ad6de90335..fd9195f910d9 100644 --- a/sc/source/filter/oox/revisionfragment.cxx +++ b/sc/source/filter/oox/revisionfragment.cxx @@ -300,8 +300,8 @@ void RevisionHeadersFragment::importHeader( const AttributeList& rAttribs ) { util::DateTime aDateTime; sax::Converter::parseDateTime(aDateTime, 0, aDateTimeStr); - Date aDate(aDateTime.Day, aDateTime.Month, aDateTime.Year); - tools::Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.NanoSeconds); + Date aDate(aDateTime); + tools::Time aTime(aDateTime); aMetadata.maDateTime.SetDate(aDate.GetDate()); aMetadata.maDateTime.SetTime(aTime.GetTime()); } diff --git a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx index c6974192467d..a85ec222b7bb 100644 --- a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx +++ b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx @@ -433,8 +433,8 @@ void ScXMLChangeTrackingImportHelper::EndChangeAction() void ScXMLChangeTrackingImportHelper::ConvertInfo(const ScMyActionInfo& aInfo, OUString& rUser, DateTime& aDateTime) { - Date aDate(aInfo.aDateTime.Day, aInfo.aDateTime.Month, aInfo.aDateTime.Year); - tools::Time aTime(aInfo.aDateTime.Hours, aInfo.aDateTime.Minutes, aInfo.aDateTime.Seconds, aInfo.aDateTime.NanoSeconds); + Date aDate(aInfo.aDateTime); + tools::Time aTime(aInfo.aDateTime); aDateTime.SetDate( aDate.GetDate() ); aDateTime.SetTime( aTime.GetTime() ); diff --git a/sc/source/filter/xml/XMLConverter.cxx b/sc/source/filter/xml/XMLConverter.cxx index 4e4fb3143aa3..a3a9986a0563 100644 --- a/sc/source/filter/xml/XMLConverter.cxx +++ b/sc/source/filter/xml/XMLConverter.cxx @@ -312,30 +312,10 @@ void ScXMLConverter::ParseFormula(OUString& sFormula, const bool bIsFormula) void ScXMLConverter::ConvertDateTimeToString(const DateTime& aDateTime, OUStringBuffer& sDate) { - util::DateTime aAPIDateTime; - ConvertCoreToAPIDateTime(aDateTime, aAPIDateTime); + css::util::DateTime aAPIDateTime = aDateTime.GetUNODateTime(); ::sax::Converter::convertDateTime(sDate, aAPIDateTime, 0); } -void ScXMLConverter::ConvertCoreToAPIDateTime(const DateTime& aDateTime, util::DateTime& rDateTime) -{ - rDateTime.Year = aDateTime.GetYear(); - rDateTime.Month = aDateTime.GetMonth(); - rDateTime.Day = aDateTime.GetDay(); - rDateTime.Hours = aDateTime.GetHour(); - rDateTime.Minutes = aDateTime.GetMin(); - rDateTime.Seconds = aDateTime.GetSec(); - rDateTime.NanoSeconds = aDateTime.GetNanoSec(); -} - -void ScXMLConverter::ConvertAPIToCoreDateTime(const util::DateTime& aDateTime, DateTime& rDateTime) -{ - Date aDate(aDateTime.Day, aDateTime.Month, aDateTime.Year); - tools::Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.NanoSeconds); - DateTime aTempDateTime (aDate, aTime); - rDateTime = aTempDateTime; -} - namespace { /** Enumerates different types of condition tokens. */ diff --git a/sc/source/filter/xml/XMLConverter.hxx b/sc/source/filter/xml/XMLConverter.hxx index f9891cd4ff43..7baa9ef8521e 100644 --- a/sc/source/filter/xml/XMLConverter.hxx +++ b/sc/source/filter/xml/XMLConverter.hxx @@ -96,9 +96,7 @@ public: const bool bIsFormula = true); // EXPORT: Core Date Time static void ConvertDateTimeToString(const DateTime& aDateTime, OUStringBuffer& sDate); - static void ConvertCoreToAPIDateTime(const DateTime& aDateTime, com::sun::star::util::DateTime& rDateTime); - static void ConvertAPIToCoreDateTime(const com::sun::star::util::DateTime& aDateTime, DateTime& rDateTime); }; enum ScXMLConditionToken diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index fa6c9443ac83..5f1f4d585a71 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -4831,13 +4831,10 @@ void ScXMLExport::GetChangeTrackViewSettings(uno::Sequence<beans::PropertyValue> pChangeProps[SC_SHOW_CHANGES_BY_DATETIME].Value <<= pViewSettings->HasDate(); pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_MODE].Name = "ShowChangesByDatetimeMode"; pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_MODE].Value <<= static_cast<sal_Int16>(pViewSettings->GetTheDateMode()); - util::DateTime aDateTime; - ScXMLConverter::ConvertCoreToAPIDateTime(pViewSettings->GetTheFirstDateTime(), aDateTime); pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME].Name = "ShowChangesByDatetimeFirstDatetime"; - pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME].Value <<= aDateTime; - ScXMLConverter::ConvertCoreToAPIDateTime(pViewSettings->GetTheLastDateTime(), aDateTime); + pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME].Value <<= pViewSettings->GetTheFirstDateTime().GetUNODateTime(); pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME].Name = "ShowChangesByDatetimeSecondDatetime"; - pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME].Value <<= aDateTime; + pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME].Value <<= pViewSettings->GetTheLastDateTime().GetUNODateTime(); pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR].Name = "ShowChangesByAuthor"; pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR].Value <<= pViewSettings->HasAuthor(); pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR_NAME].Name = "ShowChangesByAuthorName"; diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 4b6f92b86633..6648144ad157 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -2478,9 +2478,7 @@ void ScXMLImport::SetChangeTrackingViewSettings(const com::sun::star::uno::Seque util::DateTime aDateTime; if (rChangeProps[i].Value >>= aDateTime) { - DateTime aCoreDateTime( DateTime::EMPTY ); - ScXMLConverter::ConvertAPIToCoreDateTime(aDateTime, aCoreDateTime); - pViewSettings->SetTheFirstDateTime(aCoreDateTime); + pViewSettings->SetTheFirstDateTime(::DateTime(aDateTime)); } } else if (sName == "ShowChangesByDatetimeSecondDatetime") @@ -2488,9 +2486,7 @@ void ScXMLImport::SetChangeTrackingViewSettings(const com::sun::star::uno::Seque util::DateTime aDateTime; if (rChangeProps[i].Value >>= aDateTime) { - DateTime aCoreDateTime( DateTime::EMPTY ); - ScXMLConverter::ConvertAPIToCoreDateTime(aDateTime, aCoreDateTime); - pViewSettings->SetTheLastDateTime(aCoreDateTime); + pViewSettings->SetTheLastDateTime(::DateTime(aDateTime)); } } else if (sName == "ShowChangesByAuthor") diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx index f7f7f0f09997..d89701b1f40d 100644 --- a/sc/source/ui/docshell/docsh8.cxx +++ b/sc/source/ui/docshell/docsh8.cxx @@ -1014,8 +1014,7 @@ sal_uLong ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncodi { Date aDate = *(pNumFmt->GetNullDate()); // tools date aDate += (long)fVal; //! approxfloor? - util::Date aUnoDate( aDate.GetDay(), aDate.GetMonth(), aDate.GetYear() ); - xRowUpdate->updateDate( nCol+1, aUnoDate ); + xRowUpdate->updateDate( nCol+1, aDate.GetUNODate() ); } } break; diff --git a/sc/source/ui/miscdlgs/sharedocdlg.cxx b/sc/source/ui/miscdlgs/sharedocdlg.cxx index 87b9bbe89f1c..d934ff77ea27 100644 --- a/sc/source/ui/miscdlgs/sharedocdlg.cxx +++ b/sc/source/ui/miscdlgs/sharedocdlg.cxx @@ -228,9 +228,7 @@ void ScShareDocumentDlg::UpdateView() uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties(); util::DateTime uDT(xDocProps->getModificationDate()); - Date d(uDT.Day, uDT.Month, uDT.Year); - tools::Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); - DateTime aDateTime(d,t); + DateTime aDateTime(uDT); aString += formatTime(aDateTime, *ScGlobal::pLocaleData); aString += " "; diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index 73e21d6f15ad..c5c0f7eee266 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -944,7 +944,7 @@ void ScEditFieldObj::setPropertyValueDateTime(const OUString& rName, const uno:: else if (rName == SC_UNONAME_DATETIME) { maDateTime = rVal.get<util::DateTime>(); - tools::Time aTime(maDateTime.Hours, maDateTime.Minutes, maDateTime.Seconds, maDateTime.NanoSeconds); + tools::Time aTime(maDateTime); p->SetFixTime(aTime); } else if (rName == SC_UNONAME_NUMFMT) |