From cd528c3099ffec4f34565820b923d6385478e44b Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 23 Jan 2015 23:10:41 +0100 Subject: 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. --- i18npool/source/calendar/calendarImpl.cxx | 23 +++++++++++++-- i18npool/source/calendar/calendar_gregorian.cxx | 34 ++++++++++++++++++++++ .../source/registerservices/registerservices.cxx | 3 ++ 3 files changed, 58 insertions(+), 2 deletions(-) (limited to 'i18npool/source') 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(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 }, -- cgit