summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-01-23 23:10:41 +0100
committerEike Rathke <erack@redhat.com>2015-01-26 18:12:10 +0100
commitcd528c3099ffec4f34565820b923d6385478e44b (patch)
tree3156470b934873bf63307ed2740f4bf73614887f /i18npool
parent15e1c881684c0127c0ca989924bbf2508b4fd780 (diff)
implement css::i18n::XCalendar4 and LocaleCalendar2 service, tdf#63230
Implementation only, new local date/time routines not used yet from the outside in this step.
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/calendarImpl.hxx14
-rw-r--r--i18npool/inc/calendar_gregorian.hxx4
-rw-r--r--i18npool/source/calendar/calendarImpl.cxx23
-rw-r--r--i18npool/source/calendar/calendar_gregorian.cxx34
-rw-r--r--i18npool/source/registerservices/registerservices.cxx3
-rw-r--r--i18npool/util/i18npool.component1
6 files changed, 72 insertions, 7 deletions
diff --git a/i18npool/inc/calendarImpl.hxx b/i18npool/inc/calendarImpl.hxx
index 7ec10debd5ad..0f67c1eb4eea 100644
--- a/i18npool/inc/calendarImpl.hxx
+++ b/i18npool/inc/calendarImpl.hxx
@@ -19,7 +19,7 @@
#ifndef INCLUDED_I18NPOOL_INC_CALENDARIMPL_HXX
#define INCLUDED_I18NPOOL_INC_CALENDARIMPL_HXX
-#include <com/sun/star/i18n/XCalendar3.hpp>
+#include <com/sun/star/i18n/XCalendar4.hpp>
#include <com/sun/star/i18n/CalendarDisplayCode.hpp>
#include <com/sun/star/i18n/CalendarFieldIndex.hpp>
#include <com/sun/star/i18n/CalendarDisplayIndex.hpp>
@@ -36,7 +36,7 @@ namespace com { namespace sun { namespace star { namespace i18n {
class CalendarImpl : public cppu::WeakImplHelper2
<
- com::sun::star::i18n::XCalendar3,
+ com::sun::star::i18n::XCalendar4,
com::sun::star::lang::XServiceInfo
>
{
@@ -84,6 +84,10 @@ public:
virtual com::sun::star::uno::Sequence < CalendarItem2 > SAL_CALL getGenitiveMonths2() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual com::sun::star::uno::Sequence < CalendarItem2 > SAL_CALL getPartitiveMonths2() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ // XCalendar4
+ virtual void SAL_CALL setLocalDateTime(double TimeInDays) throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ virtual double SAL_CALL getLocalDateTime() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
//XServiceInfo
virtual OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
@@ -91,14 +95,14 @@ public:
private:
struct lookupTableItem {
- lookupTableItem(const OUString& _uniqueID, com::sun::star::uno::Reference < com::sun::star::i18n::XCalendar3 >& _xCalendar) :
+ lookupTableItem(const OUString& _uniqueID, com::sun::star::uno::Reference < com::sun::star::i18n::XCalendar4 >& _xCalendar) :
uniqueID(_uniqueID), xCalendar(_xCalendar) {}
OUString uniqueID;
- com::sun::star::uno::Reference < com::sun::star::i18n::XCalendar3 > xCalendar;
+ com::sun::star::uno::Reference < com::sun::star::i18n::XCalendar4 > xCalendar;
};
std::vector<lookupTableItem*> lookupTable;
com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xContext;
- com::sun::star::uno::Reference < com::sun::star::i18n::XCalendar3 > xCalendar;
+ com::sun::star::uno::Reference < com::sun::star::i18n::XCalendar4 > xCalendar;
};
} } } }
diff --git a/i18npool/inc/calendar_gregorian.hxx b/i18npool/inc/calendar_gregorian.hxx
index ea06b007bc4f..f270779f7b87 100644
--- a/i18npool/inc/calendar_gregorian.hxx
+++ b/i18npool/inc/calendar_gregorian.hxx
@@ -85,6 +85,10 @@ public:
virtual com::sun::star::uno::Sequence < CalendarItem2 > SAL_CALL getGenitiveMonths2() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual com::sun::star::uno::Sequence < CalendarItem2 > SAL_CALL getPartitiveMonths2() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ // XCalendar4
+ virtual void SAL_CALL setLocalDateTime(double TimeInDays) throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ virtual double SAL_CALL getLocalDateTime() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
//XServiceInfo
virtual OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
diff --git a/i18npool/source/calendar/calendarImpl.cxx b/i18npool/source/calendar/calendarImpl.cxx
index 4780ce6ad598..68cf9c2116b3 100644
--- a/i18npool/source/calendar/calendarImpl.cxx
+++ b/i18npool/source/calendar/calendarImpl.cxx
@@ -57,7 +57,7 @@ CalendarImpl::loadDefaultCalendar( const Locale& rLocale ) throw(RuntimeExceptio
void SAL_CALL
CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) throw (RuntimeException, std::exception)
{
- Reference < XCalendar3 > xOldCalendar( xCalendar ); // backup
+ Reference < XCalendar4 > xOldCalendar( xCalendar ); // backup
sal_Int32 i;
for (i = 0; i < sal::static_int_cast<sal_Int32>(lookupTable.size()); i++) {
@@ -155,6 +155,24 @@ CalendarImpl::getDateTime() throw(RuntimeException, std::exception)
throw ERROR ;
}
+void SAL_CALL
+CalendarImpl::setLocalDateTime( double fTimeInDays ) throw(RuntimeException, std::exception)
+{
+ if (xCalendar.is())
+ xCalendar->setLocalDateTime( fTimeInDays );
+ else
+ throw ERROR ;
+}
+
+double SAL_CALL
+CalendarImpl::getLocalDateTime() throw(RuntimeException, std::exception)
+{
+ if (xCalendar.is())
+ return xCalendar->getLocalDateTime();
+ else
+ throw ERROR ;
+}
+
OUString SAL_CALL
CalendarImpl::getUniqueID() throw(RuntimeException, std::exception)
{
@@ -352,8 +370,9 @@ CalendarImpl::supportsService(const OUString& rServiceName) throw( RuntimeExcept
Sequence< OUString > SAL_CALL
CalendarImpl::getSupportedServiceNames(void) throw( RuntimeException, std::exception )
{
- Sequence< OUString > aRet(1);
+ Sequence< OUString > aRet(2);
aRet[0] = "com.sun.star.i18n.LocaleCalendar";
+ aRet[1] = "com.sun.star.i18n.LocaleCalendar2";
return aRet;
}
diff --git a/i18npool/source/calendar/calendar_gregorian.cxx b/i18npool/source/calendar/calendar_gregorian.cxx
index a634c5225f89..d2f513c2afff 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -317,6 +317,40 @@ Calendar_gregorian::getDateTime() throw(RuntimeException, std::exception)
return fR / U_MILLIS_PER_DAY;
}
+void SAL_CALL
+Calendar_gregorian::setLocalDateTime( double fTimeInDays ) throw(RuntimeException, std::exception)
+{
+ // See setDateTime() for why the rounding.
+ double fM = fTimeInDays * U_MILLIS_PER_DAY;
+ double fR = rtl::math::round( fM );
+ SAL_INFO_IF( fM != fR, "i18npool",
+ "Calendar_gregorian::setLocalDateTime: " << std::fixed << fM << " rounded to " << fR);
+ int32_t nZoneOffset, nDSTOffset;
+ UErrorCode status;
+ body->getTimeZone().getOffset( fR, TRUE, nZoneOffset, nDSTOffset, status = U_ZERO_ERROR );
+ if ( !U_SUCCESS(status) ) throw ERROR;
+ body->setTime( fR - (nZoneOffset + nDSTOffset), status = U_ZERO_ERROR );
+ if ( !U_SUCCESS(status) ) throw ERROR;
+ getValue();
+}
+
+double SAL_CALL
+Calendar_gregorian::getLocalDateTime() throw(RuntimeException, std::exception)
+{
+ if (fieldSet) {
+ setValue();
+ getValue();
+ }
+ UErrorCode status;
+ double fTime = body->getTime( status = U_ZERO_ERROR );
+ if ( !U_SUCCESS(status) ) throw ERROR;
+ int32_t nZoneOffset = body->get( UCAL_ZONE_OFFSET, status = U_ZERO_ERROR );
+ if ( !U_SUCCESS(status) ) throw ERROR;
+ int32_t nDSTOffset = body->get( UCAL_DST_OFFSET, status = U_ZERO_ERROR );
+ if ( !U_SUCCESS(status) ) throw ERROR;
+ return (fTime + (nZoneOffset + nDSTOffset)) / U_MILLIS_PER_DAY;
+}
+
// map field value from gregorian calendar to other calendar, it can be overwritten by derived class.
// By using eraArray, it can take care Japanese and Taiwan ROC calendar.
void Calendar_gregorian::mapFromGregorian() throw(RuntimeException)
diff --git a/i18npool/source/registerservices/registerservices.cxx b/i18npool/source/registerservices/registerservices.cxx
index 634c71112e03..a38e9692033d 100644
--- a/i18npool/source/registerservices/registerservices.cxx
+++ b/i18npool/source/registerservices/registerservices.cxx
@@ -288,6 +288,9 @@ static const struct InstancesArray {
{ "com.sun.star.i18n.LocaleCalendar",
"com.sun.star.i18n.CalendarImpl",
&CalendarImpl_CreateInstance },
+ { "com.sun.star.i18n.LocaleCalendar2",
+ "com.sun.star.i18n.CalendarImpl",
+ &CalendarImpl_CreateInstance },
{ "com.sun.star.i18n.Calendar_gregorian",
"com.sun.star.i18n.Calendar_gregorian",
&Calendar_gregorian_CreateInstance },
diff --git a/i18npool/util/i18npool.component b/i18npool/util/i18npool.component
index 9617a8b4151b..1b74fd736f54 100644
--- a/i18npool/util/i18npool.component
+++ b/i18npool/util/i18npool.component
@@ -44,6 +44,7 @@
</implementation>
<implementation name="com.sun.star.i18n.CalendarImpl">
<service name="com.sun.star.i18n.LocaleCalendar"/>
+ <service name="com.sun.star.i18n.LocaleCalendar2"/>
</implementation>
<implementation name="com.sun.star.i18n.Calendar_ROC">
<service name="com.sun.star.i18n.Calendar_ROC"/>