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 <sal/log.hxx>
21 #include <unotools/calendarwrapper.hxx>
22 #include <i18nlangtag/languagetag.hxx>
23 #include <com/sun/star/i18n/LocaleCalendar2.hpp>
24 #include <comphelper/diagnose_ex.hxx>
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 css::lang::Locale
& rLocale
, bool bTimeZoneUTC
)
48 xC
->loadDefaultCalendarTZ( rLocale
, (bTimeZoneUTC
? "UTC" : OUString()));
50 catch (const Exception
&)
52 TOOLS_WARN_EXCEPTION( "unotools.i18n", "loadDefaultCalendar" );
56 void CalendarWrapper::loadCalendar( const OUString
& rUniqueID
, const css::lang::Locale
& rLocale
, bool bTimeZoneUTC
)
61 xC
->loadCalendarTZ( rUniqueID
, rLocale
, (bTimeZoneUTC
? "UTC" : OUString()));
63 catch (const Exception
&)
65 TOOLS_WARN_EXCEPTION( "unotools.i18n", "loadCalendar: "
66 << rUniqueID
<< " Locale: " << LanguageTag::convertToBcp47(rLocale
) );
70 css::uno::Sequence
< OUString
> CalendarWrapper::getAllCalendars( const css::lang::Locale
& rLocale
) const
75 return xC
->getAllCalendars( rLocale
);
77 catch (const Exception
&)
79 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getAllCalendars" );
85 OUString
CalendarWrapper::getUniqueID() const
90 return xC
->getUniqueID();
92 catch (const Exception
&)
94 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getUniqueID" );
99 void CalendarWrapper::setDateTime( double fTimeInDays
)
104 xC
->setDateTime( fTimeInDays
);
106 catch (const Exception
&)
108 TOOLS_WARN_EXCEPTION( "unotools.i18n", "setDateTime" );
112 double CalendarWrapper::getDateTime() const
117 return xC
->getDateTime();
119 catch (const Exception
&)
121 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDateTime" );
126 void CalendarWrapper::setLocalDateTime( double fTimeInDays
)
132 xC
->setLocalDateTime( fTimeInDays
);
135 catch (const Exception
&)
137 TOOLS_WARN_EXCEPTION( "unotools.i18n", "setLocalDateTime" );
141 double CalendarWrapper::getLocalDateTime() const
147 return xC
->getLocalDateTime();
150 catch (const Exception
&)
152 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getLocalDateTime" );
157 void CalendarWrapper::setValue( sal_Int16 nFieldIndex
, sal_Int16 nValue
)
162 xC
->setValue( nFieldIndex
, nValue
);
164 catch (const Exception
&)
166 TOOLS_WARN_EXCEPTION( "unotools.i18n", "setValue" );
170 bool CalendarWrapper::isValid() const
175 return xC
->isValid();
177 catch (const Exception
&)
179 TOOLS_WARN_EXCEPTION( "unotools.i18n", "isValid" );
184 sal_Int16
CalendarWrapper::getValue( sal_Int16 nFieldIndex
) const
189 return xC
->getValue( nFieldIndex
);
191 catch (const Exception
&)
193 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getValue" );
198 sal_Int16
CalendarWrapper::getFirstDayOfWeek() const
203 return xC
->getFirstDayOfWeek();
205 catch (const Exception
&)
207 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getFirstDayOfWeek" );
212 sal_Int16
CalendarWrapper::getNumberOfMonthsInYear() const
217 return xC
->getNumberOfMonthsInYear();
219 catch (const Exception
&)
221 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getNumberOfMonthsInYear" );
226 sal_Int16
CalendarWrapper::getNumberOfDaysInWeek() const
231 return xC
->getNumberOfDaysInWeek();
233 catch (const Exception
&)
235 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getNumberOfDaysInWeek" );
240 css::uno::Sequence
< css::i18n::CalendarItem2
> CalendarWrapper::getMonths() const
245 return xC
->getMonths2();
247 catch (const Exception
&)
249 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getMonths" );
254 css::uno::Sequence
< css::i18n::CalendarItem2
> CalendarWrapper::getDays() const
259 return xC
->getDays2();
261 catch (const Exception
&)
263 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDays" );
268 OUString
CalendarWrapper::getDisplayName( sal_Int16 nCalendarDisplayIndex
, sal_Int16 nIdx
, sal_Int16 nNameType
) const
273 return xC
->getDisplayName( nCalendarDisplayIndex
, nIdx
, nNameType
);
275 catch (const Exception
&)
277 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDisplayName" );
282 // --- XExtendedCalendar -----------------------------------------------------
284 OUString
CalendarWrapper::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
) const
289 return xC
->getDisplayString( nCalendarDisplayCode
, nNativeNumberMode
);
291 catch (const Exception
&)
293 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDisplayString" );
298 // --- XCalendar3 ------------------------------------------------------------
300 css::i18n::Calendar2
CalendarWrapper::getLoadedCalendar() const
305 return xC
->getLoadedCalendar2();
307 catch (const Exception
&)
309 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getLoadedCalendar2" );
311 return css::i18n::Calendar2();
314 css::uno::Sequence
< css::i18n::CalendarItem2
> CalendarWrapper::getGenitiveMonths() const
319 return xC
->getGenitiveMonths2();
321 catch (const Exception
&)
323 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getGenitiveMonths" );
328 css::uno::Sequence
< css::i18n::CalendarItem2
> CalendarWrapper::getPartitiveMonths() const
333 return xC
->getPartitiveMonths2();
335 catch (const Exception
&)
337 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getPartitiveMonths" );
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */