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.
This commit is contained in:
Eike Rathke 2015-01-23 23:10:41 +01:00
parent 15e1c88168
commit cd528c3099
14 changed files with 191 additions and 34 deletions

View file

@ -57,7 +57,7 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/i18n/LocaleCalendar.hpp>
#include <com/sun/star/i18n/LocaleCalendar2.hpp>
#include <com/sun/star/sheet/XFunctionAccess.hpp>
#include <boost/scoped_array.hpp>
@ -67,13 +67,13 @@ using namespace com::sun::star::lang;
using namespace com::sun::star::sheet;
using namespace com::sun::star::uno;
static Reference< XCalendar3 > getLocaleCalendar( void )
static Reference< XCalendar4 > getLocaleCalendar( void )
{
static Reference< XCalendar3 > xCalendar;
static Reference< XCalendar4 > xCalendar;
if( !xCalendar.is() )
{
Reference< XComponentContext > xContext = getProcessComponentContext();
xCalendar = LocaleCalendar::create(xContext);
xCalendar = LocaleCalendar2::create(xContext);
}
static com::sun::star::lang::Locale aLastLocale;
@ -1857,7 +1857,7 @@ RTLFUNC(MonthName)
return;
}
Reference< XCalendar3 > xCalendar = getLocaleCalendar();
Reference< XCalendar4 > xCalendar = getLocaleCalendar();
if( !xCalendar.is() )
{
StarBASIC::Error( SbERR_INTERNAL_ERROR );
@ -1897,7 +1897,7 @@ RTLFUNC(WeekdayName)
return;
}
Reference< XCalendar3 > xCalendar = getLocaleCalendar();
Reference< XCalendar4 > xCalendar = getLocaleCalendar();
if( !xCalendar.is() )
{
StarBASIC::Error( SbERR_INTERNAL_ERROR );
@ -2246,7 +2246,7 @@ RTLFUNC(DateDiff)
}
if( nFirstDay == 0 )
{
Reference< XCalendar3 > xCalendar = getLocaleCalendar();
Reference< XCalendar4 > xCalendar = getLocaleCalendar();
if( !xCalendar.is() )
{
StarBASIC::Error( SbERR_INTERNAL_ERROR );
@ -2304,7 +2304,7 @@ double implGetDateOfFirstDayInFirstWeek
if( nFirstWeek < 0 || nFirstWeek > 3 )
nError = SbERR_BAD_ARGUMENT;
Reference< XCalendar3 > xCalendar;
Reference< XCalendar4 > xCalendar;
if( nFirstDay == 0 || nFirstWeek == 0 )
{
xCalendar = getLocaleCalendar();
@ -2505,7 +2505,7 @@ RTLFUNC(FormatDateTime)
}
}
Reference< XCalendar3 > xCalendar = getLocaleCalendar();
Reference< XCalendar4 > xCalendar = getLocaleCalendar();
if( !xCalendar.is() )
{
StarBASIC::Error( SbERR_INTERNAL_ERROR );
@ -3329,7 +3329,7 @@ sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam, sal_Int16 nFirstDay
}
if( nFirstDay == 0 )
{
Reference< XCalendar3 > xCalendar = getLocaleCalendar();
Reference< XCalendar4 > xCalendar = getLocaleCalendar();
if( !xCalendar.is() )
{
#if HAVE_FEATURE_SCRIPTING

View file

@ -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;
};
} } } }

View file

@ -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;

View file

@ -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;
}

View file

@ -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)

View file

@ -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 },

View file

@ -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"/>

View file

