diff options
author | Michael Stahl <mst@openoffice.org> | 2009-10-09 15:14:09 +0200 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2009-10-09 15:14:09 +0200 |
commit | 609de6a8feea12300005a6b8f4dc29fc00fd2697 (patch) | |
tree | 4e212ed291c62dc41e6e6bc175f3dcdc692fb212 | |
parent | #i105687# enable number format for custom date/datetime/time data (diff) | |
download | core-609de6a8feea12300005a6b8f4dc29fc00fd2697.tar.gz core-609de6a8feea12300005a6b8f4dc29fc00fd2697.zip |
#i97029#: sax::Converter: add convertDateOrDateTime() and convertDate()
-rw-r--r-- | sax/inc/sax/tools/converter.hxx | 15 | ||||
-rw-r--r-- | sax/source/tools/converter.cxx | 71 |
2 files changed, 73 insertions, 13 deletions
diff --git a/sax/inc/sax/tools/converter.hxx b/sax/inc/sax/tools/converter.hxx index 18212dfb9b8b..6632dda8507e 100644 --- a/sax/inc/sax/tools/converter.hxx +++ b/sax/inc/sax/tools/converter.hxx @@ -154,15 +154,26 @@ public: static bool convertTime( ::com::sun::star::util::DateTime& rDateTime, const ::rtl::OUString& rString ); - /** convert util::DateTime to ISO Date String */ + /** convert util::Date to ISO Date String */ + static void convertDate( ::rtl::OUStringBuffer& rBuffer, + const com::sun::star::util::Date& rDate ); + + /** convert util::DateTime to ISO Date or DateTime String */ static void convertDateTime( ::rtl::OUStringBuffer& rBuffer, const com::sun::star::util::DateTime& rDateTime, bool bAddTimeIf0AM = false ); - /** convert ISO Date String to util::DateTime */ + /** convert ISO Date or DateTime String to util::DateTime */ static bool convertDateTime( com::sun::star::util::DateTime& rDateTime, const ::rtl::OUString& rString ); + /** convert ISO Date or DateTime String to util::DateTime or util::Date */ + static bool convertDateOrDateTime( + com::sun::star::util::Date & rDate, + com::sun::star::util::DateTime & rDateTime, + bool & rbDateTime, + const ::rtl::OUString & rString ); + /** gets the position of the first comma after npos in the string rStr. Commas inside '"' pairs are not matched */ static sal_Int32 indexOfComma( const ::rtl::OUString& rStr, diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index 354ee1936094..d7203f61bf20 100644 --- a/sax/source/tools/converter.cxx +++ b/sax/source/tools/converter.cxx @@ -937,7 +937,17 @@ bool Converter::convertTime( ::com::sun::star::util::DateTime& rDateTime, return false; } -/** convert util::DateTime to ISO Date String */ +/** convert util::Date to ISO Date String */ +void Converter::convertDate( + ::rtl::OUStringBuffer& i_rBuffer, + const util::Date& i_rDate) +{ + const util::DateTime dt( + i_rDate.Year, i_rDate.Month, i_rDate.Day, 0, 0, 0, 0); + convertDateTime(i_rBuffer, dt, false); +} + +/** convert util::DateTime to ISO Date or DateTime String */ void Converter::convertDateTime( ::rtl::OUStringBuffer& i_rBuffer, const com::sun::star::util::DateTime& i_rDateTime, @@ -990,9 +1000,36 @@ void Converter::convertDateTime( } } -/** convert ISO Date String to util::DateTime */ -bool Converter::convertDateTime( com::sun::star::util::DateTime& rDateTime, - const ::rtl::OUString& rString ) +/** convert ISO Date or DateTime String to util::DateTime */ +bool Converter::convertDateTime( util::DateTime& rDateTime, + const ::rtl::OUString& rString ) +{ + bool isDateTime; + util::Date date; + if (convertDateOrDateTime(date, rDateTime, isDateTime, rString)) + { + if (!isDateTime) + { + rDateTime.Year = date.Year; + rDateTime.Month = date.Month; + rDateTime.Day = date.Day; + rDateTime.Hours = 0; + rDateTime.Minutes = 0; + rDateTime.Seconds = 0; + rDateTime.HundredthSeconds = 0; + } + return true; + } + else + { + return false; + } +} + +/** convert ISO Date or DateTime String to util::DateTime or util::Date */ +bool Converter::convertDateOrDateTime( + util::Date & rDate, util::DateTime & rDateTime, + bool & rbDateTime, const ::rtl::OUString & rString ) { bool bSuccess = true; @@ -1077,13 +1114,25 @@ bool Converter::convertDateTime( com::sun::star::util::DateTime& rDateTime, if (bSuccess) { - rDateTime.Year = (sal_uInt16)nYear; - rDateTime.Month = (sal_uInt16)nMonth; - rDateTime.Day = (sal_uInt16)nDay; - rDateTime.Hours = (sal_uInt16)nHour; - rDateTime.Minutes = (sal_uInt16)nMin; - rDateTime.Seconds = (sal_uInt16)nSec; - rDateTime.HundredthSeconds = (sal_uInt16)(sDoubleStr.toDouble() * 100); + if ( aTimeStr.getLength() > 0 ) // time is optional + { + rDateTime.Year = static_cast<sal_uInt16>(nYear); + rDateTime.Month = static_cast<sal_uInt16>(nMonth); + rDateTime.Day = static_cast<sal_uInt16>(nDay); + rDateTime.Hours = static_cast<sal_uInt16>(nHour); + rDateTime.Minutes = static_cast<sal_uInt16>(nMin); + rDateTime.Seconds = static_cast<sal_uInt16>(nSec); + rDateTime.HundredthSeconds = + static_cast<sal_uInt16>((sDoubleStr).toDouble() * 100); + rbDateTime = true; + } + else + { + rDate.Year = static_cast<sal_uInt16>(nYear); + rDate.Month = static_cast<sal_uInt16>(nMonth); + rDate.Day = static_cast<sal_uInt16>(nDay); + rbDateTime = false; + } } return bSuccess; } |