1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b5088357SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b5088357SAndrew Rist  * distributed with this work for additional information
6*b5088357SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b5088357SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist  * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b5088357SAndrew Rist  *
11*b5088357SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist  *
13*b5088357SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist  * software distributed under the License is distributed on an
15*b5088357SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b5088357SAndrew Rist  * specific language governing permissions and limitations
18*b5088357SAndrew Rist  * under the License.
19*b5088357SAndrew Rist  *
20*b5088357SAndrew Rist  *************************************************************/
21*b5088357SAndrew Rist 
22*b5088357SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <unotools/calendarwrapper.hxx>
28cdf0e10cSrcweir #include <tools/string.hxx>
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef _COMPHELPER_COMPONENTFACTORY_HXX_
32cdf0e10cSrcweir #include <comphelper/componentfactory.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <com/sun/star/i18n/CalendarFieldIndex.hpp>
35cdf0e10cSrcweir #include <com/sun/star/i18n/XExtendedCalendar.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #define CALENDAR_LIBRARYNAME "i18n"
39cdf0e10cSrcweir #define CALENDAR_SERVICENAME "com.sun.star.i18n.LocaleCalendar"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir using namespace ::com::sun::star::i18n;
44cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir const double MILLISECONDS_PER_DAY = 1000.0 * 60.0 * 60.0 * 24.0;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
CalendarWrapper(const Reference<lang::XMultiServiceFactory> & xSF)50cdf0e10cSrcweir CalendarWrapper::CalendarWrapper(
51cdf0e10cSrcweir 			const Reference< lang::XMultiServiceFactory > & xSF
52cdf0e10cSrcweir 			)
53cdf0e10cSrcweir 		:
54cdf0e10cSrcweir 		xSMgr( xSF ),
55cdf0e10cSrcweir 		aEpochStart( Date( 1, 1, 1970 ) )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	if ( xSMgr.is() )
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 		try
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 			xC = Reference< XExtendedCalendar > ( xSMgr->createInstance(
62cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CALENDAR_SERVICENAME ) ) ),
63cdf0e10cSrcweir 				uno::UNO_QUERY );
64cdf0e10cSrcweir 		}
65cdf0e10cSrcweir 		catch ( Exception& e )
66cdf0e10cSrcweir 		{
67cdf0e10cSrcweir #ifdef DBG_UTIL
68cdf0e10cSrcweir 			ByteString aMsg( "CalendarWrapper ctor: Exception caught\n" );
69cdf0e10cSrcweir 			aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
70cdf0e10cSrcweir 			DBG_ERRORFILE( aMsg.GetBuffer() );
71cdf0e10cSrcweir #else
72cdf0e10cSrcweir 			(void)e;
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir 		}
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 	else
77cdf0e10cSrcweir 	{	// try to get an instance somehow
78cdf0e10cSrcweir 		DBG_ERRORFILE( "CalendarWrapper: no service manager, trying own" );
79cdf0e10cSrcweir 		try
80cdf0e10cSrcweir 		{
81cdf0e10cSrcweir 			Reference< XInterface > xI = ::comphelper::getComponentInstance(
82cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( CALENDAR_LIBRARYNAME ) ) ),
83cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CALENDAR_SERVICENAME ) ) );
84cdf0e10cSrcweir 			if ( xI.is() )
85cdf0e10cSrcweir 			{
86cdf0e10cSrcweir 				Any x = xI->queryInterface( ::getCppuType((const Reference< XExtendedCalendar >*)0) );
87cdf0e10cSrcweir 				x >>= xC;
88cdf0e10cSrcweir 			}
89cdf0e10cSrcweir 		}
90cdf0e10cSrcweir 		catch ( Exception& e )
91cdf0e10cSrcweir 		{
92cdf0e10cSrcweir #ifdef DBG_UTIL
93cdf0e10cSrcweir 			ByteString aMsg( "getComponentInstance: Exception caught\n" );
94cdf0e10cSrcweir 			aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
95cdf0e10cSrcweir 			DBG_ERRORFILE( aMsg.GetBuffer() );
96cdf0e10cSrcweir #else
97cdf0e10cSrcweir 			(void)e;
98cdf0e10cSrcweir #endif
99cdf0e10cSrcweir 		}
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
~CalendarWrapper()104cdf0e10cSrcweir CalendarWrapper::~CalendarWrapper()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
loadDefaultCalendar(const::com::sun::star::lang::Locale & rLocale)109cdf0e10cSrcweir void CalendarWrapper::loadDefaultCalendar( const ::com::sun::star::lang::Locale& rLocale )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	try
112cdf0e10cSrcweir 	{
113cdf0e10cSrcweir 		if ( xC.is() )
114cdf0e10cSrcweir 			xC->loadDefaultCalendar( rLocale );
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 	catch ( Exception& e )
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir #ifdef DBG_UTIL
119cdf0e10cSrcweir 		ByteString aMsg( "loadDefaultCalendar: Exception caught\n" );
120cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
121cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
122cdf0e10cSrcweir #else
123cdf0e10cSrcweir 		(void)e;
124cdf0e10cSrcweir #endif
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
loadCalendar(const::rtl::OUString & rUniqueID,const::com::sun::star::lang::Locale & rLocale)129cdf0e10cSrcweir void CalendarWrapper::loadCalendar( const ::rtl::OUString& rUniqueID, const ::com::sun::star::lang::Locale& rLocale )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	try
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		if ( xC.is() )
134cdf0e10cSrcweir 			xC->loadCalendar( rUniqueID, rLocale );
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 	catch ( Exception& e )
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir #ifdef DBG_UTIL
139cdf0e10cSrcweir 		ByteString aMsg( "loadCalendar: Exception caught\nrequested: " );
140cdf0e10cSrcweir 		aMsg += ByteString( String( rUniqueID ), RTL_TEXTENCODING_UTF8 );
141cdf0e10cSrcweir 		aMsg += "   Locale: ";
142cdf0e10cSrcweir 		aMsg += ByteString( String( rLocale.Language ), RTL_TEXTENCODING_UTF8 );
143cdf0e10cSrcweir 		aMsg += '_';
144cdf0e10cSrcweir 		aMsg += ByteString( String( rLocale.Country ), RTL_TEXTENCODING_UTF8 );
145cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
146cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
147cdf0e10cSrcweir #else
148cdf0e10cSrcweir 		(void)e;
149cdf0e10cSrcweir #endif
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
getLoadedCalendar() const154cdf0e10cSrcweir ::com::sun::star::i18n::Calendar CalendarWrapper::getLoadedCalendar() const
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	try
157cdf0e10cSrcweir 	{
158cdf0e10cSrcweir 		if ( xC.is() )
159cdf0e10cSrcweir 			return xC->getLoadedCalendar();
160cdf0e10cSrcweir 	}
161cdf0e10cSrcweir 	catch ( Exception& e )
162cdf0e10cSrcweir 	{
163cdf0e10cSrcweir #ifdef DBG_UTIL
164cdf0e10cSrcweir 		ByteString aMsg( "getLoadedCalendar: Exception caught\n" );
165cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
166cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
167cdf0e10cSrcweir #else
168cdf0e10cSrcweir         (void)e;
169cdf0e10cSrcweir #endif
170cdf0e10cSrcweir 	}
171cdf0e10cSrcweir 	return ::com::sun::star::i18n::Calendar();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 
getAllCalendars(const::com::sun::star::lang::Locale & rLocale) const175cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > CalendarWrapper::getAllCalendars( const ::com::sun::star::lang::Locale& rLocale ) const
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	try
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir 		if ( xC.is() )
180cdf0e10cSrcweir 			return xC->getAllCalendars( rLocale );
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 	catch ( Exception& e )
183cdf0e10cSrcweir 	{
184cdf0e10cSrcweir #ifdef DBG_UTIL
185cdf0e10cSrcweir 		ByteString aMsg( "getAllCalendars: Exception caught\n" );
186cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
187cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
188cdf0e10cSrcweir #else
189cdf0e10cSrcweir         (void)e;
190cdf0e10cSrcweir #endif
191cdf0e10cSrcweir 	}
192cdf0e10cSrcweir 	return ::com::sun::star::uno::Sequence< ::rtl::OUString > (0);
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
getUniqueID() const196cdf0e10cSrcweir ::rtl::OUString CalendarWrapper::getUniqueID() const
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	try
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		if ( xC.is() )
201cdf0e10cSrcweir 			return xC->getUniqueID();
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 	catch ( Exception& e )
204cdf0e10cSrcweir 	{
205cdf0e10cSrcweir #ifdef DBG_UTIL
206cdf0e10cSrcweir 		ByteString aMsg( "getUniqueID: Exception caught\n" );
207cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
208cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
209cdf0e10cSrcweir #else
210cdf0e10cSrcweir         (void)e;
211cdf0e10cSrcweir #endif
212cdf0e10cSrcweir 	}
213cdf0e10cSrcweir 	return ::rtl::OUString();
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
setDateTime(double nTimeInDays)217cdf0e10cSrcweir void CalendarWrapper::setDateTime( double nTimeInDays )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	try
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir 		if ( xC.is() )
222cdf0e10cSrcweir 			xC->setDateTime( nTimeInDays );
223cdf0e10cSrcweir 	}
224cdf0e10cSrcweir 	catch ( Exception& e )
225cdf0e10cSrcweir 	{
226cdf0e10cSrcweir #ifdef DBG_UTIL
227cdf0e10cSrcweir 		ByteString aMsg( "setDateTime: Exception caught\n" );
228cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
229cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
230cdf0e10cSrcweir #else
231cdf0e10cSrcweir         (void)e;
232cdf0e10cSrcweir #endif
233cdf0e10cSrcweir 	}
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 
getDateTime() const237cdf0e10cSrcweir double CalendarWrapper::getDateTime() const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir 	try
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 		if ( xC.is() )
242cdf0e10cSrcweir 			return xC->getDateTime();
243cdf0e10cSrcweir 	}
244cdf0e10cSrcweir 	catch ( Exception& e )
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir #ifdef DBG_UTIL
247cdf0e10cSrcweir 		ByteString aMsg( "getDateTime: Exception caught\n" );
248cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
249cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
250cdf0e10cSrcweir #else
251cdf0e10cSrcweir         (void)e;
252cdf0e10cSrcweir #endif
253cdf0e10cSrcweir 	}
254cdf0e10cSrcweir 	return 0.0;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 
getCombinedOffsetInMillis(sal_Int16 nParentFieldIndex,sal_Int16 nChildFieldIndex) const258cdf0e10cSrcweir sal_Int32 CalendarWrapper::getCombinedOffsetInMillis(
259cdf0e10cSrcweir         sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     sal_Int32 nOffset = 0;
262cdf0e10cSrcweir     try
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         if ( xC.is() )
265cdf0e10cSrcweir         {
266cdf0e10cSrcweir             nOffset = static_cast<sal_Int32>( xC->getValue( nParentFieldIndex )) * 60000;
267cdf0e10cSrcweir             sal_Int16 nSecondMillis = xC->getValue( nChildFieldIndex );
268cdf0e10cSrcweir             if (nOffset < 0)
269cdf0e10cSrcweir                 nOffset -= static_cast<sal_uInt16>( nSecondMillis);
270cdf0e10cSrcweir             else
271cdf0e10cSrcweir                 nOffset += static_cast<sal_uInt16>( nSecondMillis);
272cdf0e10cSrcweir         }
273cdf0e10cSrcweir     }
274cdf0e10cSrcweir     catch ( Exception& e )
275cdf0e10cSrcweir     {
276cdf0e10cSrcweir #ifdef DBG_UTIL
277cdf0e10cSrcweir         ByteString aMsg( "setLocalDateTime: Exception caught\n" );
278cdf0e10cSrcweir         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
279cdf0e10cSrcweir         DBG_ERRORFILE( aMsg.GetBuffer() );
280cdf0e10cSrcweir #else
281cdf0e10cSrcweir         (void)e;
282cdf0e10cSrcweir #endif
283cdf0e10cSrcweir     }
284cdf0e10cSrcweir     return nOffset;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 
getZoneOffsetInMillis() const288cdf0e10cSrcweir sal_Int32 CalendarWrapper::getZoneOffsetInMillis() const
289cdf0e10cSrcweir {
290cdf0e10cSrcweir     return getCombinedOffsetInMillis( CalendarFieldIndex::ZONE_OFFSET,
291cdf0e10cSrcweir             CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS);
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 
getDSTOffsetInMillis() const295cdf0e10cSrcweir sal_Int32 CalendarWrapper::getDSTOffsetInMillis() const
296cdf0e10cSrcweir {
297cdf0e10cSrcweir     return getCombinedOffsetInMillis( CalendarFieldIndex::DST_OFFSET,
298cdf0e10cSrcweir             CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS);
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 
setLocalDateTime(double nTimeInDays)302cdf0e10cSrcweir void CalendarWrapper::setLocalDateTime( double nTimeInDays )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     try
305cdf0e10cSrcweir     {
306cdf0e10cSrcweir         if ( xC.is() )
307cdf0e10cSrcweir         {
308cdf0e10cSrcweir             // First set a nearby value to obtain the timezone and DST offset.
309cdf0e10cSrcweir             // This is necessary to let ICU choose the corresponding
310cdf0e10cSrcweir             // OlsonTimeZone transitions. Since ICU incorporates also
311cdf0e10cSrcweir             // historical data even the timezone may differ for different
312cdf0e10cSrcweir             // dates! (Which was the cause for #i76623# when the timezone of a
313cdf0e10cSrcweir             // previously set date was used.) Timezone may also include
314cdf0e10cSrcweir             // seconds, so use milliseconds field as well.
315cdf0e10cSrcweir             xC->setDateTime( nTimeInDays );
316cdf0e10cSrcweir             sal_Int32 nZone1 = getZoneOffsetInMillis();
317cdf0e10cSrcweir             sal_Int32 nDST1  = getDSTOffsetInMillis();
318cdf0e10cSrcweir             double nLoc = nTimeInDays - (double)(nZone1 + nDST1) / MILLISECONDS_PER_DAY;
319cdf0e10cSrcweir             xC->setDateTime( nLoc );
320cdf0e10cSrcweir             sal_Int32 nZone2 = getZoneOffsetInMillis();
321cdf0e10cSrcweir             sal_Int32 nDST2  = getDSTOffsetInMillis();
322cdf0e10cSrcweir             // If DSTs differ after calculation, we crossed boundaries. Do it
323cdf0e10cSrcweir             // again, this time using the DST corrected initial value for the
324cdf0e10cSrcweir             // real local time.
325cdf0e10cSrcweir             // See also localtime/gmtime conversion pitfalls at
326cdf0e10cSrcweir             // http://www.erack.de/download/timetest.c
327cdf0e10cSrcweir             if ( nDST1 != nDST2 )
328cdf0e10cSrcweir             {
329cdf0e10cSrcweir                 nLoc = nTimeInDays - (double)(nZone2 + nDST2) / MILLISECONDS_PER_DAY;
330cdf0e10cSrcweir                 xC->setDateTime( nLoc );
331cdf0e10cSrcweir                 // #i17222# If the DST onset rule says to switch from 00:00 to
332cdf0e10cSrcweir                 // 01:00 and we tried to set onsetDay 00:00 with DST, the
333cdf0e10cSrcweir                 // result was onsetDay-1 23:00 and no DST, which is not what we
334cdf0e10cSrcweir                 // want. So once again without DST, resulting in onsetDay
335cdf0e10cSrcweir                 // 01:00 and DST. Yes, this seems to be weird, but logically
336cdf0e10cSrcweir                 // correct.
337cdf0e10cSrcweir                 sal_Int32 nDST3 = getDSTOffsetInMillis();
338cdf0e10cSrcweir                 if ( nDST2 != nDST3 && !nDST3 )
339cdf0e10cSrcweir                 {
340cdf0e10cSrcweir                     nLoc = nTimeInDays - (double)(nZone2 + nDST3) / MILLISECONDS_PER_DAY;
341cdf0e10cSrcweir                     xC->setDateTime( nLoc );
342cdf0e10cSrcweir                 }
343cdf0e10cSrcweir             }
344cdf0e10cSrcweir         }
345cdf0e10cSrcweir     }
346cdf0e10cSrcweir     catch ( Exception& e )
347cdf0e10cSrcweir     {
348cdf0e10cSrcweir #ifdef DBG_UTIL
349cdf0e10cSrcweir         ByteString aMsg( "setLocalDateTime: Exception caught\n" );
350cdf0e10cSrcweir         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
351cdf0e10cSrcweir         DBG_ERRORFILE( aMsg.GetBuffer() );
352cdf0e10cSrcweir #else
353cdf0e10cSrcweir         (void)e;
354cdf0e10cSrcweir #endif
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 
getLocalDateTime() const359cdf0e10cSrcweir double CalendarWrapper::getLocalDateTime() const
360cdf0e10cSrcweir {
361cdf0e10cSrcweir     try
362cdf0e10cSrcweir     {
363cdf0e10cSrcweir         if ( xC.is() )
364cdf0e10cSrcweir         {
365cdf0e10cSrcweir             double nTimeInDays = xC->getDateTime();
366cdf0e10cSrcweir             sal_Int32 nZone = getZoneOffsetInMillis();
367cdf0e10cSrcweir             sal_Int32 nDST = getDSTOffsetInMillis();
368cdf0e10cSrcweir             nTimeInDays += (double)(nZone + nDST) / MILLISECONDS_PER_DAY;
369cdf0e10cSrcweir             return nTimeInDays;
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir     catch ( Exception& e )
373cdf0e10cSrcweir     {
374cdf0e10cSrcweir #ifdef DBG_UTIL
375cdf0e10cSrcweir         ByteString aMsg( "getLocalDateTime: Exception caught\n" );
376cdf0e10cSrcweir         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
377cdf0e10cSrcweir         DBG_ERRORFILE( aMsg.GetBuffer() );
378cdf0e10cSrcweir #else
379cdf0e10cSrcweir         (void)e;
380cdf0e10cSrcweir #endif
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir     return 0.0;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 
setValue(sal_Int16 nFieldIndex,sal_Int16 nValue)386cdf0e10cSrcweir void CalendarWrapper::setValue( sal_Int16 nFieldIndex, sal_Int16 nValue )
387cdf0e10cSrcweir {
388cdf0e10cSrcweir 	try
389cdf0e10cSrcweir 	{
390cdf0e10cSrcweir 		if ( xC.is() )
391cdf0e10cSrcweir 			xC->setValue( nFieldIndex, nValue );
392cdf0e10cSrcweir 	}
393cdf0e10cSrcweir 	catch ( Exception& e )
394cdf0e10cSrcweir 	{
395cdf0e10cSrcweir #ifdef DBG_UTIL
396cdf0e10cSrcweir 		ByteString aMsg( "setValue: Exception caught\n" );
397cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
398cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
399cdf0e10cSrcweir #else
400cdf0e10cSrcweir         (void)e;
401cdf0e10cSrcweir #endif
402cdf0e10cSrcweir 	}
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 
isValid() const406cdf0e10cSrcweir sal_Bool CalendarWrapper::isValid() const
407cdf0e10cSrcweir {
408cdf0e10cSrcweir 	try
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 		if ( xC.is() )
411cdf0e10cSrcweir             return xC->isValid();
412cdf0e10cSrcweir 	}
413cdf0e10cSrcweir 	catch ( Exception& e )
414cdf0e10cSrcweir 	{
415cdf0e10cSrcweir #ifdef DBG_UTIL
416cdf0e10cSrcweir         ByteString aMsg( "isValid: Exception caught\n" );
417cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
418cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
419cdf0e10cSrcweir #else
420cdf0e10cSrcweir         (void)e;
421cdf0e10cSrcweir #endif
422cdf0e10cSrcweir 	}
423cdf0e10cSrcweir     return sal_False;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 
getValue(sal_Int16 nFieldIndex) const427cdf0e10cSrcweir sal_Int16 CalendarWrapper::getValue( sal_Int16 nFieldIndex ) const
428cdf0e10cSrcweir {
429cdf0e10cSrcweir 	try
430cdf0e10cSrcweir 	{
431cdf0e10cSrcweir 		if ( xC.is() )
432cdf0e10cSrcweir 			return xC->getValue( nFieldIndex );
433cdf0e10cSrcweir 	}
434cdf0e10cSrcweir 	catch ( Exception& e )
435cdf0e10cSrcweir 	{
436cdf0e10cSrcweir #ifdef DBG_UTIL
437cdf0e10cSrcweir 		ByteString aMsg( "getValue: Exception caught\n" );
438cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
439cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
440cdf0e10cSrcweir #else
441cdf0e10cSrcweir         (void)e;
442cdf0e10cSrcweir #endif
443cdf0e10cSrcweir 	}
444cdf0e10cSrcweir 	return 0;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 
addValue(sal_Int16 nFieldIndex,sal_Int32 nAmount)448cdf0e10cSrcweir void CalendarWrapper::addValue( sal_Int16 nFieldIndex, sal_Int32 nAmount )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	try
451cdf0e10cSrcweir 	{
452cdf0e10cSrcweir 		if ( xC.is() )
453cdf0e10cSrcweir 			xC->addValue( nFieldIndex, nAmount );
454cdf0e10cSrcweir 	}
455cdf0e10cSrcweir 	catch ( Exception& e )
456cdf0e10cSrcweir 	{
457cdf0e10cSrcweir #ifdef DBG_UTIL
458cdf0e10cSrcweir 		ByteString aMsg( "addValue: Exception caught\n" );
459cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
460cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
461cdf0e10cSrcweir #else
462cdf0e10cSrcweir         (void)e;
463cdf0e10cSrcweir #endif
464cdf0e10cSrcweir 	}
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 
getFirstDayOfWeek() const468cdf0e10cSrcweir sal_Int16 CalendarWrapper::getFirstDayOfWeek() const
469cdf0e10cSrcweir {
470cdf0e10cSrcweir 	try
471cdf0e10cSrcweir 	{
472cdf0e10cSrcweir 		if ( xC.is() )
473cdf0e10cSrcweir 			return xC->getFirstDayOfWeek();
474cdf0e10cSrcweir 	}
475cdf0e10cSrcweir 	catch ( Exception& e )
476cdf0e10cSrcweir 	{
477cdf0e10cSrcweir #ifdef DBG_UTIL
478cdf0e10cSrcweir 		ByteString aMsg( "getFirstDayOfWeek: Exception caught\n" );
479cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
480cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
481cdf0e10cSrcweir #else
482cdf0e10cSrcweir         (void)e;
483cdf0e10cSrcweir #endif
484cdf0e10cSrcweir 	}
485cdf0e10cSrcweir 	return 0;
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 
setFirstDayOfWeek(sal_Int16 nDay)489cdf0e10cSrcweir void CalendarWrapper::setFirstDayOfWeek( sal_Int16 nDay )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir 	try
492cdf0e10cSrcweir 	{
493cdf0e10cSrcweir 		if ( xC.is() )
494cdf0e10cSrcweir 			xC->setFirstDayOfWeek( nDay );
495cdf0e10cSrcweir 	}
496cdf0e10cSrcweir 	catch ( Exception& e )
497cdf0e10cSrcweir 	{
498cdf0e10cSrcweir #ifdef DBG_UTIL
499cdf0e10cSrcweir 		ByteString aMsg( "setFirstDayOfWeek: Exception caught\n" );
500cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
501cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
502cdf0e10cSrcweir #else
503cdf0e10cSrcweir         (void)e;
504cdf0e10cSrcweir #endif
505cdf0e10cSrcweir 	}
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 
setMinimumNumberOfDaysForFirstWeek(sal_Int16 nDays)509cdf0e10cSrcweir void CalendarWrapper::setMinimumNumberOfDaysForFirstWeek( sal_Int16 nDays )
510cdf0e10cSrcweir {
511cdf0e10cSrcweir 	try
512cdf0e10cSrcweir 	{
513cdf0e10cSrcweir 		if ( xC.is() )
514cdf0e10cSrcweir 			xC->setMinimumNumberOfDaysForFirstWeek( nDays );
515cdf0e10cSrcweir 	}
516cdf0e10cSrcweir 	catch ( Exception& e )
517cdf0e10cSrcweir 	{
518cdf0e10cSrcweir #ifdef DBG_UTIL
519cdf0e10cSrcweir 		ByteString aMsg( "setMinimumNumberOfDaysForFirstWeek: Exception caught\n" );
520cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
521cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
522cdf0e10cSrcweir #else
523cdf0e10cSrcweir         (void)e;
524cdf0e10cSrcweir #endif
525cdf0e10cSrcweir 	}
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 
getMinimumNumberOfDaysForFirstWeek() const529cdf0e10cSrcweir sal_Int16 CalendarWrapper::getMinimumNumberOfDaysForFirstWeek() const
530cdf0e10cSrcweir {
531cdf0e10cSrcweir 	try
532cdf0e10cSrcweir 	{
533cdf0e10cSrcweir 		if ( xC.is() )
534cdf0e10cSrcweir 			return xC->getMinimumNumberOfDaysForFirstWeek();
535cdf0e10cSrcweir 	}
536cdf0e10cSrcweir 	catch ( Exception& e )
537cdf0e10cSrcweir 	{
538cdf0e10cSrcweir #ifdef DBG_UTIL
539cdf0e10cSrcweir 		ByteString aMsg( "getMinimumNumberOfDaysForFirstWeek: Exception caught\n" );
540cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
541cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
542cdf0e10cSrcweir #else
543cdf0e10cSrcweir         (void)e;
544cdf0e10cSrcweir #endif
545cdf0e10cSrcweir 	}
546cdf0e10cSrcweir 	return 0;
547cdf0e10cSrcweir }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 
getNumberOfMonthsInYear() const550cdf0e10cSrcweir sal_Int16 CalendarWrapper::getNumberOfMonthsInYear() const
551cdf0e10cSrcweir {
552cdf0e10cSrcweir 	try
553cdf0e10cSrcweir 	{
554cdf0e10cSrcweir 		if ( xC.is() )
555cdf0e10cSrcweir 			return xC->getNumberOfMonthsInYear();
556cdf0e10cSrcweir 	}
557cdf0e10cSrcweir 	catch ( Exception& e )
558cdf0e10cSrcweir 	{
559cdf0e10cSrcweir #ifdef DBG_UTIL
560cdf0e10cSrcweir 		ByteString aMsg( "getNumberOfMonthsInYear: Exception caught\n" );
561cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
562cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
563cdf0e10cSrcweir #else
564cdf0e10cSrcweir         (void)e;
565cdf0e10cSrcweir #endif
566cdf0e10cSrcweir 	}
567cdf0e10cSrcweir 	return 0;
568cdf0e10cSrcweir }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 
getNumberOfDaysInWeek() const571cdf0e10cSrcweir sal_Int16 CalendarWrapper::getNumberOfDaysInWeek() const
572cdf0e10cSrcweir {
573cdf0e10cSrcweir 	try
574cdf0e10cSrcweir 	{
575cdf0e10cSrcweir 		if ( xC.is() )
576cdf0e10cSrcweir 			return xC->getNumberOfDaysInWeek();
577cdf0e10cSrcweir 	}
578cdf0e10cSrcweir 	catch ( Exception& e )
579cdf0e10cSrcweir 	{
580cdf0e10cSrcweir #ifdef DBG_UTIL
581cdf0e10cSrcweir 		ByteString aMsg( "getNumberOfDaysInWeek: Exception caught\n" );
582cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
583cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
584cdf0e10cSrcweir #else
585cdf0e10cSrcweir         (void)e;
586cdf0e10cSrcweir #endif
587cdf0e10cSrcweir 	}
588cdf0e10cSrcweir 	return 0;
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 
getMonths() const592cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > CalendarWrapper::getMonths() const
593cdf0e10cSrcweir {
594cdf0e10cSrcweir 	try
595cdf0e10cSrcweir 	{
596cdf0e10cSrcweir 		if ( xC.is() )
597cdf0e10cSrcweir 			return xC->getMonths();
598cdf0e10cSrcweir 	}
599cdf0e10cSrcweir 	catch ( Exception& e )
600cdf0e10cSrcweir 	{
601cdf0e10cSrcweir #ifdef DBG_UTIL
602cdf0e10cSrcweir 		ByteString aMsg( "getMonths: Exception caught\n" );
603cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
604cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
605cdf0e10cSrcweir #else
606cdf0e10cSrcweir         (void)e;
607cdf0e10cSrcweir #endif
608cdf0e10cSrcweir 	}
609cdf0e10cSrcweir 	return ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > (0);
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 
getDays() const613cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > CalendarWrapper::getDays() const
614cdf0e10cSrcweir {
615cdf0e10cSrcweir 	try
616cdf0e10cSrcweir 	{
617cdf0e10cSrcweir 		if ( xC.is() )
618cdf0e10cSrcweir 			return xC->getDays();
619cdf0e10cSrcweir 	}
620cdf0e10cSrcweir 	catch ( Exception& e )
621cdf0e10cSrcweir 	{
622cdf0e10cSrcweir #ifdef DBG_UTIL
623cdf0e10cSrcweir 		ByteString aMsg( "getDays: Exception caught\n" );
624cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
625cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
626cdf0e10cSrcweir #else
627cdf0e10cSrcweir         (void)e;
628cdf0e10cSrcweir #endif
629cdf0e10cSrcweir 	}
630cdf0e10cSrcweir 	return ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > (0);
631cdf0e10cSrcweir }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir 
getDisplayName(sal_Int16 nCalendarDisplayIndex,sal_Int16 nIdx,sal_Int16 nNameType) const634cdf0e10cSrcweir String CalendarWrapper::getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const
635cdf0e10cSrcweir {
636cdf0e10cSrcweir 	try
637cdf0e10cSrcweir 	{
638cdf0e10cSrcweir 		if ( xC.is() )
639cdf0e10cSrcweir 			return xC->getDisplayName( nCalendarDisplayIndex, nIdx, nNameType );
640cdf0e10cSrcweir 	}
641cdf0e10cSrcweir 	catch ( Exception& e )
642cdf0e10cSrcweir 	{
643cdf0e10cSrcweir #ifdef DBG_UTIL
644cdf0e10cSrcweir 		ByteString aMsg( "getDisplayName: Exception caught\n" );
645cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
646cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
647cdf0e10cSrcweir #else
648cdf0e10cSrcweir         (void)e;
649cdf0e10cSrcweir #endif
650cdf0e10cSrcweir 	}
651cdf0e10cSrcweir 	return String();
652cdf0e10cSrcweir }
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 
655cdf0e10cSrcweir // --- XExtendedCalendar -----------------------------------------------------
656cdf0e10cSrcweir 
getDisplayString(sal_Int32 nCalendarDisplayCode,sal_Int16 nNativeNumberMode) const657cdf0e10cSrcweir String CalendarWrapper::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const
658cdf0e10cSrcweir {
659cdf0e10cSrcweir 	try
660cdf0e10cSrcweir 	{
661cdf0e10cSrcweir 		if ( xC.is() )
662cdf0e10cSrcweir 			return xC->getDisplayString( nCalendarDisplayCode, nNativeNumberMode );
663cdf0e10cSrcweir 	}
664cdf0e10cSrcweir 	catch ( Exception& e )
665cdf0e10cSrcweir 	{
666cdf0e10cSrcweir #ifdef DBG_UTIL
667cdf0e10cSrcweir 		ByteString aMsg( "getDisplayString: Exception caught\n" );
668cdf0e10cSrcweir 		aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
669cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
670cdf0e10cSrcweir #else
671cdf0e10cSrcweir         (void)e;
672cdf0e10cSrcweir #endif
673cdf0e10cSrcweir 	}
674cdf0e10cSrcweir 	return String();
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
677