1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/strbuf.hxx>
21 #include <sal/log.hxx>
22 #include <unotools/calendarwrapper.hxx>
23 #include <com/sun/star/i18n/CalendarFieldIndex.hpp>
24 #include <com/sun/star/i18n/LocaleCalendar2.hpp>
26 using namespace ::com::sun::star
;
27 using namespace ::com::sun::star::i18n
;
28 using namespace ::com::sun::star::uno
;
30 CalendarWrapper::CalendarWrapper(
31 const Reference
< uno::XComponentContext
> & rxContext
34 aEpochStart( Date( 1, 1, 1970 ) )
36 xC
= LocaleCalendar2::create(rxContext
);
39 CalendarWrapper::~CalendarWrapper()
43 void CalendarWrapper::loadDefaultCalendar( const ::com::sun::star::lang::Locale
& rLocale
)
48 xC
->loadDefaultCalendar( rLocale
);
50 catch (const Exception
& e
)
52 SAL_WARN( "unotools.i18n", "loadDefaultCalendar: Exception caught " << e
.Message
);
56 void CalendarWrapper::loadCalendar( const OUString
& rUniqueID
, const ::com::sun::star::lang::Locale
& rLocale
)
61 xC
->loadCalendar( rUniqueID
, rLocale
);
63 catch (const Exception
& e
)
65 SAL_WARN( "unotools.i18n", "loadCalendar: Exception caught requested: "
66 << rUniqueID
<< " Locale: " << rLocale
.Language
<< "_" << rLocale
.Country
<< " " << e
.Message
);
70 ::com::sun::star::uno::Sequence
< OUString
> CalendarWrapper::getAllCalendars( const ::com::sun::star::lang::Locale
& rLocale
) const
75 return xC
->getAllCalendars( rLocale
);
77 catch (const Exception
& e
)
79 SAL_WARN( "unotools.i18n", "getAllCalendars: Exception caught " << e
.Message
);
82 return ::com::sun::star::uno::Sequence
< OUString
> (0);
85 OUString
CalendarWrapper::getUniqueID() const
90 return xC
->getUniqueID();
92 catch (const Exception
& e
)
94 SAL_WARN( "unotools.i18n", "getUniqueID: Exception caught " << e
.Message
);
99 void CalendarWrapper::setDateTime( double fTimeInDays
)
104 xC
->setDateTime( fTimeInDays
);
106 catch (const Exception
& e
)
108 SAL_WARN( "unotools.i18n", "setDateTime: Exception caught " << e
.Message
);
112 double CalendarWrapper::getDateTime() const
117 return xC
->getDateTime();
119 catch (const Exception
& e
)
121 SAL_WARN( "unotools.i18n", "getDateTime: Exception caught " << e
.Message
);
126 void CalendarWrapper::setLocalDateTime( double fTimeInDays
)
132 xC
->setLocalDateTime( fTimeInDays
);
135 catch (const Exception
& e
)
137 SAL_WARN( "unotools.i18n", "setLocalDateTime: Exception caught " << e
.Message
);
141 double CalendarWrapper::getLocalDateTime() const
147 return xC
->getLocalDateTime();
150 catch (const Exception
& e
)
152 SAL_WARN( "unotools.i18n", "getLocalDateTime: Exception caught " << e
.Message
);
157 void CalendarWrapper::setValue( sal_Int16 nFieldIndex
, sal_Int16 nValue
)
162 xC
->setValue( nFieldIndex
, nValue
);
164 catch (const Exception
& e
)
166 SAL_WARN( "unotools.i18n", "setValue: Exception caught " << e
.Message
);
170 bool CalendarWrapper::isValid() const
175 return xC
->isValid();
177 catch (const Exception
& e
)
179 SAL_WARN( "unotools.i18n", "isValid: Exception caught " << e
.Message
);
184 sal_Int16
CalendarWrapper::getValue( sal_Int16 nFieldIndex
) const
189 return xC
->getValue( nFieldIndex
);
191 catch (const Exception
& e
)
193 SAL_WARN( "unotools.i18n", "getValue: Exception caught " << e
.Message
);
198 void CalendarWrapper::addValue( sal_Int16 nFieldIndex
, sal_Int32 nAmount
)
203 xC
->addValue( nFieldIndex
, nAmount
);
205 catch (const Exception
& e
)
207 SAL_WARN( "unotools.i18n", "addValue: Exception caught " << e
.Message
);
211 sal_Int16
CalendarWrapper::getFirstDayOfWeek() const
216 return xC
->getFirstDayOfWeek();
218 catch (const Exception
& e
)
220 SAL_WARN( "unotools.i18n", "getFirstDayOfWeek: Exception caught " << e
.Message
);
225 sal_Int16
CalendarWrapper::getNumberOfMonthsInYear() const
230 return xC
->getNumberOfMonthsInYear();
232 catch (const Exception
& e
)
234 SAL_WARN( "unotools.i18n", "getNumberOfMonthsInYear: Exception caught " << e
.Message
);
239 sal_Int16
CalendarWrapper::getNumberOfDaysInWeek() const
244 return xC
->getNumberOfDaysInWeek();
246 catch (const Exception
& e
)
248 SAL_WARN( "unotools.i18n", "getNumberOfDaysInWeek: Exception caught " << e
.Message
);
253 ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> CalendarWrapper::getMonths() const
258 return xC
->getMonths2();
260 catch (const Exception
& e
)
262 SAL_WARN( "unotools.i18n", "getMonths: Exception caught " << e
.Message
);
264 return ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> (0);
267 ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> CalendarWrapper::getDays() const
272 return xC
->getDays2();
274 catch (const Exception
& e
)
276 SAL_WARN( "unotools.i18n", "getDays: Exception caught " << e
.Message
);
278 return ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> (0);
281 OUString
CalendarWrapper::getDisplayName( sal_Int16 nCalendarDisplayIndex
, sal_Int16 nIdx
, sal_Int16 nNameType
) const
286 return xC
->getDisplayName( nCalendarDisplayIndex
, nIdx
, nNameType
);
288 catch (const Exception
& e
)
290 SAL_WARN( "unotools.i18n", "getDisplayName: Exception caught " << e
.Message
);
295 // --- XExtendedCalendar -----------------------------------------------------
297 OUString
CalendarWrapper::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
) const
302 return xC
->getDisplayString( nCalendarDisplayCode
, nNativeNumberMode
);
304 catch (const Exception
& e
)
306 SAL_WARN( "unotools.i18n", "getDisplayString: Exception caught " << e
.Message
);
311 // --- XCalendar3 ------------------------------------------------------------
313 ::com::sun::star::i18n::Calendar2
CalendarWrapper::getLoadedCalendar() const
318 return xC
->getLoadedCalendar2();
320 catch (const Exception
& e
)
322 SAL_WARN( "unotools.i18n", "getLoadedCalendar2: Exception caught " << e
.Message
);
324 return ::com::sun::star::i18n::Calendar2();
327 ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> CalendarWrapper::getGenitiveMonths() const
332 return xC
->getGenitiveMonths2();
334 catch (const Exception
& e
)
336 SAL_WARN( "unotools.i18n", "getGenitiveMonths: Exception caught " << e
.Message
);
338 return ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> (0);
341 ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> CalendarWrapper::getPartitiveMonths() const
346 return xC
->getPartitiveMonths2();
348 catch (const Exception
& e
)
350 SAL_WARN( "unotools.i18n", "getPartitiveMonths: Exception caught " << e
.Message
);
352 return ::com::sun::star::uno::Sequence
< ::com::sun::star::i18n::CalendarItem2
> (0);
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */