LibreOffice Module i18npool (master) 1
calendar_gregorian.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <algorithm>
21
23#include <localedata.hxx>
25#include <com/sun/star/i18n/CalendarDisplayCode.hpp>
26#include <com/sun/star/i18n/CalendarDisplayIndex.hpp>
27#include <com/sun/star/i18n/NativeNumberMode.hpp>
28#include <com/sun/star/i18n/reservedWords.hpp>
30#include <o3tl/sprintf.hxx>
31#include <rtl/math.hxx>
32#include <sal/log.hxx>
33
34#include <stdio.h>
35#include <string.h>
36
37#define erDUMP_ICU_CALENDAR 0
38#define erDUMP_I18N_CALENDAR 0
39#if erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
40// If both are used, DUMP_ICU_CAL_MSG() must be used before DUMP_I18N_CAL_MSG()
41// to obtain internally set values from ICU, else Calendar::get() calls in
42// DUMP_I18N_CAL_MSG() recalculate!
43
44// These pieces of macro are shamelessly borrowed from icu's olsontz.cpp, the
45// double parens'ed approach to pass multiple parameters as one macro parameter
46// is appealing.
47static void debug_cal_loc(const char *f, int32_t l)
48{
49 fprintf(stderr, "%s:%d: ", f, l);
50}
51# include <stdarg.h>
52static void debug_cal_msg(const char *pat, ...)
53{
54 va_list ap;
55 va_start(ap, pat);
56 vfprintf(stderr, pat, ap);
57 va_end(ap);
58}
59
60#if erDUMP_ICU_CALENDAR
61// Make icu with
62// DEFS = -DU_DEBUG_CALSVC -DUCAL_DEBUG_DUMP
63// in workdir/UnpackedTarball/icu/source/icudefs.mk
64// May need some patches to fix unmaintained things there.
65extern void ucal_dump( const icu::Calendar & );
66static void debug_icu_cal_dump( const ::icu::Calendar & r )
67{
68 ucal_dump(r);
69 fflush(stderr);
70 // set a breakpoint here to pause display between dumps
71}
72// must use double parens, i.e.: DUMP_ICU_CAL_MSG(("four is: %d",4));
73#define DUMP_ICU_CAL_MSG(x) {debug_cal_loc(__FILE__,__LINE__);debug_cal_msg x;debug_icu_cal_dump(*body);}
74#else // erDUMP_ICU_CALENDAR
75#define DUMP_ICU_CAL_MSG(x)
76#endif // erDUMP_ICU_CALENDAR
77
78#if erDUMP_I18N_CALENDAR
79static void debug_cal_millis_to_time( long nMillis, long & h, long & m, long & s, long & f )
80{
81 int sign = (nMillis < 0 ? -1 : 1);
82 nMillis = ::std::abs(nMillis);
83 h = sign * nMillis / (60 * 60 * 1000);
84 nMillis -= sign * h * (60 * 60 * 1000);
85 m = nMillis / (60 * 1000);
86 nMillis -= m * (60 * 1000);
87 s = nMillis / (1000);
88 nMillis -= s * (1000);
89 f = nMillis;
90}
91static void debug_i18n_cal_dump( const ::icu::Calendar & r )
92{
93 UErrorCode status;
94 long nMillis, h, m, s, f;
95 fprintf( stderr, " %04ld", (long)r.get( UCAL_YEAR, status = U_ZERO_ERROR));
96 fprintf( stderr, "-%02ld", (long)r.get( UCAL_MONTH, status = U_ZERO_ERROR)+1);
97 fprintf( stderr, "-%02ld", (long)r.get( UCAL_DATE, status = U_ZERO_ERROR));
98 fprintf( stderr, " %02ld", (long)r.get( UCAL_HOUR_OF_DAY, status = U_ZERO_ERROR));
99 fprintf( stderr, ":%02ld", (long)r.get( UCAL_MINUTE, status = U_ZERO_ERROR));
100 fprintf( stderr, ":%02ld", (long)r.get( UCAL_SECOND, status = U_ZERO_ERROR));
101 fprintf( stderr, " zone: %ld", (long)(nMillis = r.get( UCAL_ZONE_OFFSET, status = U_ZERO_ERROR)));
102 fprintf( stderr, " (%f min)", (double)nMillis / 60000);
103 debug_cal_millis_to_time( nMillis, h, m, s, f);
104 fprintf( stderr, " (%ld:%02ld:%02ld.%ld)", h, m, s, f);
105 fprintf( stderr, " DST: %ld", (long)(nMillis = r.get( UCAL_DST_OFFSET, status = U_ZERO_ERROR)));
106 fprintf( stderr, " (%f min)", (double)nMillis / 60000);
107 debug_cal_millis_to_time( nMillis, h, m, s, f);
108 fprintf( stderr, " (%ld:%02ld:%02ld.%ld)", h, m, s, f);
109 fprintf( stderr, "\n");
110 fflush(stderr);
111}
112// must use double parens, i.e.: DUMP_I18N_CAL_MSG(("four is: %d",4));
113#define DUMP_I18N_CAL_MSG(x) {debug_cal_loc(__FILE__,__LINE__);debug_cal_msg x;debug_i18n_cal_dump(*body);}
114#else // erDUMP_I18N_CALENDAR
115#define DUMP_I18N_CAL_MSG(x)
116#endif // erDUMP_I18N_CALENDAR
117
118#else // erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
119#define DUMP_ICU_CAL_MSG(x)
120#define DUMP_I18N_CAL_MSG(x)
121#endif // erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
122
123
124using namespace ::com::sun::star::uno;
125using namespace ::com::sun::star::i18n;
126using namespace ::com::sun::star::lang;
127
128
129namespace i18npool {
130
131// Cast positive int32 values to signed int16, needed for
132// fieldValue[CalendarFieldIndex::YEAR] where absolute value of an era year may
133// be 32768 that with static_cast<sal_Int16> becomes -32768, which we also
134// do here but indicating places in a controlled way to map back.
135static inline sal_Int16 cast32To16( sal_Int32 a )
136{
137 // More than uint16 can't be handled, should not occur.
138 assert(a >= 0 && a < static_cast<sal_Int32>(SAL_MAX_INT16) - static_cast<sal_Int32>(SAL_MIN_INT16));
139 return static_cast<sal_Int16>(a);
140}
141// And back.
142static inline sal_Int32 cast16To32( sal_Int16 i )
143{
144 return static_cast<sal_Int32>(static_cast<sal_uInt16>(i));
145}
146
148 : mxNatNum(new NativeNumberSupplierService)
149{
150 init(nullptr);
151}
153 : mxNatNum(new NativeNumberSupplierService)
154{
155 init(_earArray);
156}
157void
159{
160 cCalendar = "com.sun.star.i18n.Calendar_gregorian";
161
162 fieldSet = 0;
163
164 // #i102356# With icu::Calendar::createInstance(UErrorCode) in a Thai
165 // th_TH system locale we accidentally used a Buddhist calendar. Though
166 // the ICU documentation says that should be the case only for
167 // th_TH_TRADITIONAL (and ja_JP_TRADITIONAL Gengou), a plain th_TH
168 // already triggers that behavior, ja_JP does not. Strange enough,
169 // passing a th_TH locale to the calendar creation doesn't trigger
170 // this.
171 // See also http://userguide.icu-project.org/datetime/calendar
172
173 // Whatever ICU offers as the default calendar for a locale, ensure we
174 // have a Gregorian calendar as requested.
175
176 /* XXX: with the current implementation the aLocale member variable is
177 * not set prior to loading a calendar from locale data. This
178 * creates an empty (root) locale for ICU, but at least the correct
179 * calendar is used. The language part must not be NULL (respectively
180 * not all, language and country and variant), otherwise the current
181 * default locale would be used again and the calendar keyword ignored.
182 * */
183 icu::Locale aIcuLocale( "", nullptr, nullptr, "calendar=gregorian");
184
185 /* XXX: not specifying a timezone when creating a calendar assigns the
186 * system's timezone with all DST quirks, invalid times when switching
187 * to/from DST and so on. The XCalendar* interfaces are defined to support
188 * local time and UTC time so we can not override that here.
189 */
190 UErrorCode status = U_ZERO_ERROR;
191 body.reset( icu::Calendar::createInstance( aIcuLocale, status) );
192 if (!body || !U_SUCCESS(status)) throw RuntimeException();
193 eraArray=_eraArray;
194}
195
197{
198}
199
201{
202 cCalendar = "com.sun.star.i18n.Calendar_hanja";
203}
204
205OUString SAL_CALL
206Calendar_hanja::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType )
207{
208 if ( displayIndex == CalendarDisplayIndex::AM_PM ) {
209 // Am/Pm string for Korean Hanja calendar will refer to Japanese locale
210 css::lang::Locale jaLocale("ja", OUString(), OUString());
211 if (idx == 0) return LocaleDataImpl::get()->getLocaleItem(jaLocale).timeAM;
212 else if (idx == 1) return LocaleDataImpl::get()->getLocaleItem(jaLocale).timePM;
213 else throw RuntimeException();
214 }
215 else
216 return Calendar_gregorian::getDisplayName( displayIndex, idx, nameType );
217}
218
219
221{
222 cCalendar = "com.sun.star.i18n.Calendar_Calendar_hanja_yoil";
223}
224
225OUString SAL_CALL
226Calendar_hanja_yoil::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType )
227{
228 if ( displayIndex == CalendarDisplayIndex::AM_PM ) {
229 // Am/Pm string for Korean Hanja calendar will refer to Japanese locale
230 css::lang::Locale jaLocale("ja", OUString(), OUString());
231 if (idx == 0) return LocaleDataImpl::get()->getLocaleItem(jaLocale).timeAM;
232 else if (idx == 1) return LocaleDataImpl::get()->getLocaleItem(jaLocale).timePM;
233 else throw RuntimeException();
234 }
235 else
236 return Calendar_gregorian::getDisplayName( displayIndex, idx, nameType );
237}
238
239
241 {1868, 1, 1, 0}, // Meiji
242 {1912, 7, 30, 0}, // Taisho
243 {1926, 12, 25, 0}, // Showa
244 {1989, 1, 8, 0}, // Heisei
245 {2019, 5, 1, 0}, // Reiwa
246 {0, 0, 0, 0}
247};
249{
250 cCalendar = "com.sun.star.i18n.Calendar_gengou";
251}
252
253const Era ROC_eraArray[] = {
254 {1912, 1, 1, kDisplayEraForcedLongYear}, // #i116701#
255 {0, 0, 0, 0}
256};
258{
259 cCalendar = "com.sun.star.i18n.Calendar_ROC";
260}
261
267 {-2332, 1, 1, 0},
268 {0, 0, 0, 0}
269};
271{
272 cCalendar = "com.sun.star.i18n.Calendar_dangi";
273}
274
276 {-542, 1, 1, 0},
277 {0, 0, 0, 0}
278};
280{
281 cCalendar = "com.sun.star.i18n.Calendar_buddhist";
282}
283
284void SAL_CALL
285Calendar_gregorian::loadCalendar( const OUString& uniqueID, const css::lang::Locale& rLocale )
286{
287 // init. fieldValue[]
288 getValue();
289
290 aLocale = rLocale;
291 const Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
292 for (const auto& rCal : xC)
293 {
294 if (uniqueID == rCal.Name)
295 {
296 aCalendar = rCal;
297 // setup minimalDaysInFirstWeek
299 aCalendar.MinimumNumberOfDaysForFirstWeek);
300 // setup first day of week
301 for (sal_Int16 day = sal::static_int_cast<sal_Int16>(
302 aCalendar.Days.getLength()-1); day>=0; day--)
303 {
304 if (aCalendar.StartOfWeek == aCalendar.Days[day].ID)
305 {
307 return;
308 }
309 }
310 }
311 }
312 // Calendar is not for the locale
313 throw RuntimeException();
314}
315
316
317css::i18n::Calendar2 SAL_CALL
319{
320 return aCalendar;
321}
322
323css::i18n::Calendar SAL_CALL
325{
327}
328
329OUString SAL_CALL
331{
332 return aCalendar.Name;
333}
334
335void SAL_CALL
337{
338 // ICU handles dates in milliseconds as double values and uses floor()
339 // to obtain integer values, which may yield a date decremented by one
340 // for odd (historical) timezone values where the computed value due to
341 // rounding errors has a fractional part in milliseconds. Ensure we
342 // pass a value without fraction here. If not, that may lead to
343 // fdo#44286 or fdo#52619 and the like, e.g. when passing
344 // -2136315212000.000244 instead of -2136315212000.000000
345 double fM = fTimeInDays * U_MILLIS_PER_DAY;
346 double fR = rtl::math::round( fM );
347 SAL_INFO_IF( fM != fR, "i18npool",
348 "Calendar_gregorian::setDateTime: " << std::fixed << fM << " rounded to " << fR);
349 UErrorCode status = U_ZERO_ERROR;
350 body->setTime( fR, status);
351 if ( !U_SUCCESS(status) ) throw RuntimeException();
352 getValue();
353}
354
355double SAL_CALL
357{
358 if (fieldSet) {
359 setValue();
360 getValue();
361 }
362 UErrorCode status = U_ZERO_ERROR;
363 double fR = body->getTime(status);
364 if ( !U_SUCCESS(status) ) throw RuntimeException();
365 return fR / U_MILLIS_PER_DAY;
366}
367
368void SAL_CALL
370{
371 // See setDateTime() for why the rounding.
372 double fM = fTimeInDays * U_MILLIS_PER_DAY;
373 double fR = rtl::math::round( fM );
374 SAL_INFO_IF( fM != fR, "i18npool",
375 "Calendar_gregorian::setLocalDateTime: " << std::fixed << fM << " rounded to " << fR);
376 int32_t nZoneOffset, nDSTOffset;
377 UErrorCode status = U_ZERO_ERROR;
378 body->getTimeZone().getOffset( fR, true, nZoneOffset, nDSTOffset, status );
379
380 if ( !U_SUCCESS(status) ) throw RuntimeException();
381 status = U_ZERO_ERROR;
382 body->setTime( fR - (nZoneOffset + nDSTOffset), status );
383 if ( !U_SUCCESS(status) ) throw RuntimeException();
384 getValue();
385}
386
387double SAL_CALL
389{
390 if (fieldSet) {
391 setValue();
392 getValue();
393 }
394 UErrorCode status = U_ZERO_ERROR;
395 double fTime = body->getTime( status );
396 if ( !U_SUCCESS(status) ) throw RuntimeException();
397 status = U_ZERO_ERROR;
398 int32_t nZoneOffset = body->get( UCAL_ZONE_OFFSET, status );
399 if ( !U_SUCCESS(status) ) throw RuntimeException();
400 status = U_ZERO_ERROR;
401 int32_t nDSTOffset = body->get( UCAL_DST_OFFSET, status );
402 if ( !U_SUCCESS(status) ) throw RuntimeException();
403 return (fTime + (nZoneOffset + nDSTOffset)) / U_MILLIS_PER_DAY;
404}
405
406bool Calendar_gregorian::setTimeZone( const OUString& rTimeZone )
407{
408 if (fieldSet)
409 {
410 setValue();
411 getValue();
412 }
413 const icu::UnicodeString aID( reinterpret_cast<const UChar*>(rTimeZone.getStr()), rTimeZone.getLength());
414 const std::unique_ptr<const icu::TimeZone> pTZ( icu::TimeZone::createTimeZone(aID));
415 if (!pTZ)
416 return false;
417
418 body->setTimeZone(*pTZ);
419 return true;
420}
421
422// map field value from gregorian calendar to other calendar, it can be overwritten by derived class.
423// By using eraArray, it can take care Japanese and Taiwan ROC calendar.
425{
426 if (!eraArray)
427 return;
428
429 sal_Int16 e, m, d;
430 sal_Int32 y;
431
432 e = fieldValue[CalendarFieldIndex::ERA];
433 y = cast16To32(fieldValue[CalendarFieldIndex::YEAR]);
434 m = fieldValue[CalendarFieldIndex::MONTH] + 1;
435 d = fieldValue[CalendarFieldIndex::DAY_OF_MONTH];
436
437 // since the year is reversed for first era, it is reversed again here for Era compare.
438 if (e == 0)
439 y = 1 - y;
440
441 for (e = 0; eraArray[e].year; e++)
442 if ((y != eraArray[e].year) ? y < eraArray[e].year :
443 (m != eraArray[e].month) ? m < eraArray[e].month : d < eraArray[e].day)
444 break;
445
446 fieldValue[CalendarFieldIndex::ERA] = e;
447 fieldValue[CalendarFieldIndex::YEAR] =
448 cast32To16( (e == 0) ? (eraArray[0].year - y) : (y - eraArray[e-1].year + 1) );
449}
450
451#define FIELDS ((1 << CalendarFieldIndex::ERA) | (1 << CalendarFieldIndex::YEAR))
452// map field value from other calendar to gregorian calendar, it can be overwritten by derived class.
453// By using eraArray, it can take care Japanese and Taiwan ROC calendar.
455{
456 if (!eraArray || !(fieldSet & FIELDS))
457 return;
458
459 sal_Int16 e = fieldValue[CalendarFieldIndex::ERA];
460 sal_Int32 y;
461 if (e == 0)
462 y = eraArray[0].year - cast16To32(fieldValue[CalendarFieldIndex::YEAR]);
463 else
464 y = eraArray[e-1].year + cast16To32(fieldValue[CalendarFieldIndex::YEAR] - 1);
465
466 fieldSetValue[CalendarFieldIndex::ERA] = y <= 0 ? 0 : 1;
467 fieldSetValue[CalendarFieldIndex::YEAR] = cast32To16(y <= 0 ? 1 - y : y);
468 fieldSet |= FIELDS;
469}
470
472static UCalendarDateFields fieldNameConverter(sal_Int16 fieldIndex)
473{
474 UCalendarDateFields f;
475
476 switch (fieldIndex) {
477 case CalendarFieldIndex::AM_PM: f = UCAL_AM_PM; break;
478 case CalendarFieldIndex::DAY_OF_MONTH: f = UCAL_DATE; break;
479 case CalendarFieldIndex::DAY_OF_WEEK: f = UCAL_DAY_OF_WEEK; break;
480 case CalendarFieldIndex::DAY_OF_YEAR: f = UCAL_DAY_OF_YEAR; break;
481 case CalendarFieldIndex::DST_OFFSET: f = UCAL_DST_OFFSET; break;
482 case CalendarFieldIndex::ZONE_OFFSET: f = UCAL_ZONE_OFFSET; break;
483 case CalendarFieldIndex::HOUR: f = UCAL_HOUR_OF_DAY; break;
484 case CalendarFieldIndex::MINUTE: f = UCAL_MINUTE; break;
485 case CalendarFieldIndex::SECOND: f = UCAL_SECOND; break;
486 case CalendarFieldIndex::MILLISECOND: f = UCAL_MILLISECOND; break;
487 case CalendarFieldIndex::WEEK_OF_MONTH: f = UCAL_WEEK_OF_MONTH; break;
488 case CalendarFieldIndex::WEEK_OF_YEAR: f = UCAL_WEEK_OF_YEAR; break;
489 case CalendarFieldIndex::YEAR: f = UCAL_YEAR; break;
490 case CalendarFieldIndex::MONTH: f = UCAL_MONTH; break;
491 case CalendarFieldIndex::ERA: f = UCAL_ERA; break;
492 default: throw RuntimeException();
493 }
494 return f;
495}
496
497void SAL_CALL
498Calendar_gregorian::setValue( sal_Int16 fieldIndex, sal_Int16 value )
499{
500 if (fieldIndex < 0 || FIELD_INDEX_COUNT <= fieldIndex)
501 throw RuntimeException();
502 fieldSet |= (1 << fieldIndex);
503 fieldValue[fieldIndex] = value;
504}
505
506bool Calendar_gregorian::getCombinedOffset( sal_Int32 & o_nOffset,
507 sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const
508{
509 o_nOffset = 0;
510 bool bFieldsSet = false;
511 if (fieldSet & (1 << nParentFieldIndex))
512 {
513 bFieldsSet = true;
514 o_nOffset = static_cast<sal_Int32>( fieldValue[nParentFieldIndex]) * 60000;
515 }
516 if (fieldSet & (1 << nChildFieldIndex))
517 {
518 bFieldsSet = true;
519 if (o_nOffset < 0)
520 o_nOffset -= static_cast<sal_uInt16>( fieldValue[nChildFieldIndex]);
521 else
522 o_nOffset += static_cast<sal_uInt16>( fieldValue[nChildFieldIndex]);
523 }
524 return bFieldsSet;
525}
526
527bool Calendar_gregorian::getZoneOffset( sal_Int32 & o_nOffset ) const
528{
529 return getCombinedOffset( o_nOffset, CalendarFieldIndex::ZONE_OFFSET,
530 CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS);
531}
532
533bool Calendar_gregorian::getDSTOffset( sal_Int32 & o_nOffset ) const
534{
535 return getCombinedOffset( o_nOffset, CalendarFieldIndex::DST_OFFSET,
536 CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS);
537}
538
540{
541 for (sal_Int16 fieldIndex = 0; fieldIndex < FIELD_INDEX_COUNT; fieldIndex++)
542 {
543 if (fieldSet & (1 << fieldIndex))
544 {
545 switch (fieldIndex)
546 {
547 default:
548 body->set(fieldNameConverter(fieldIndex), fieldSetValue[fieldIndex]);
549 break;
550 case CalendarFieldIndex::ZONE_OFFSET:
551 case CalendarFieldIndex::DST_OFFSET:
552 case CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS:
553 case CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS:
554 break; // nothing, extra handling
555 }
556 }
557 }
558 sal_Int32 nZoneOffset, nDSTOffset;
559 if (getZoneOffset( nZoneOffset))
560 body->set( fieldNameConverter( CalendarFieldIndex::ZONE_OFFSET), nZoneOffset);
561 if (getDSTOffset( nDSTOffset))
562 body->set( fieldNameConverter( CalendarFieldIndex::DST_OFFSET), nDSTOffset);
563}
564
566{
567 // Copy fields before calling submitFields() directly or indirectly below.
568 memcpy(fieldSetValue, fieldValue, sizeof(fieldSetValue));
569 // Possibly setup ERA and YEAR in fieldSetValue.
571
572 DUMP_ICU_CAL_MSG(("%s\n","setValue() before submission"));
573 DUMP_I18N_CAL_MSG(("%s\n","setValue() before submission"));
574
575 submitFields();
576
577 DUMP_ICU_CAL_MSG(("%s\n","setValue() after submission"));
578 DUMP_I18N_CAL_MSG(("%s\n","setValue() after submission"));
579
580#if erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
581 {
582 // force icu::Calendar to recalculate
583 UErrorCode status;
584 sal_Int32 nTmp = body->get( UCAL_DATE, status = U_ZERO_ERROR);
585 DUMP_ICU_CAL_MSG(("%s: %d\n","setValue() result day",nTmp));
586 DUMP_I18N_CAL_MSG(("%s: %d\n","setValue() result day",nTmp));
587 }
588#endif
589}
590
592{
593 DUMP_ICU_CAL_MSG(("%s\n","getValue()"));
594 DUMP_I18N_CAL_MSG(("%s\n","getValue()"));
595 for (sal_Int16 fieldIndex = 0; fieldIndex < FIELD_INDEX_COUNT; fieldIndex++)
596 {
597 if (fieldIndex == CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS ||
598 fieldIndex == CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS)
599 continue; // not ICU fields
600
601 UErrorCode status = U_ZERO_ERROR;
602 sal_Int32 value = body->get( fieldNameConverter(
603 fieldIndex), status);
604 if ( !U_SUCCESS(status) ) throw RuntimeException();
605
606 // Convert millisecond to minute for ZONE and DST and set remainder in
607 // second field.
608 if (fieldIndex == CalendarFieldIndex::ZONE_OFFSET)
609 {
610 sal_Int32 nMinutes = value / 60000;
611 sal_Int16 nMillis = static_cast<sal_Int16>( static_cast<sal_uInt16>(
612 abs( value - nMinutes * 60000)));
613 fieldValue[CalendarFieldIndex::ZONE_OFFSET] = static_cast<sal_Int16>( nMinutes);
614 fieldValue[CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS] = nMillis;
615 }
616 else if (fieldIndex == CalendarFieldIndex::DST_OFFSET)
617 {
618 sal_Int32 nMinutes = value / 60000;
619 sal_Int16 nMillis = static_cast<sal_Int16>( static_cast<sal_uInt16>(
620 abs( value - nMinutes * 60000)));
621 fieldValue[CalendarFieldIndex::DST_OFFSET] = static_cast<sal_Int16>( nMinutes);
622 fieldValue[CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS] = nMillis;
623 }
624 else
625 fieldValue[fieldIndex] = static_cast<sal_Int16>(value);
626
627 // offset 1 since the value for week start day SunDay is different between Calendar and Weekdays.
628 if ( fieldIndex == CalendarFieldIndex::DAY_OF_WEEK )
629 fieldValue[fieldIndex]--; // UCAL_SUNDAY:/* == 1 */ ==> Weekdays::SUNDAY /* ==0 */
630 }
632 fieldSet = 0;
633}
634
635sal_Int16 SAL_CALL
636Calendar_gregorian::getValue( sal_Int16 fieldIndex )
637{
638 if (fieldIndex < 0 || FIELD_INDEX_COUNT <= fieldIndex)
639 throw RuntimeException();
640
641 if (fieldSet) {
642 setValue();
643 getValue();
644 }
645
646 return fieldValue[fieldIndex];
647}
648
649void SAL_CALL
650Calendar_gregorian::addValue( sal_Int16 fieldIndex, sal_Int32 value )
651{
652 // since ZONE and DST could not be add, we don't need to convert value here
653 UErrorCode status = U_ZERO_ERROR;
654 body->add(fieldNameConverter(fieldIndex), value, status);
655 if ( !U_SUCCESS(status) ) throw RuntimeException();
656 getValue();
657}
658
659sal_Bool SAL_CALL
661{
662 if (fieldSet) {
663 sal_Int32 tmp = fieldSet;
664 setValue();
665 memcpy(fieldSetValue, fieldValue, sizeof(fieldSetValue));
666 getValue();
667 for ( sal_Int16 fieldIndex = 0; fieldIndex < FIELD_INDEX_COUNT; fieldIndex++ ) {
668 // compare only with fields that are set and reset fieldSet[]
669 if (tmp & (1 << fieldIndex)) {
670 if (fieldSetValue[fieldIndex] != fieldValue[fieldIndex])
671 return false;
672 }
673 }
674 }
675 return true;
676}
677
678// NativeNumberMode has different meaning between Number and Calendar for Asian locales.
679// Here is the mapping table
680// calendar(q/y/m/d) zh_CN zh_TW ja ko
681// NatNum1 NatNum1/1/7/7 NatNum1/1/7/7 NatNum1/1/4/4 NatNum1/1/7/7
682// NatNum2 NatNum2/2/8/8 NatNum2/2/8/8 NatNum2/2/5/5 NatNum2/2/8/8
683// NatNum3 NatNum3/3/3/3 NatNum3/3/3/3 NatNum3/3/3/3 NatNum3/3/3/3
684// NatNum4 NatNum9/9/11/11
685
686static sal_Int16 NatNumForCalendar(const css::lang::Locale& aLocale,
687 sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, sal_Int32 value )
688{
689 bool isShort = ((nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR ||
690 nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR) && value >= 100) ||
691 nCalendarDisplayCode == CalendarDisplayCode::SHORT_QUARTER ||
692 nCalendarDisplayCode == CalendarDisplayCode::LONG_QUARTER;
693 bool isChinese = aLocale.Language == "zh";
694 bool isJapanese = aLocale.Language == "ja";
695 bool isKorean = aLocale.Language == "ko";
696
697 if (isChinese || isJapanese || isKorean) {
698 switch (nNativeNumberMode) {
699 case NativeNumberMode::NATNUM1:
700 if (!isShort)
701 nNativeNumberMode = isJapanese ? NativeNumberMode::NATNUM4 : NativeNumberMode::NATNUM7;
702 break;
703 case NativeNumberMode::NATNUM2:
704 if (!isShort)
705 nNativeNumberMode = isJapanese ? NativeNumberMode::NATNUM5 : NativeNumberMode::NATNUM8;
706 break;
707 case NativeNumberMode::NATNUM3:
708 break;
709 case NativeNumberMode::NATNUM4:
710 if (isKorean)
711 return isShort ? NativeNumberMode::NATNUM9 : NativeNumberMode::NATNUM11;
712 [[fallthrough]];
713 default: return 0;
714 }
715 }
716 return nNativeNumberMode;
717}
718
719static sal_Int32 DisplayCode2FieldIndex(sal_Int32 nCalendarDisplayCode)
720{
721 switch( nCalendarDisplayCode ) {
722 case CalendarDisplayCode::SHORT_DAY:
723 case CalendarDisplayCode::LONG_DAY:
724 return CalendarFieldIndex::DAY_OF_MONTH;
725 case CalendarDisplayCode::SHORT_DAY_NAME:
726 case CalendarDisplayCode::LONG_DAY_NAME:
727 case CalendarDisplayCode::NARROW_DAY_NAME:
728 return CalendarFieldIndex::DAY_OF_WEEK;
729 case CalendarDisplayCode::SHORT_QUARTER:
730 case CalendarDisplayCode::LONG_QUARTER:
731 case CalendarDisplayCode::SHORT_MONTH:
732 case CalendarDisplayCode::LONG_MONTH:
733 case CalendarDisplayCode::SHORT_MONTH_NAME:
734 case CalendarDisplayCode::LONG_MONTH_NAME:
735 case CalendarDisplayCode::NARROW_MONTH_NAME:
736 case CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME:
737 case CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME:
738 case CalendarDisplayCode::NARROW_GENITIVE_MONTH_NAME:
739 case CalendarDisplayCode::SHORT_PARTITIVE_MONTH_NAME:
740 case CalendarDisplayCode::LONG_PARTITIVE_MONTH_NAME:
741 case CalendarDisplayCode::NARROW_PARTITIVE_MONTH_NAME:
742 return CalendarFieldIndex::MONTH;
743 case CalendarDisplayCode::SHORT_YEAR:
744 case CalendarDisplayCode::LONG_YEAR:
745 return CalendarFieldIndex::YEAR;
746 case CalendarDisplayCode::SHORT_ERA:
747 case CalendarDisplayCode::LONG_ERA:
748 return CalendarFieldIndex::ERA;
749 case CalendarDisplayCode::SHORT_YEAR_AND_ERA:
750 case CalendarDisplayCode::LONG_YEAR_AND_ERA:
751 return CalendarFieldIndex::YEAR;
752 default:
753 return 0;
754 }
755}
756
757sal_Int16 SAL_CALL
759{
760 // UCAL_SUNDAY == 1, Weekdays::SUNDAY == 0 => offset -1
761 // Check for underflow just in case we're called "out of sync".
762 return ::std::max( sal::static_int_cast<sal_Int16>(0),
763 sal::static_int_cast<sal_Int16>( static_cast<sal_Int16>(
764 body->getFirstDayOfWeek()) - 1));
765}
766
767void SAL_CALL
769{
770 // Weekdays::SUNDAY == 0, UCAL_SUNDAY == 1 => offset +1
771 body->setFirstDayOfWeek( static_cast<UCalendarDaysOfWeek>( day + 1));
772}
773
774void SAL_CALL
776{
777 aCalendar.MinimumNumberOfDaysForFirstWeek = days;
778 body->setMinimalDaysInFirstWeek( static_cast<uint8_t>( days));
779}
780
781sal_Int16 SAL_CALL
783{
784 return aCalendar.MinimumNumberOfDaysForFirstWeek;
785}
786
787sal_Int16 SAL_CALL
789{
790 return static_cast<sal_Int16>(aCalendar.Months.getLength());
791}
792
793
794sal_Int16 SAL_CALL
796{
797 return static_cast<sal_Int16>(aCalendar.Days.getLength());
798}
799
800
801Sequence< CalendarItem > SAL_CALL
803{
805}
806
807
808Sequence< CalendarItem > SAL_CALL
810{
812}
813
814
815Sequence< CalendarItem2 > SAL_CALL
817{
818 return aCalendar.Days;
819}
820
821
822Sequence< CalendarItem2 > SAL_CALL
824{
825 return aCalendar.Months;
826}
827
828
829Sequence< CalendarItem2 > SAL_CALL
831{
832 return aCalendar.GenitiveMonths;
833}
834
835
836Sequence< CalendarItem2 > SAL_CALL
838{
839 return aCalendar.PartitiveMonths;
840}
841
842
843OUString SAL_CALL
844Calendar_gregorian::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType )
845{
846 OUString aStr;
847
848 switch( displayIndex ) {
849 case CalendarDisplayIndex::AM_PM:/* ==0 */
850 if (idx == 0) aStr = LocaleDataImpl::get()->getLocaleItem(aLocale).timeAM;
851 else if (idx == 1) aStr = LocaleDataImpl::get()->getLocaleItem(aLocale).timePM;
852 else throw RuntimeException();
853 break;
854 case CalendarDisplayIndex::DAY:
855 if( idx >= aCalendar.Days.getLength() ) throw RuntimeException();
856 if (nameType == 0) aStr = aCalendar.Days[idx].AbbrevName;
857 else if (nameType == 1) aStr = aCalendar.Days[idx].FullName;
858 else if (nameType == 2) aStr = aCalendar.Days[idx].NarrowName;
859 else throw RuntimeException();
860 break;
861 case CalendarDisplayIndex::MONTH:
862 if( idx >= aCalendar.Months.getLength() ) throw RuntimeException();
863 if (nameType == 0) aStr = aCalendar.Months[idx].AbbrevName;
864 else if (nameType == 1) aStr = aCalendar.Months[idx].FullName;
865 else if (nameType == 2) aStr = aCalendar.Months[idx].NarrowName;
866 else throw RuntimeException();
867 break;
868 case CalendarDisplayIndex::GENITIVE_MONTH:
869 if( idx >= aCalendar.GenitiveMonths.getLength() ) throw RuntimeException();
870 if (nameType == 0) aStr = aCalendar.GenitiveMonths[idx].AbbrevName;
871 else if (nameType == 1) aStr = aCalendar.GenitiveMonths[idx].FullName;
872 else if (nameType == 2) aStr = aCalendar.GenitiveMonths[idx].NarrowName;
873 else throw RuntimeException();
874 break;
875 case CalendarDisplayIndex::PARTITIVE_MONTH:
876 if( idx >= aCalendar.PartitiveMonths.getLength() ) throw RuntimeException();
877 if (nameType == 0) aStr = aCalendar.PartitiveMonths[idx].AbbrevName;
878 else if (nameType == 1) aStr = aCalendar.PartitiveMonths[idx].FullName;
879 else if (nameType == 2) aStr = aCalendar.PartitiveMonths[idx].NarrowName;
880 else throw RuntimeException();
881 break;
882 case CalendarDisplayIndex::ERA:
883 if( idx >= aCalendar.Eras.getLength() ) throw RuntimeException();
884 if (nameType == 0) aStr = aCalendar.Eras[idx].AbbrevName;
885 else if (nameType == 1) aStr = aCalendar.Eras[idx].FullName;
886 else throw RuntimeException();
887 break;
888 case CalendarDisplayIndex::YEAR:
889 break;
890 default:
891 throw RuntimeException();
892 }
893 return aStr;
894}
895
896// Methods in XExtendedCalendar
897OUString SAL_CALL
898Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
899{
900 return getDisplayStringImpl( nCalendarDisplayCode, nNativeNumberMode, false);
901}
902
903OUString
904Calendar_gregorian::getDisplayStringImpl( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, bool bEraMode )
905{
906 sal_Int32 value = cast16To32( getValue( sal::static_int_cast<sal_Int16>(
907 DisplayCode2FieldIndex(nCalendarDisplayCode))));
908 OUString aOUStr;
909
910 if (nCalendarDisplayCode == CalendarDisplayCode::SHORT_QUARTER ||
911 nCalendarDisplayCode == CalendarDisplayCode::LONG_QUARTER) {
912 Sequence< OUString> xR = LocaleDataImpl::get()->getReservedWord(aLocale);
913 sal_Int16 quarter = value / 3;
914 // Since this base class method may be called by derived calendar
915 // classes where a year consists of more than 12 months we need a check
916 // to not run out of bounds of reserved quarter words. Perhaps a more
917 // clean way (instead of dividing by 3) would be to first get the
918 // number of months, divide by 4 and then use that result to divide the
919 // actual month value.
920 if ( quarter > 3 )
921 quarter = 3;
922 quarter = sal::static_int_cast<sal_Int16>( quarter +
923 ((nCalendarDisplayCode == CalendarDisplayCode::SHORT_QUARTER) ?
924 reservedWords::QUARTER1_ABBREVIATION : reservedWords::QUARTER1_WORD) );
925 aOUStr = xR[quarter];
926 } else {
927 // The "#100211# - checked" comments serve for detection of "use of
928 // sprintf is safe here" conditions. An sprintf encountered without
929 // having that comment triggers alarm ;-)
930 switch( nCalendarDisplayCode ) {
931 case CalendarDisplayCode::SHORT_MONTH:
932 value += 1; // month is zero based
933 [[fallthrough]];
934 case CalendarDisplayCode::SHORT_DAY:
935 aOUStr = OUString::number(value);
936 break;
937 case CalendarDisplayCode::LONG_YEAR:
938 if ( aCalendar.Name == "gengou" )
939 {
940 char aStr[12]; // "-2147483648" and \0
941 o3tl::sprintf(aStr, "%02" SAL_PRIdINT32, value); // #100211# - checked
942 aOUStr = OUString::createFromAscii(aStr);
943 }
944 else
945 aOUStr = OUString::number(value);
946 break;
947 case CalendarDisplayCode::LONG_MONTH:
948 {
949 value += 1; // month is zero based
950 char aStr[12]; // "-2147483648" and \0
951 o3tl::sprintf(aStr, "%02" SAL_PRIdINT32, value); // #100211# - checked
952 aOUStr = OUString::createFromAscii(aStr);
953 break;
954 }
955 case CalendarDisplayCode::SHORT_YEAR:
956 // Take last 2 digits, or only one if value<10, for example,
957 // in case of the Gengou calendar. For combined era+year always
958 // the full year is displayed, without leading 0.
959 // Workaround for non-combined calls in certain calendars is
960 // the kDisplayEraForcedLongYear flag, but this also could get
961 // called for YY not only E format codes, no differentiation
962 // possible here; the good news is that usually the Gregorian
963 // calendar is the default and hence YY calls for Gregorian and
964 // E for the other calendar and currently (2013-02-28) ROC is
965 // the only calendar using this.
966 // See i#116701 and fdo#60915
967 if (value < 100 || bEraMode || (eraArray && (eraArray[0].flags & kDisplayEraForcedLongYear)))
968 aOUStr = OUString::number(value);
969 else
970 {
971 char aStr[12]; // "-2147483648" and \0
972 o3tl::sprintf(aStr, "%02" SAL_PRIdINT32, value % 100); // #100211# - checked
973 aOUStr = OUString::createFromAscii(aStr);
974 }
975 break;
976 case CalendarDisplayCode::LONG_DAY:
977 {
978 char aStr[12]; // "-2147483648" and \0
979 o3tl::sprintf(aStr, "%02" SAL_PRIdINT32, value); // #100211# - checked
980 aOUStr = OUString::createFromAscii(aStr);
981 break;
982 }
983
984 case CalendarDisplayCode::SHORT_DAY_NAME:
985 return getDisplayName(CalendarDisplayIndex::DAY, value, 0);
986 case CalendarDisplayCode::LONG_DAY_NAME:
987 return getDisplayName(CalendarDisplayIndex::DAY, value, 1);
988 case CalendarDisplayCode::NARROW_DAY_NAME:
989 return getDisplayName(CalendarDisplayIndex::DAY, value, 2);
990 case CalendarDisplayCode::SHORT_MONTH_NAME:
991 return getDisplayName(CalendarDisplayIndex::MONTH, value, 0);
992 case CalendarDisplayCode::LONG_MONTH_NAME:
993 return getDisplayName(CalendarDisplayIndex::MONTH, value, 1);
994 case CalendarDisplayCode::NARROW_MONTH_NAME:
995 return getDisplayName(CalendarDisplayIndex::MONTH, value, 2);
996 case CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME:
997 return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH, value, 0);
998 case CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME:
999 return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH, value, 1);
1000 case CalendarDisplayCode::NARROW_GENITIVE_MONTH_NAME:
1001 return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH, value, 2);
1002 case CalendarDisplayCode::SHORT_PARTITIVE_MONTH_NAME:
1003 return getDisplayName(CalendarDisplayIndex::PARTITIVE_MONTH, value, 0);
1004 case CalendarDisplayCode::LONG_PARTITIVE_MONTH_NAME:
1005 return getDisplayName(CalendarDisplayIndex::PARTITIVE_MONTH, value, 1);
1006 case CalendarDisplayCode::NARROW_PARTITIVE_MONTH_NAME:
1007 return getDisplayName(CalendarDisplayIndex::PARTITIVE_MONTH, value, 2);
1008 case CalendarDisplayCode::SHORT_ERA:
1009 return getDisplayName(CalendarDisplayIndex::ERA, value, 0);
1010 case CalendarDisplayCode::LONG_ERA:
1011 return getDisplayName(CalendarDisplayIndex::ERA, value, 1);
1012
1013 case CalendarDisplayCode::SHORT_YEAR_AND_ERA:
1014 return getDisplayStringImpl( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode, true ) +
1015 getDisplayStringImpl( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode, true );
1016
1017 case CalendarDisplayCode::LONG_YEAR_AND_ERA:
1018 return getDisplayStringImpl( CalendarDisplayCode::LONG_ERA, nNativeNumberMode, true ) +
1019 getDisplayStringImpl( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode, true );
1020
1021 default:
1022 throw RuntimeException();
1023 }
1024 }
1025 // NatNum12 used only for selected parts
1026 if (nNativeNumberMode > 0 && nNativeNumberMode != 12) {
1027 // For Japanese calendar, first year calls GAN, see bug 111668 for detail.
1028 if (eraArray == gengou_eraArray && value == 1
1029 && (nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR ||
1030 nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR)
1031 && (nNativeNumberMode == NativeNumberMode::NATNUM1 ||
1032 nNativeNumberMode == NativeNumberMode::NATNUM2)) {
1033 static sal_Unicode gan = 0x5143;
1034 return OUString(&gan, 1);
1035 }
1036 sal_Int16 nNatNum = NatNumForCalendar(aLocale, nCalendarDisplayCode, nNativeNumberMode, value);
1037 if (nNatNum > 0)
1038 return mxNatNum->getNativeNumberString(aOUStr, aLocale, nNatNum);
1039 }
1040 return aOUStr;
1041}
1042
1043// Methods in XExtendedCalendar
1044OUString SAL_CALL
1045Calendar_buddhist::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
1046{
1047 // make year and era in different order for year before and after 0.
1048 if ((nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR_AND_ERA ||
1049 nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR_AND_ERA) &&
1050 getValue(CalendarFieldIndex::ERA) == 0) {
1051 if (nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR_AND_ERA)
1052 return getDisplayStringImpl( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode, true ) +
1053 getDisplayStringImpl( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode, true );
1054 else
1055 return getDisplayStringImpl( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode, true ) +
1056 getDisplayStringImpl( CalendarDisplayCode::LONG_ERA, nNativeNumberMode, true );
1057 }
1058 return Calendar_gregorian::getDisplayString(nCalendarDisplayCode, nNativeNumberMode);
1059}
1060
1061OUString SAL_CALL
1063{
1064 return OUString::createFromAscii(cCalendar);
1065}
1066
1067sal_Bool SAL_CALL
1068Calendar_gregorian::supportsService(const OUString& rServiceName)
1069{
1070 return cppu::supportsService(this, rServiceName);
1071}
1072
1073Sequence< OUString > SAL_CALL
1075{
1076 Sequence< OUString > aRet { OUString::createFromAscii(cCalendar) };
1077 return aRet;
1078}
1079
1080}
1081
1082/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
#define FIELDS
#define DUMP_ICU_CAL_MSG(x)
#define DUMP_I18N_CAL_MSG(x)
sal_Int32 day
sal_Int32 year
sal_Int32 month
virtual OUString SAL_CALL getDisplayString(sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode) override
std::unique_ptr< icu::Calendar > body
sal_Int16 fieldSetValue[FIELD_INDEX_COUNT]
virtual double SAL_CALL getDateTime() override
void submitFields()
Submit fieldSetValue array according to fieldSet.
virtual void SAL_CALL loadCalendar(const OUString &uniqueID, const css::lang::Locale &rLocale) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< css::i18n::CalendarItem2 > SAL_CALL getDays2() override
void init(const Era *_eraArray)
virtual void SAL_CALL setLocalDateTime(double TimeInDays) override
virtual sal_Int16 SAL_CALL getMinimumNumberOfDaysForFirstWeek() override
virtual sal_Int16 SAL_CALL getFirstDayOfWeek() override
OUString getDisplayStringImpl(sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, bool bEraMode)
virtual css::uno::Sequence< css::i18n::CalendarItem2 > SAL_CALL getGenitiveMonths2() override
rtl::Reference< NativeNumberSupplierService > mxNatNum
virtual double SAL_CALL getLocalDateTime() override
virtual css::uno::Sequence< css::i18n::CalendarItem > SAL_CALL getMonths() override
virtual OUString SAL_CALL getDisplayString(sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode) override
virtual OUString SAL_CALL getUniqueID() override
virtual css::uno::Sequence< css::i18n::CalendarItem2 > SAL_CALL getMonths2() override
virtual void SAL_CALL addValue(sal_Int16 nFieldIndex, sal_Int32 nAmount) override
virtual void SAL_CALL setDateTime(double fTimeInDays) override
bool getZoneOffset(sal_Int32 &o_nOffset) const
Obtain combined field values for timezone offset (minutes+secondmillis) in milliseconds and whether f...
virtual void SAL_CALL setMinimumNumberOfDaysForFirstWeek(sal_Int16 nDays) override
virtual ~Calendar_gregorian() override
Destructor.
void setValue()
Set fields internally.
bool getDSTOffset(sal_Int32 &o_nOffset) const
Obtain combined field values for DST offset (minutes+secondmillis) in milliseconds and whether fields...
virtual css::uno::Sequence< css::i18n::CalendarItem2 > SAL_CALL getPartitiveMonths2() override
virtual css::i18n::Calendar2 SAL_CALL getLoadedCalendar2() override
virtual css::uno::Sequence< css::i18n::CalendarItem > SAL_CALL getDays() override
virtual sal_Bool SAL_CALL isValid() override
virtual css::i18n::Calendar SAL_CALL getLoadedCalendar() override
virtual void SAL_CALL setFirstDayOfWeek(sal_Int16 nDay) override
bool setTimeZone(const OUString &rTimeZone)
sal_Int16 fieldValue[FIELD_INDEX_COUNT]
virtual OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Int16 SAL_CALL getNumberOfDaysInWeek() override
bool getCombinedOffset(sal_Int32 &o_nOffset, sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex) const
Used by getZoneOffset() and getDSTOffset().
virtual sal_Int16 SAL_CALL getNumberOfMonthsInYear() override
virtual OUString SAL_CALL getImplementationName() override
virtual OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) override
virtual OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) override
static rtl::Reference< LocaleDataImpl > get()
Definition: localedata.hxx:77
static css::uno::Sequence< css::i18n::CalendarItem > downcastCalendarItems(const css::uno::Sequence< css::i18n::CalendarItem2 > &rCi)
Definition: localedata.cxx:356
static css::i18n::Calendar downcastCalendar(const css::i18n::Calendar2 &rC)
Definition: localedata.cxx:363
Any value
float y
const sal_uInt16 idx[]
uno_Any a
sal_Int32 nNatNum
#define SAL_INFO_IF(condition, area, stream)
aStr
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
Constant values shared between i18npool and, for example, the number formatter.
static sal_Int32 DisplayCode2FieldIndex(sal_Int32 nCalendarDisplayCode)
static UCalendarDateFields fieldNameConverter(sal_Int16 fieldIndex)
static sal_Int32 cast16To32(sal_Int16 i)
const Era ROC_eraArray[]
const Era buddhist_eraArray[]
const sal_Int16 FIELD_INDEX_COUNT
const Era gengou_eraArray[]
static sal_Int16 cast32To16(sal_Int32 a)
const Era dangi_eraArray[]
The start year of the Korean traditional calendar (Dan-gi) is the inaugural year of Dan-gun (BC 2333)...
const sal_uInt8 kDisplayEraForcedLongYear
static sal_Int16 NatNumForCalendar(const css::lang::Locale &aLocale, sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, sal_Int32 value)
m
int sprintf(char(&s)[N], char const *format, T &&... arguments)
sal_Int32 h
SwNodeOffset abs(const SwNodeOffset &a)
unsigned char sal_Bool
#define SAL_MIN_INT16
#define SAL_MAX_INT16
sal_uInt16 sal_Unicode