@ -35,13 +35,13 @@ namespace com { namespace sun { namespace star {
namespace com { namespace sun { namespace star {
namespace i18n {
class XCalendar3;
class XCalendar4;
}
}}}
class UNOTOOLS_DLLPUBLIC CalendarWrapper
{
::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCalendar3 > xC;
::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCalendar4 > xC;
DateTime aEpochStart; // 1Jan1970
@ -61,10 +61,9 @@ public:
void setDateTime( double fTimeInDays );
/// get UTC date/time
double getDateTime() const;
/// convenience method to set local date/time
void setLocalDateTime( double fTimeInDays );
/// convenience method to get local date/time
double getLocalDateTime() const;
// For local setDateTime() and getDateTime() see further down at wrapper
// implementations of XCalendar4.
// wrapper implementations of XCalendar
@ -96,6 +95,13 @@ public:
::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getGenitiveMonths() const;
::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getPartitiveMonths() const;
// wrapper implementations of XCalendar4
/// set local date/time
void setLocalDateTime( double fTimeInDays );
/// get local date/time
double getLocalDateTime() const;
// convenience methods
/// get epoch start (should be 01Jan1970)

View file

@ -224,6 +224,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/i18n,\
IndexEntrySupplier \
InputSequenceChecker \
LocaleCalendar \
LocaleCalendar2 \
LocaleData \
NativeNumberSupplier \
NumberFormatMapper \
@ -2752,6 +2753,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/i18n,\
XBreakIterator \
XCalendar \
XCalendar3 \
XCalendar4 \
XCharacterClassification \
XCollator \
XExtendedCalendar \

View file

@ -0,0 +1,27 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef __com_sun_star_i18n_LocaleCalendar2_idl__
#define __com_sun_star_i18n_LocaleCalendar2_idl__
#include <com/sun/star/i18n/XCalendar4.idl>
module com { module sun { module star { module i18n {
/** Access a locale specific calendar.
@since LibreOffice 4.5
*/
published service LocaleCalendar2 : XCalendar4;
}; }; }; };
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -53,17 +53,17 @@ published interface XCalendar : com::sun::star::uno::XInterface
string getUniqueID();
/**
Set the date/time as an offset to the start of the calendar at
1-Jan-1970 00:00. The integer part represents the number of days
passed since start date. The fractional part represents
Set the UTC date/time as an offset to the start of the calendar
at 1-Jan-1970 00:00. The integer part represents the number of
days passed since start date. The fractional part represents
fractions of a day, thus 0.5 means 12 hours.
*/
void setDateTime( [in] double nTimeInDays );
/**
Get the date/time as an offset to the start of the calendar at
1-Jan-1970 00:00. The integer part represents the number of days
passed since start date. The fractional part represents
Get the UTC date/time as an offset to the start of the calendar
at 1-Jan-1970 00:00. The integer part represents the number of
days passed since start date. The fractional part represents
fractions of a day, thus 0.5 means 12 hours.
*/
double getDateTime();

View file

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef __com_sun_star_i18n_XCalendar4_idl__
#define __com_sun_star_i18n_XCalendar4_idl__
#include <com/sun/star/i18n/Calendar3.idl>
module com { module sun { module star { module i18n {
/** This interface provides access to locale specific calendar
systems.
<p> It is derived from ::com::sun::star::i18n::XCalendar3 and
provides additional methods to set and get the local time. </p>
@since LibreOffice 4.5
*/
published interface XCalendar4 : com::sun::star::i18n::XCalendar3
{
/** Set the local date/time as an offset to the start of the
calendar at 1-Jan-1970 00:00. The integer part represents the
number of days passed since start date. The fractional part
represents fractions of a day, thus 0.5 means 12 hours.
The actual timezone and daylight saving time offsets effective
at the given date and time are considered and subtracted before
setting the UTC time at the calendar.
*/
void setLocalDateTime( [in] double TimeInDays );
/** Get the local date/time as an offset to the start of the
calendar at 1-Jan-1970 00:00. The integer part represents the
number of days passed since start date. The fractional part
represents fractions of a day, thus 0.5 means 12 hours.
The actual timezone and daylight saving time offsets effective
at the given date and time are considered and added to the UTC
time at the calendar.
*/
double getLocalDateTime();
};
}; }; }; };
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -28,7 +28,7 @@
#include <unotools/calendarwrapper.hxx>
#include <unotools/localedatawrapper.hxx>
#include <com/sun/star/i18n/CalendarFieldIndex.hpp>
#include <com/sun/star/i18n/LocaleCalendar.hpp>
#include <com/sun/star/i18n/LocaleCalendar2.hpp>
#include <unotools/digitgroupingiterator.hxx>
#include <svl/zforlist.hxx>
@ -44,7 +44,7 @@
#endif
#if NF_TEST_CALENDAR
#include <comphelper/processfactory.hxx>
#include <com/sun/star/i18n/XCalendar3.hpp>
#include <com/sun/star/i18n/XCalendar4.hpp>
#endif
@ -1974,7 +1974,7 @@ input for the following reasons:
sal_Int32 nZoneInMillis, nDST1InMillis, nDST2InMillis;
uno::Reference< uno::XComponentContext > xContext =
::comphelper::getProcessComponentContext();
uno::Reference< i18n::XCalendar3 > xCal = i18n::LocaleCalendar::create(xContext);
uno::Reference< i18n::XCalendar4 > xCal = i18n::LocaleCalendar2::create(xContext);
for ( const entry* p = cals; p->lan; ++p )
{
aLocale.Language = OUString::createFromAscii( p->lan );

View file

@ -20,7 +20,7 @@
#include <rtl/strbuf.hxx>
#include <unotools/calendarwrapper.hxx>
#include <com/sun/star/i18n/CalendarFieldIndex.hpp>
#include <com/sun/star/i18n/LocaleCalendar.hpp>
#include <com/sun/star/i18n/LocaleCalendar2.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::i18n;
@ -34,7 +34,7 @@ CalendarWrapper::CalendarWrapper(
:
aEpochStart( Date( 1, 1, 1970 ) )
{
xC = LocaleCalendar::create(rxContext);
xC = LocaleCalendar2::create(rxContext);
}
CalendarWrapper::~CalendarWrapper()