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