Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / unotools / source / i18n / calendarwrapper.cxx
blob51e975bbe90679381fc1fb87a6ed80c750bed2e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 )
45 try
47 if ( xC.is() )
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 )
58 try
60 if ( xC.is() )
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
72 try
74 if ( xC.is() )
75 return xC->getAllCalendars( rLocale );
77 catch (const Exception&)
79 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getAllCalendars" );
82 return {};
85 OUString CalendarWrapper::getUniqueID() const
87 try
89 if ( xC.is() )
90 return xC->getUniqueID();
92 catch (const Exception&)
94 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getUniqueID" );
96 return OUString();
99 void CalendarWrapper::setDateTime( double fTimeInDays )
103 if ( xC.is() )
104 xC->setDateTime( fTimeInDays );
106 catch (const Exception&)
108 TOOLS_WARN_EXCEPTION( "unotools.i18n", "setDateTime" );
112 double CalendarWrapper::getDateTime() const
116 if ( xC.is() )
117 return xC->getDateTime();
119 catch (const Exception&)
121 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDateTime" );
123 return 0.0;
126 void CalendarWrapper::setLocalDateTime( double fTimeInDays )
130 if ( xC.is() )
132 xC->setLocalDateTime( fTimeInDays );
135 catch (const Exception&)
137 TOOLS_WARN_EXCEPTION( "unotools.i18n", "setLocalDateTime" );
141 double CalendarWrapper::getLocalDateTime() const
145 if ( xC.is() )
147 return xC->getLocalDateTime();
150 catch (const Exception&)
152 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getLocalDateTime" );
154 return 0.0;
157 void CalendarWrapper::setValue( sal_Int16 nFieldIndex, sal_Int16 nValue )
161 if ( xC.is() )
162 xC->setValue( nFieldIndex, nValue );
164 catch (const Exception&)
166 TOOLS_WARN_EXCEPTION( "unotools.i18n", "setValue" );
170 bool CalendarWrapper::isValid() const
174 if ( xC.is() )
175 return xC->isValid();
177 catch (const Exception&)
179 TOOLS_WARN_EXCEPTION( "unotools.i18n", "isValid" );
181 return false;
184 sal_Int16 CalendarWrapper::getValue( sal_Int16 nFieldIndex ) const
188 if ( xC.is() )
189 return xC->getValue( nFieldIndex );
191 catch (const Exception&)
193 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getValue" );
195 return 0;
198 sal_Int16 CalendarWrapper::getFirstDayOfWeek() const
202 if ( xC.is() )
203 return xC->getFirstDayOfWeek();
205 catch (const Exception&)
207 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getFirstDayOfWeek" );
209 return 0;
212 sal_Int16 CalendarWrapper::getNumberOfMonthsInYear() const
216 if ( xC.is() )
217 return xC->getNumberOfMonthsInYear();
219 catch (const Exception&)
221 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getNumberOfMonthsInYear" );
223 return 0;
226 sal_Int16 CalendarWrapper::getNumberOfDaysInWeek() const
230 if ( xC.is() )
231 return xC->getNumberOfDaysInWeek();
233 catch (const Exception&)
235 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getNumberOfDaysInWeek" );
237 return 0;
240 css::uno::Sequence< css::i18n::CalendarItem2 > CalendarWrapper::getMonths() const
244 if ( xC.is() )
245 return xC->getMonths2();
247 catch (const Exception&)
249 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getMonths" );
251 return {};
254 css::uno::Sequence< css::i18n::CalendarItem2 > CalendarWrapper::getDays() const
258 if ( xC.is() )
259 return xC->getDays2();
261 catch (const Exception&)
263 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDays" );
265 return {};
268 OUString CalendarWrapper::getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const
272 if ( xC.is() )
273 return xC->getDisplayName( nCalendarDisplayIndex, nIdx, nNameType );
275 catch (const Exception&)
277 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDisplayName" );
279 return OUString();
282 // --- XExtendedCalendar -----------------------------------------------------
284 OUString CalendarWrapper::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const
288 if ( xC.is() )
289 return xC->getDisplayString( nCalendarDisplayCode, nNativeNumberMode );
291 catch (const Exception&)
293 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getDisplayString" );
295 return OUString();
298 // --- XCalendar3 ------------------------------------------------------------
300 css::i18n::Calendar2 CalendarWrapper::getLoadedCalendar() const
304 if ( xC.is() )
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
318 if ( xC.is() )
319 return xC->getGenitiveMonths2();
321 catch (const Exception&)
323 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getGenitiveMonths" );
325 return {};
328 css::uno::Sequence< css::i18n::CalendarItem2 > CalendarWrapper::getPartitiveMonths() const
332 if ( xC.is() )
333 return xC->getPartitiveMonths2();
335 catch (const Exception&)
337 TOOLS_WARN_EXCEPTION( "unotools.i18n", "getPartitiveMonths" );
339 return {};
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */