summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-07-11 17:27:06 +0200
committerMichael Stahl <mstahl@redhat.com>2013-07-15 15:23:25 +0200
commit20cbf5bd3042ed547408f324e020a3d6405705f7 (patch)
tree5aa9ef1f1b960bd4f5b1013e3db582916fc76c28 /sfx2
parent604aae1fd240254fe851d93dc35b5408bd13296c (diff)
i#108348: support DateTimeWithTimezone in user defined Document Properties
- fix interface of sax::Converter to allow passing time zones (rename the parsing methods while at it to reduce pointless overloading) - SfxDocumentMetaData supports DateWithTimezone and DateTimeWithTimezone in user-defined properties - add some ugly hacks to SfxCustomPropertiesPage to preserve existing time zones (which are not displayed in UI currently) Change-Id: Ice94112b9d79c285f80b5beda15f0ace91db97f3
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/dialog/dinfdlg.cxx68
-rw-r--r--sfx2/source/doc/SfxDocumentMetaData.cxx75
2 files changed, 103 insertions, 40 deletions
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
index c741c3959e4a..33c968d94e6d 100644
--- a/sfx2/source/dialog/dinfdlg.cxx
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -41,7 +41,8 @@
#include <com/sun/star/beans/XPropertyContainer.hpp>
#include <com/sun/star/util/DateTime.hpp>
#include <com/sun/star/util/Date.hpp>
-#include <com/sun/star/util/Time.hpp>
+#include <com/sun/star/util/DateTimeWithTimezone.hpp>
+#include <com/sun/star/util/DateWithTimezone.hpp>
#include <com/sun/star/util/Duration.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
@@ -1715,6 +1716,8 @@ void CustomPropertiesWindow::AddLine( const OUString& sName, Any& rAny )
OUString sTmpValue;
util::DateTime aTmpDateTime;
util::Date aTmpDate;
+ util::DateTimeWithTimezone aTmpDateTimeTZ;
+ util::DateWithTimezone aTmpDateTZ;
util::Duration aTmpDuration;
SvtSysLocale aSysLocale;
const LocaleDataWrapper& rLocaleWrapper = aSysLocale.GetLocaleData();
@@ -1741,22 +1744,38 @@ void CustomPropertiesWindow::AddLine( const OUString& sName, Any& rAny )
}
else if ( rAny >>= aTmpDate )
{
- nType = CUSTOM_TYPE_DATE;
pNewLine->m_aDateField.SetDate( Date( aTmpDate.Day, aTmpDate.Month, aTmpDate.Year ) );
-
- }
- else if ( rAny >>= aTmpDuration )
- {
- nType = CUSTOM_TYPE_DURATION;
- pNewLine->m_aDurationField.SetDuration( aTmpDuration );
+ nType = CUSTOM_TYPE_DATE;
}
else if ( rAny >>= aTmpDateTime )
{
pNewLine->m_aDateField.SetDate( Date( aTmpDateTime.Day, aTmpDateTime.Month, aTmpDateTime.Year ) );
pNewLine->m_aTimeField.SetTime( Time( aTmpDateTime.Hours, aTmpDateTime.Minutes, aTmpDateTime.Seconds, aTmpDateTime.NanoSeconds ) );
-
+ pNewLine->m_aTimeField.m_isUTC = aTmpDateTime.IsUTC;
nType = CUSTOM_TYPE_DATETIME;
}
+ else if ( rAny >>= aTmpDateTZ )
+ {
+ pNewLine->m_aDateField.SetDate( Date( aTmpDateTZ.DateInTZ.Day,
+ aTmpDateTZ.DateInTZ.Month, aTmpDateTZ.DateInTZ.Year ) );
+ pNewLine->m_aDateField.m_TZ = aTmpDateTZ.Timezone;
+ nType = CUSTOM_TYPE_DATE;
+ }
+ else if ( rAny >>= aTmpDateTimeTZ )
+ {
+ util::DateTime const& rDT(aTmpDateTimeTZ.DateTimeInTZ);
+ pNewLine->m_aDateField.SetDate( Date( rDT.Day, rDT.Month, rDT.Year ) );
+ pNewLine->m_aTimeField.SetTime( Time( rDT.Hours, rDT.Minutes,
+ rDT.Seconds, rDT.NanoSeconds ) );
+ pNewLine->m_aTimeField.m_isUTC = rDT.IsUTC;
+ pNewLine->m_aDateField.m_TZ = aTmpDateTimeTZ.Timezone;
+ nType = CUSTOM_TYPE_DATETIME;
+ }
+ else if ( rAny >>= aTmpDuration )
+ {
+ nType = CUSTOM_TYPE_DURATION;
+ pNewLine->m_aDurationField.SetDuration( aTmpDuration );
+ }
if ( nType != CUSTOM_TYPE_UNKNOWN )
{
@@ -1870,20 +1889,35 @@ Sequence< beans::PropertyValue > CustomPropertiesWindow::GetCustomProperties() c
util::DateTime const aDateTime(aTmpTime.GetNanoSec(),
aTmpTime.GetSec(), aTmpTime.GetMin(), aTmpTime.GetHour(),
aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear(),
- false);
- aPropertiesSeq[i].Value <<= aDateTime;
- }
- else if ( CUSTOM_TYPE_DURATION == nType )
- {
- aPropertiesSeq[i].Value <<= pLine->m_aDurationField.GetDuration();
+ pLine->m_aTimeField.m_isUTC);
+ if (pLine->m_aDateField.m_TZ.is_initialized())
+ {
+ aPropertiesSeq[i].Value <<= util::DateTimeWithTimezone(
+ aDateTime, pLine->m_aDateField.m_TZ.get());
+ }
+ else
+ {
+ aPropertiesSeq[i].Value <<= aDateTime;
+ }
}
else if ( CUSTOM_TYPE_DATE == nType )
{
Date aTmpDate = pLine->m_aDateField.GetDate();
util::Date const aDate(aTmpDate.GetDay(), aTmpDate.GetMonth(),
aTmpDate.GetYear());
- aPropertiesSeq[i].Value <<= aDate;
-
+ if (pLine->m_aDateField.m_TZ.is_initialized())
+ {
+ aPropertiesSeq[i].Value <<= util::DateWithTimezone(
+ aDate, pLine->m_aDateField.m_TZ.get());
+ }
+ else
+ {
+ aPropertiesSeq[i].Value <<= aDate;
+ }
+ }
+ else if ( CUSTOM_TYPE_DURATION == nType )
+ {
+ aPropertiesSeq[i].Value <<= pLine->m_aDurationField.GetDuration();
}
else
{
diff --git a/sfx2/source/doc/SfxDocumentMetaData.cxx b/sfx2/source/doc/SfxDocumentMetaData.cxx
index 520db84f3e12..f1fe1233b4a0 100644
--- a/sfx2/source/doc/SfxDocumentMetaData.cxx
+++ b/sfx2/source/doc/SfxDocumentMetaData.cxx
@@ -54,6 +54,8 @@
#include "com/sun/star/xml/xpath/XPathAPI.hpp"
#include "com/sun/star/util/Date.hpp"
#include "com/sun/star/util/Time.hpp"
+#include "com/sun/star/util/DateWithTimezone.hpp"
+#include "com/sun/star/util/DateTimeWithTimezone.hpp"
#include "com/sun/star/util/Duration.hpp"
#include "SfxDocumentMetaData.hxx"
@@ -530,10 +532,11 @@ OUString SAL_CALL getNameSpace(const char* i_qname) throw ()
bool SAL_CALL
textToDateOrDateTime(css::util::Date & io_rd, css::util::DateTime & io_rdt,
- bool & o_rIsDateTime, OUString i_text) throw ()
+ bool & o_rIsDateTime, boost::optional<sal_Int16> & o_rTimeZone,
+ OUString i_text) throw ()
{
- if (::sax::Converter::convertDateOrDateTime(
- io_rd, io_rdt, o_rIsDateTime, i_text)) {
+ if (::sax::Converter::parseDateOrDateTime(
+ &io_rd, io_rdt, o_rIsDateTime, &o_rTimeZone, i_text)) {
return true;
} else {
DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
@@ -546,7 +549,7 @@ textToDateOrDateTime(css::util::Date & io_rd, css::util::DateTime & io_rdt,
bool SAL_CALL
textToDateTime(css::util::DateTime & io_rdt, OUString i_text) throw ()
{
- if (::sax::Converter::convertDateTime(io_rdt, i_text)) {
+ if (::sax::Converter::parseDateTime(io_rdt, 0, i_text)) {
return true;
} else {
DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
@@ -567,11 +570,12 @@ textToDateTimeDefault(OUString i_text) throw ()
// convert date to string
OUString SAL_CALL
-dateToText(css::util::Date const& i_rd) throw ()
+dateToText(css::util::Date const& i_rd,
+ sal_Int16 const*const pTimeZone = 0) throw ()
{
if (isValidDate(i_rd)) {
OUStringBuffer buf;
- ::sax::Converter::convertDate(buf, i_rd);
+ ::sax::Converter::convertDate(buf, i_rd, pTimeZone);
return buf.makeStringAndClear();
} else {
return OUString();
@@ -581,11 +585,12 @@ dateToText(css::util::Date const& i_rd) throw ()
// convert date/time to string
OUString SAL_CALL
-dateTimeToText(css::util::DateTime const& i_rdt) throw ()
+dateTimeToText(css::util::DateTime const& i_rdt,
+ sal_Int16 const*const pTimeZone = 0) throw ()
{
if (isValidDateTime(i_rdt)) {
OUStringBuffer buf;
- ::sax::Converter::convertDateTime(buf, i_rdt, true);
+ ::sax::Converter::convertDateTime(buf, i_rdt, pTimeZone, true);
return buf.makeStringAndClear();
} else {
return OUString();
@@ -960,6 +965,18 @@ propsToStrings(css::uno::Reference<css::beans::XPropertySet> const & i_xPropSet)
values.push_back(dateToText(d));
as.push_back(std::make_pair(vt,
OUString("date")));
+ } else if (type == ::cppu::UnoType<css::util::DateTimeWithTimezone>::get()) {
+ css::util::DateTimeWithTimezone dttz;
+ any >>= dttz;
+ values.push_back(dateTimeToText(dttz.DateTimeInTZ, &dttz.Timezone));
+ as.push_back(std::make_pair(vt,
+ OUString("date")));
+ } else if (type == ::cppu::UnoType<css::util::DateWithTimezone>::get()) {
+ css::util::DateWithTimezone dtz;
+ any >>= dtz;
+ values.push_back(dateToText(dtz.DateInTZ, &dtz.Timezone));
+ as.push_back(std::make_pair(vt,
+ OUString("date")));
} else if (type == ::cppu::UnoType<css::util::Time>::get()) {
// #i97029#: replaced by Duration
// Time is supported for backward compatibility with OOo 3.x, x<=2
@@ -1293,11 +1310,21 @@ void SAL_CALL SfxDocumentMetaData::init(
bool isDateTime;
css::util::Date d;
css::util::DateTime dt;
- if (textToDateOrDateTime(d, dt, isDateTime, text)) {
+ boost::optional<sal_Int16> nTimeZone;
+ if (textToDateOrDateTime(d, dt, isDateTime, nTimeZone, text)) {
if (isDateTime) {
- any <<= dt;
+ if (nTimeZone.is_initialized()) {
+ any <<= css::util::DateTimeWithTimezone(dt,
+ nTimeZone.get());
+ } else {
+ any <<= dt;
+ }
} else {
- any <<= d;
+ if (nTimeZone.is_initialized()) {
+ any <<= css::util::DateWithTimezone(d, nTimeZone.get());
+ } else {
+ any <<= d;
+ }
}
} else {
DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
@@ -2261,19 +2288,21 @@ void SfxDocumentMetaData::createUserDefined()
// values of allowed types
if ( !m_xUserDefined.is() )
{
- css::uno::Sequence<css::uno::Type> types(11);
- types[0] = ::cppu::UnoType<bool>::get();
- types[1] = ::cppu::UnoType< OUString>::get();
- types[2] = ::cppu::UnoType<css::util::DateTime>::get();
- types[3] = ::cppu::UnoType<css::util::Date>::get();
- types[4] = ::cppu::UnoType<css::util::Duration>::get();
- types[5] = ::cppu::UnoType<float>::get();
- types[6] = ::cppu::UnoType<double>::get();
- types[7] = ::cppu::UnoType<sal_Int16>::get();
- types[8] = ::cppu::UnoType<sal_Int32>::get();
- types[9] = ::cppu::UnoType<sal_Int64>::get();
+ css::uno::Sequence<css::uno::Type> types(13);
+ types[ 0] = ::cppu::UnoType<bool>::get();
+ types[ 1] = ::cppu::UnoType< OUString>::get();
+ types[ 2] = ::cppu::UnoType<css::util::DateTime>::get();
+ types[ 3] = ::cppu::UnoType<css::util::Date>::get();
+ types[ 4] = ::cppu::UnoType<css::util::DateTimeWithTimezone>::get();
+ types[ 5] = ::cppu::UnoType<css::util::DateWithTimezone>::get();
+ types[ 6] = ::cppu::UnoType<css::util::Duration>::get();
+ types[ 7] = ::cppu::UnoType<float>::get();
+ types[ 8] = ::cppu::UnoType<double>::get();
+ types[ 9] = ::cppu::UnoType<sal_Int16>::get();
+ types[10] = ::cppu::UnoType<sal_Int32>::get();
+ types[11] = ::cppu::UnoType<sal_Int64>::get();
// Time is supported for backward compatibility with OOo 3.x, x<=2
- types[10] = ::cppu::UnoType<css::util::Time>::get();
+ types[12] = ::cppu::UnoType<css::util::Time>::get();
// #i94175#: ODF allows empty user-defined property names!
m_xUserDefined.set(
css::beans::PropertyBag::createWithTypes( m_xContext, types, sal_True/*AllowEmptyPropertyName*/, sal_False/*AutomaticAddition*/ ),