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 .
21 #include "calendar_gregorian.hxx"
22 #include "localedata.hxx"
23 #include <com/sun/star/i18n/AmPmValue.hpp>
24 #include <com/sun/star/i18n/Months.hpp>
25 #include <com/sun/star/i18n/Weekdays.hpp>
26 #include <com/sun/star/i18n/reservedWords.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <comphelper/processfactory.hxx>
33 #define erDUMP_ICU_CALENDAR 0
34 #define erDUMP_I18N_CALENDAR 0
35 #if erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
36 // If both are used, DUMP_ICU_CAL_MSG() must be used before DUMP_I18N_CAL_MSG()
37 // to obtain internally set values from ICU, else Calendar::get() calls in
38 // DUMP_I18N_CAL_MSG() recalculate!
40 // These pieces of macro are shamelessly borrowed from icu's olsontz.cpp, the
41 // double parens'ed approach to pass multiple parameters as one macro parameter
43 static void debug_cal_loc(const char *f
, int32_t l
)
45 fprintf(stderr
, "%s:%d: ", f
, l
);
48 static void debug_cal_msg(const char *pat
, ...)
52 vfprintf(stderr
, pat
, ap
);
56 #if erDUMP_ICU_CALENDAR
58 // DEFS = -DU_DEBUG_CALSVC -DUCAL_DEBUG_DUMP
59 // in icu/$(INPATH)/misc/build/icu/source/icudefs.mk
60 // May need some patches to fix unmaintained things there.
61 extern void ucal_dump( const icu::Calendar
& );
62 static void debug_icu_cal_dump( const ::icu::Calendar
& r
)
66 // set a breakpoint here to pause display between dumps
68 // must use double parens, i.e.: DUMP_ICU_CAL_MSG(("four is: %d",4));
69 #define DUMP_ICU_CAL_MSG(x) {debug_cal_loc(__FILE__,__LINE__);debug_cal_msg x;debug_icu_cal_dump(*body);}
70 #else // erDUMP_ICU_CALENDAR
71 #define DUMP_ICU_CAL_MSG(x)
72 #endif // erDUMP_ICU_CALENDAR
74 #if erDUMP_I18N_CALENDAR
75 static void debug_cal_millis_to_time( long nMillis
, long & h
, long & m
, long & s
, long & f
)
77 int sign
= (nMillis
< 0 ? -1 : 1);
78 nMillis
= ::std::abs(nMillis
);
79 h
= sign
* nMillis
/ (60 * 60 * 1000);
80 nMillis
-= sign
* h
* (60 * 60 * 1000);
81 m
= nMillis
/ (60 * 1000);
82 nMillis
-= m
* (60 * 1000);
84 nMillis
-= s
* (1000);
87 static void debug_i18n_cal_dump( const ::icu::Calendar
& r
)
90 long nMillis
, h
, m
, s
, f
;
91 fprintf( stderr
, " %04ld", (long)r
.get( UCAL_YEAR
, status
= U_ZERO_ERROR
));
92 fprintf( stderr
, "-%02ld", (long)r
.get( UCAL_MONTH
, status
= U_ZERO_ERROR
)+1);
93 fprintf( stderr
, "-%02ld", (long)r
.get( UCAL_DATE
, status
= U_ZERO_ERROR
));
94 fprintf( stderr
, " %02ld", (long)r
.get( UCAL_HOUR_OF_DAY
, status
= U_ZERO_ERROR
));
95 fprintf( stderr
, ":%02ld", (long)r
.get( UCAL_MINUTE
, status
= U_ZERO_ERROR
));
96 fprintf( stderr
, ":%02ld", (long)r
.get( UCAL_SECOND
, status
= U_ZERO_ERROR
));
97 fprintf( stderr
, " zone: %ld", (long)(nMillis
= r
.get( UCAL_ZONE_OFFSET
, status
= U_ZERO_ERROR
)));
98 fprintf( stderr
, " (%f min)", (double)nMillis
/ 60000);
99 debug_cal_millis_to_time( nMillis
, h
, m
, s
, f
);
100 fprintf( stderr
, " (%ld:%02ld:%02ld.%ld)", h
, m
, s
, f
);
101 fprintf( stderr
, " DST: %ld", (long)(nMillis
= r
.get( UCAL_DST_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
, "\n");
108 // must use double parens, i.e.: DUMP_I18N_CAL_MSG(("four is: %d",4));
109 #define DUMP_I18N_CAL_MSG(x) {debug_cal_loc(__FILE__,__LINE__);debug_cal_msg x;debug_i18n_cal_dump(*body);}
110 #else // erDUMP_I18N_CALENDAR
111 #define DUMP_I18N_CAL_MSG(x)
112 #endif // erDUMP_I18N_CALENDAR
114 #else // erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
115 #define DUMP_ICU_CAL_MSG(x)
116 #define DUMP_I18N_CAL_MSG(x)
117 #endif // erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
120 using namespace ::com::sun::star::uno
;
121 using namespace ::com::sun::star::lang
;
122 using ::rtl::OUString
;
125 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
127 #define ERROR RuntimeException()
129 Calendar_gregorian::Calendar_gregorian()
133 Calendar_gregorian::Calendar_gregorian(Era
*_earArray
)
138 Calendar_gregorian::init(Era
*_eraArray
)
140 cCalendar
= "com.sun.star.i18n.Calendar_gregorian";
142 // #i102356# With icu::Calendar::createInstance(UErrorCode) in a Thai
143 // th_TH system locale we accidentally used a Buddhist calendar. Though
144 // the ICU documentation says that should be the case only for
145 // th_TH_TRADITIONAL (and ja_JP_TRADITIONAL Gengou), a plain th_TH
146 // already triggers that behavior, ja_JP does not. Strange enough,
147 // passing a th_TH locale to the calendar creation doesn't trigger
149 // See also http://userguide.icu-project.org/datetime/calendar
151 // Whatever ICU offers as the default calendar for a locale, ensure we
152 // have a Gregorian calendar as requested.
154 /* XXX: with the current implementation the aLocale member variable is
155 * not set prior to loading a calendar from locale data. This
156 * creates an empty (root) locale for ICU, but at least the correct
157 * calendar is used. The language part must not be NULL (respectively
158 * not all, language and country and variant), otherwise the current
159 * default locale would be used again and the calendar keyword ignored.
161 icu::Locale
aIcuLocale( "", NULL
, NULL
, "calendar=gregorian");
164 body
= icu::Calendar::createInstance( aIcuLocale
, status
= U_ZERO_ERROR
);
165 if (!body
|| !U_SUCCESS(status
)) throw ERROR
;
169 Calendar_gregorian::~Calendar_gregorian()
174 Calendar_hanja::Calendar_hanja()
176 cCalendar
= "com.sun.star.i18n.Calendar_hanja";
180 Calendar_hanja::getDisplayName( sal_Int16 displayIndex
, sal_Int16 idx
, sal_Int16 nameType
) throw(RuntimeException
)
182 if ( displayIndex
== CalendarDisplayIndex::AM_PM
) {
183 // Am/Pm string for Korean Hanja calendar will refer to Japanese locale
184 com::sun::star::lang::Locale jaLocale
=
185 com::sun::star::lang::Locale(OUString("ja"), OUString(), OUString());
186 if (idx
== 0) return LocaleData().getLocaleItem(jaLocale
).timeAM
;
187 else if (idx
== 1) return LocaleData().getLocaleItem(jaLocale
).timePM
;
191 return Calendar_gregorian::getDisplayName( displayIndex
, idx
, nameType
);
195 Calendar_hanja::loadCalendar( const OUString
& /*uniqueID*/, const com::sun::star::lang::Locale
& rLocale
) throw(RuntimeException
)
197 // Since this class could be called by service name 'hanja_yoil', we have to
198 // rename uniqueID to get right calendar defined in locale data.
199 Calendar_gregorian::loadCalendar(OUString("hanja"), rLocale
);
202 static Era gengou_eraArray
[] = {
209 Calendar_gengou::Calendar_gengou() : Calendar_gregorian(gengou_eraArray
)
211 cCalendar
= "com.sun.star.i18n.Calendar_gengou";
214 static Era ROC_eraArray
[] = {
218 Calendar_ROC::Calendar_ROC() : Calendar_gregorian(ROC_eraArray
)
220 cCalendar
= "com.sun.star.i18n.Calendar_ROC";
223 static Era buddhist_eraArray
[] = {
227 Calendar_buddhist::Calendar_buddhist() : Calendar_gregorian(buddhist_eraArray
)
229 cCalendar
= "com.sun.star.i18n.Calendar_buddhist";
233 Calendar_gregorian::loadCalendar( const OUString
& uniqueID
, const com::sun::star::lang::Locale
& rLocale
) throw(RuntimeException
)
235 // init. fieldValue[]
239 Sequence
< Calendar2
> xC
= LocaleData().getAllCalendars2(rLocale
);
240 for (sal_Int32 i
= 0; i
< xC
.getLength(); i
++)
242 if (uniqueID
== xC
[i
].Name
)
245 // setup minimalDaysInFirstWeek
246 setMinimumNumberOfDaysForFirstWeek(
247 aCalendar
.MinimumNumberOfDaysForFirstWeek
);
248 // setup first day of week
249 for (sal_Int16 day
= sal::static_int_cast
<sal_Int16
>(
250 aCalendar
.Days
.getLength()-1); day
>=0; day
--)
252 if (aCalendar
.StartOfWeek
== aCalendar
.Days
[day
].ID
)
254 setFirstDayOfWeek( day
);
260 // Calendar is not for the locale
265 com::sun::star::i18n::Calendar2 SAL_CALL
266 Calendar_gregorian::getLoadedCalendar2() throw(RuntimeException
)
271 com::sun::star::i18n::Calendar SAL_CALL
272 Calendar_gregorian::getLoadedCalendar() throw(RuntimeException
)
274 return LocaleData::downcastCalendar( aCalendar
);
278 Calendar_gregorian::getUniqueID() throw(RuntimeException
)
280 return aCalendar
.Name
;
284 Calendar_gregorian::setDateTime( double timeInDays
) throw(RuntimeException
)
287 body
->setTime(timeInDays
* U_MILLIS_PER_DAY
, status
= U_ZERO_ERROR
);
288 if ( !U_SUCCESS(status
) ) throw ERROR
;
293 Calendar_gregorian::getDateTime() throw(RuntimeException
)
300 double r
= body
->getTime(status
= U_ZERO_ERROR
);
301 if ( !U_SUCCESS(status
) ) throw ERROR
;
302 return r
/ U_MILLIS_PER_DAY
;
305 // map field value from gregorian calendar to other calendar, it can be overwritten by derived class.
306 // By using eraArray, it can take care Japanese and Taiwan ROC calendar.
307 void Calendar_gregorian::mapFromGregorian() throw(RuntimeException
)
310 sal_Int16 e
, y
, m
, d
;
312 e
= fieldValue
[CalendarFieldIndex::ERA
];
313 y
= fieldValue
[CalendarFieldIndex::YEAR
];
314 m
= fieldValue
[CalendarFieldIndex::MONTH
] + 1;
315 d
= fieldValue
[CalendarFieldIndex::DAY_OF_MONTH
];
317 // since the year is reversed for first era, it is reversed again here for Era compare.
321 for (e
= 0; eraArray
[e
].year
; e
++)
322 if ((y
!= eraArray
[e
].year
) ? y
< eraArray
[e
].year
:
323 (m
!= eraArray
[e
].month
) ? m
< eraArray
[e
].month
: d
< eraArray
[e
].day
)
326 fieldValue
[CalendarFieldIndex::ERA
] = e
;
327 fieldValue
[CalendarFieldIndex::YEAR
] =
328 sal::static_int_cast
<sal_Int16
>( (e
== 0) ? (eraArray
[0].year
- y
) : (y
- eraArray
[e
-1].year
+ 1) );
332 #define FIELDS ((1 << CalendarFieldIndex::ERA) | (1 << CalendarFieldIndex::YEAR))
333 // map field value from other calendar to gregorian calendar, it can be overwritten by derived class.
334 // By using eraArray, it can take care Japanese and Taiwan ROC calendar.
335 void Calendar_gregorian::mapToGregorian() throw(RuntimeException
)
337 if (eraArray
&& (fieldSet
& FIELDS
)) {
338 sal_Int16 y
, e
= fieldValue
[CalendarFieldIndex::ERA
];
340 y
= sal::static_int_cast
<sal_Int16
>( eraArray
[0].year
- fieldValue
[CalendarFieldIndex::YEAR
] );
342 y
= sal::static_int_cast
<sal_Int16
>( eraArray
[e
-1].year
+ fieldValue
[CalendarFieldIndex::YEAR
] - 1 );
344 fieldSetValue
[CalendarFieldIndex::ERA
] = y
<= 0 ? 0 : 1;
345 fieldSetValue
[CalendarFieldIndex::YEAR
] = (y
<= 0 ? 1 - y
: y
);
350 static UCalendarDateFields
fieldNameConverter(sal_Int16 fieldIndex
) throw(RuntimeException
)
352 UCalendarDateFields f
;
354 switch (fieldIndex
) {
355 case CalendarFieldIndex::AM_PM
: f
= UCAL_AM_PM
; break;
356 case CalendarFieldIndex::DAY_OF_MONTH
: f
= UCAL_DATE
; break;
357 case CalendarFieldIndex::DAY_OF_WEEK
: f
= UCAL_DAY_OF_WEEK
; break;
358 case CalendarFieldIndex::DAY_OF_YEAR
: f
= UCAL_DAY_OF_YEAR
; break;
359 case CalendarFieldIndex::DST_OFFSET
: f
= UCAL_DST_OFFSET
; break;
360 case CalendarFieldIndex::ZONE_OFFSET
: f
= UCAL_ZONE_OFFSET
; break;
361 case CalendarFieldIndex::HOUR
: f
= UCAL_HOUR_OF_DAY
; break;
362 case CalendarFieldIndex::MINUTE
: f
= UCAL_MINUTE
; break;
363 case CalendarFieldIndex::SECOND
: f
= UCAL_SECOND
; break;
364 case CalendarFieldIndex::MILLISECOND
: f
= UCAL_MILLISECOND
; break;
365 case CalendarFieldIndex::WEEK_OF_MONTH
: f
= UCAL_WEEK_OF_MONTH
; break;
366 case CalendarFieldIndex::WEEK_OF_YEAR
: f
= UCAL_WEEK_OF_YEAR
; break;
367 case CalendarFieldIndex::YEAR
: f
= UCAL_YEAR
; break;
368 case CalendarFieldIndex::MONTH
: f
= UCAL_MONTH
; break;
369 case CalendarFieldIndex::ERA
: f
= UCAL_ERA
; break;
370 default: throw ERROR
;
376 Calendar_gregorian::setValue( sal_Int16 fieldIndex
, sal_Int16 value
) throw(RuntimeException
)
378 if (fieldIndex
< 0 || FIELD_INDEX_COUNT
<= fieldIndex
)
380 fieldSet
|= (1 << fieldIndex
);
381 fieldValue
[fieldIndex
] = value
;
384 bool Calendar_gregorian::getCombinedOffset( sal_Int32
& o_nOffset
,
385 sal_Int16 nParentFieldIndex
, sal_Int16 nChildFieldIndex
) const
388 bool bFieldsSet
= false;
389 if (fieldSet
& (1 << nParentFieldIndex
))
392 o_nOffset
= static_cast<sal_Int32
>( fieldValue
[nParentFieldIndex
]) * 60000;
394 if (fieldSet
& (1 << nChildFieldIndex
))
398 o_nOffset
-= static_cast<sal_uInt16
>( fieldValue
[nChildFieldIndex
]);
400 o_nOffset
+= static_cast<sal_uInt16
>( fieldValue
[nChildFieldIndex
]);
405 bool Calendar_gregorian::getZoneOffset( sal_Int32
& o_nOffset
) const
407 return getCombinedOffset( o_nOffset
, CalendarFieldIndex::ZONE_OFFSET
,
408 CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS
);
411 bool Calendar_gregorian::getDSTOffset( sal_Int32
& o_nOffset
) const
413 return getCombinedOffset( o_nOffset
, CalendarFieldIndex::DST_OFFSET
,
414 CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS
);
417 void Calendar_gregorian::submitFields() throw(com::sun::star::uno::RuntimeException
)
419 for (sal_Int16 fieldIndex
= 0; fieldIndex
< FIELD_INDEX_COUNT
; fieldIndex
++)
421 if (fieldSet
& (1 << fieldIndex
))
426 body
->set(fieldNameConverter(fieldIndex
), fieldSetValue
[fieldIndex
]);
428 case CalendarFieldIndex::ZONE_OFFSET
:
429 case CalendarFieldIndex::DST_OFFSET
:
430 case CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS
:
431 case CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS
:
432 break; // nothing, extra handling
436 sal_Int32 nZoneOffset
, nDSTOffset
;
437 if (getZoneOffset( nZoneOffset
))
438 body
->set( fieldNameConverter( CalendarFieldIndex::ZONE_OFFSET
), nZoneOffset
);
439 if (getDSTOffset( nDSTOffset
))
440 body
->set( fieldNameConverter( CalendarFieldIndex::DST_OFFSET
), nDSTOffset
);
443 void Calendar_gregorian::submitValues( sal_Int32 nYear
,
444 sal_Int32 nMonth
, sal_Int32 nDay
, sal_Int32 nHour
, sal_Int32 nMinute
,
445 sal_Int32 nSecond
, sal_Int32 nMilliSecond
, sal_Int32 nZone
, sal_Int32 nDST
)
446 throw(com::sun::star::uno::RuntimeException
)
450 body
->set( UCAL_YEAR
, nYear
);
452 body
->set( UCAL_MONTH
, nMonth
);
454 body
->set( UCAL_DATE
, nDay
);
456 body
->set( UCAL_HOUR_OF_DAY
, nHour
);
458 body
->set( UCAL_MINUTE
, nMinute
);
460 body
->set( UCAL_SECOND
, nSecond
);
461 if (nMilliSecond
>= 0)
462 body
->set( UCAL_MILLISECOND
, nMilliSecond
);
464 body
->set( UCAL_ZONE_OFFSET
, nZone
);
466 body
->set( UCAL_DST_OFFSET
, nDST
);
469 static void lcl_setCombinedOffsetFieldValues( sal_Int32 nValue
,
470 sal_Int16 rFieldSetValue
[], sal_Int16 rFieldValue
[],
471 sal_Int16 nParentFieldIndex
, sal_Int16 nChildFieldIndex
)
473 sal_Int32 nTrunc
= nValue
/ 60000;
474 rFieldSetValue
[nParentFieldIndex
] = rFieldValue
[nParentFieldIndex
] =
475 static_cast<sal_Int16
>( nTrunc
);
476 sal_uInt16 nMillis
= static_cast<sal_uInt16
>( abs( nValue
- nTrunc
* 60000));
477 rFieldSetValue
[nChildFieldIndex
] = rFieldValue
[nChildFieldIndex
] =
478 static_cast<sal_Int16
>( nMillis
);
481 void Calendar_gregorian::setValue() throw(RuntimeException
)
483 // Correct DST glitch, see also localtime/gmtime conversion pitfalls at
484 // http://www.erack.de/download/timetest.c
486 // #i24082# in order to make the DST correction work in all
487 // circumstances, the time values have to be always resubmitted,
488 // regardless whether specified by the caller or not. It is not
489 // sufficient to rely on the ICU internal values previously set, as the
490 // following may happen:
491 // - Let 2004-03-28T02:00 be the onsetRule.
492 // - On 2004-03-29 (calendar initialized with 2004-03-29T00:00 DST) set
493 // a date of 2004-03-28 => calendar results in 2004-03-27T23:00 no DST.
494 // - Correcting this with simply "2004-03-28 no DST" and no time
495 // specified results in 2004-03-29T00:00, the ICU internal 23:00 time
496 // being adjusted to 24:00 in this case, switching one day further.
497 // => submit 2004-03-28T00:00 no DST.
499 // This got even weirder since ICU incorporated also historical data,
500 // even the timezone may differ for different dates! It is necessary to
501 // let ICU choose the corresponding OlsonTimeZone transitions and adapt
503 // #i86094# gives examples where that went wrong:
504 // TZ=Europe/Moscow date <= 1919-07-01
505 // zone +2:30:48 (!) instead of +3h, DST +2h instead of +1h
506 // TZ=America/St_Johns date <= 1935-03-30
507 // zone -3:30:52 (!) instead of -3:30
509 // Copy fields before calling submitFields() directly or indirectly below.
510 memcpy(fieldSetValue
, fieldValue
, sizeof(fieldSetValue
));
511 // Possibly setup ERA and YEAR in fieldSetValue.
514 DUMP_ICU_CAL_MSG(("%s\n","setValue() before any submission"));
515 DUMP_I18N_CAL_MSG(("%s\n","setValue() before any submission"));
517 bool bNeedZone
= !(fieldSet
& (1 << CalendarFieldIndex::ZONE_OFFSET
));
518 bool bNeedDST
= !(fieldSet
& (1 << CalendarFieldIndex::DST_OFFSET
));
519 sal_Int32 nZone1
, nDST1
, nYear
, nMonth
, nDay
, nHour
, nMinute
, nSecond
, nMilliSecond
, nZone0
, nDST0
;
520 nZone1
= nDST1
= nZone0
= nDST0
= 0;
521 nYear
= nMonth
= nDay
= nHour
= nMinute
= nSecond
= nMilliSecond
= -1;
522 if ( bNeedZone
|| bNeedDST
)
525 if ( !(fieldSet
& (1 << CalendarFieldIndex::YEAR
)) )
527 nYear
= body
->get( UCAL_YEAR
, status
= U_ZERO_ERROR
);
528 if ( !U_SUCCESS(status
) )
531 if ( !(fieldSet
& (1 << CalendarFieldIndex::MONTH
)) )
533 nMonth
= body
->get( UCAL_MONTH
, status
= U_ZERO_ERROR
);
534 if ( !U_SUCCESS(status
) )
537 if ( !(fieldSet
& (1 << CalendarFieldIndex::DAY_OF_MONTH
)) )
539 nDay
= body
->get( UCAL_DATE
, status
= U_ZERO_ERROR
);
540 if ( !U_SUCCESS(status
) )
543 if ( !(fieldSet
& (1 << CalendarFieldIndex::HOUR
)) )
545 nHour
= body
->get( UCAL_HOUR_OF_DAY
, status
= U_ZERO_ERROR
);
546 if ( !U_SUCCESS(status
) )
549 if ( !(fieldSet
& (1 << CalendarFieldIndex::MINUTE
)) )
551 nMinute
= body
->get( UCAL_MINUTE
, status
= U_ZERO_ERROR
);
552 if ( !U_SUCCESS(status
) )
555 if ( !(fieldSet
& (1 << CalendarFieldIndex::SECOND
)) )
557 nSecond
= body
->get( UCAL_SECOND
, status
= U_ZERO_ERROR
);
558 if ( !U_SUCCESS(status
) )
561 if ( !(fieldSet
& (1 << CalendarFieldIndex::MILLISECOND
)) )
563 nMilliSecond
= body
->get( UCAL_MILLISECOND
, status
= U_ZERO_ERROR
);
564 if ( !U_SUCCESS(status
) )
567 if ( !(fieldSet
& (1 << CalendarFieldIndex::ZONE_OFFSET
)) )
569 nZone0
= body
->get( UCAL_ZONE_OFFSET
, status
= U_ZERO_ERROR
);
570 if ( !U_SUCCESS(status
) )
573 if ( !(fieldSet
& (1 << CalendarFieldIndex::DST_OFFSET
)) )
575 nDST0
= body
->get( UCAL_DST_OFFSET
, status
= U_ZERO_ERROR
);
576 if ( !U_SUCCESS(status
) )
580 // Submit values to obtain a time zone and DST corresponding to the date/time.
581 submitValues( nYear
, nMonth
, nDay
, nHour
, nMinute
, nSecond
, nMilliSecond
, nZone0
, nDST0
);
583 DUMP_ICU_CAL_MSG(("%s\n","setValue() in bNeedZone||bNeedDST after submitValues()"));
584 DUMP_I18N_CAL_MSG(("%s\n","setValue() in bNeedZone||bNeedDST after submitValues()"));
585 nZone1
= body
->get( UCAL_ZONE_OFFSET
, status
= U_ZERO_ERROR
);
586 if ( !U_SUCCESS(status
) )
588 nDST1
= body
->get( UCAL_DST_OFFSET
, status
= U_ZERO_ERROR
);
589 if ( !U_SUCCESS(status
) )
593 // The original submission, may lead to a different zone/DST and
596 DUMP_ICU_CAL_MSG(("%s\n","setValue() after original submission"));
597 DUMP_I18N_CAL_MSG(("%s\n","setValue() after original submission"));
599 if ( bNeedZone
|| bNeedDST
)
602 sal_Int32 nZone2
= body
->get( UCAL_ZONE_OFFSET
, status
= U_ZERO_ERROR
);
603 if ( !U_SUCCESS(status
) )
605 sal_Int32 nDST2
= body
->get( UCAL_DST_OFFSET
, status
= U_ZERO_ERROR
);
606 if ( !U_SUCCESS(status
) )
608 if ( nZone0
!= nZone1
|| nZone2
!= nZone1
|| nDST0
!= nDST1
|| nDST2
!= nDST1
)
610 // Due to different DSTs, resulting date values may differ if
611 // DST is onset at 00:00 and the very onsetRule date was
612 // submitted with DST off => date-1 23:00, for example, which
613 // is not what we want.
614 // Resubmit all values, this time including DST => date 01:00
615 // Similar for zone differences.
616 // If already the first full submission with nZone0 and nDST0
617 // lead to date-1 23:00, the original submission was based on
618 // that date if it wasn't a full date (nDST0 set, nDST1 not
619 // set, nDST2==nDST1). If it was January 1st without year we're
620 // even off by one year now. Resubmit all values including new
621 // DST => date 00:00.
623 // Set field values accordingly in case they were used.
625 lcl_setCombinedOffsetFieldValues( nZone2
, fieldSetValue
,
626 fieldValue
, CalendarFieldIndex::ZONE_OFFSET
,
627 CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS
);
629 lcl_setCombinedOffsetFieldValues( nDST2
, fieldSetValue
,
630 fieldValue
, CalendarFieldIndex::DST_OFFSET
,
631 CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS
);
632 submitValues( nYear
, nMonth
, nDay
, nHour
, nMinute
, nSecond
, nMilliSecond
, nZone2
, nDST2
);
633 DUMP_ICU_CAL_MSG(("%s\n","setValue() after Zone/DST glitch resubmit"));
634 DUMP_I18N_CAL_MSG(("%s\n","setValue() after Zone/DST glitch resubmit"));
636 // Time zone transition => resubmit.
637 // TZ=America/St_Johns date <= 1935-03-30
638 // -3:30:52 (!) instead of -3:30
639 // if first submission included time zone -3:30 that would be wrong.
640 bool bResubmit
= false;
641 sal_Int32 nZone3
= body
->get( UCAL_ZONE_OFFSET
, status
= U_ZERO_ERROR
);
642 if ( !U_SUCCESS(status
) )
644 if (nZone3
!= nZone2
)
648 lcl_setCombinedOffsetFieldValues( nZone3
, fieldSetValue
,
649 fieldValue
, CalendarFieldIndex::ZONE_OFFSET
,
650 CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS
);
653 // If the DST onset rule says to switch from 00:00 to 01:00 and
654 // we tried to set onsetDay 00:00 with DST, the result was
655 // onsetDay-1 23:00 and no DST, which is not what we want. So
656 // once again without DST, resulting in onsetDay 01:00 and DST.
657 // Yes, this seems to be weird, but logically correct.
658 // It doesn't even have to be on an onsetDay as the DST is
659 // factored in all days by ICU and there seems to be some
661 // TZ=Asia/Tehran 1999-03-22 exposes this, for example.
662 sal_Int32 nDST3
= body
->get( UCAL_DST_OFFSET
, status
= U_ZERO_ERROR
);
663 if ( !U_SUCCESS(status
) )
665 if (nDST2
!= nDST3
&& !nDST3
)
670 fieldSetValue
[CalendarFieldIndex::DST_OFFSET
] =
671 fieldValue
[CalendarFieldIndex::DST_OFFSET
] = 0;
672 fieldSetValue
[CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS
] =
673 fieldValue
[CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS
] = 0;
678 submitValues( nYear
, nMonth
, nDay
, nHour
, nMinute
, nSecond
, nMilliSecond
, nZone3
, nDST3
);
679 DUMP_ICU_CAL_MSG(("%s\n","setValue() after Zone/DST glitch 2nd resubmit"));
680 DUMP_I18N_CAL_MSG(("%s\n","setValue() after Zone/DST glitch 2nd resubmit"));
684 #if erDUMP_ICU_CALENDAR || erDUMP_I18N_CALENDAR
686 // force icu::Calendar to recalculate
688 sal_Int32 nTmp
= body
->get( UCAL_DATE
, status
= U_ZERO_ERROR
);
689 DUMP_ICU_CAL_MSG(("%s: %d\n","setValue() result day",nTmp
));
690 DUMP_I18N_CAL_MSG(("%s: %d\n","setValue() result day",nTmp
));
695 void Calendar_gregorian::getValue() throw(RuntimeException
)
697 DUMP_ICU_CAL_MSG(("%s\n","getValue()"));
698 DUMP_I18N_CAL_MSG(("%s\n","getValue()"));
699 for (sal_Int16 fieldIndex
= 0; fieldIndex
< FIELD_INDEX_COUNT
; fieldIndex
++)
701 if (fieldIndex
== CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS
||
702 fieldIndex
== CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS
)
703 continue; // not ICU fields
705 UErrorCode status
; sal_Int32 value
= body
->get( fieldNameConverter(
706 fieldIndex
), status
= U_ZERO_ERROR
);
707 if ( !U_SUCCESS(status
) ) throw ERROR
;
709 // Convert millisecond to minute for ZONE and DST and set remainder in
711 if (fieldIndex
== CalendarFieldIndex::ZONE_OFFSET
)
713 sal_Int32 nMinutes
= value
/ 60000;
714 sal_Int16 nMillis
= static_cast<sal_Int16
>( static_cast<sal_uInt16
>(
715 abs( value
- nMinutes
* 60000)));
716 fieldValue
[CalendarFieldIndex::ZONE_OFFSET
] = static_cast<sal_Int16
>( nMinutes
);
717 fieldValue
[CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS
] = nMillis
;
719 else if (fieldIndex
== CalendarFieldIndex::DST_OFFSET
)
721 sal_Int32 nMinutes
= value
/ 60000;
722 sal_Int16 nMillis
= static_cast<sal_Int16
>( static_cast<sal_uInt16
>(
723 abs( value
- nMinutes
* 60000)));
724 fieldValue
[CalendarFieldIndex::DST_OFFSET
] = static_cast<sal_Int16
>( nMinutes
);
725 fieldValue
[CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS
] = nMillis
;
728 fieldValue
[fieldIndex
] = (sal_Int16
) value
;
730 // offset 1 since the value for week start day SunDay is different between Calendar and Weekdays.
731 if ( fieldIndex
== CalendarFieldIndex::DAY_OF_WEEK
)
732 fieldValue
[fieldIndex
]--; // UCAL_SUNDAY:/* == 1 */ ==> Weekdays::SUNDAY /* ==0 */
739 Calendar_gregorian::getValue( sal_Int16 fieldIndex
) throw(RuntimeException
)
741 if (fieldIndex
< 0 || FIELD_INDEX_COUNT
<= fieldIndex
)
749 return fieldValue
[fieldIndex
];
753 Calendar_gregorian::addValue( sal_Int16 fieldIndex
, sal_Int32 value
) throw(RuntimeException
)
755 // since ZONE and DST could not be add, we don't need to convert value here
757 body
->add(fieldNameConverter(fieldIndex
), value
, status
= U_ZERO_ERROR
);
758 if ( !U_SUCCESS(status
) ) throw ERROR
;
763 Calendar_gregorian::isValid() throw(RuntimeException
)
766 sal_Int32 tmp
= fieldSet
;
768 memcpy(fieldSetValue
, fieldValue
, sizeof(fieldSetValue
));
770 for ( sal_Int16 fieldIndex
= 0; fieldIndex
< FIELD_INDEX_COUNT
; fieldIndex
++ ) {
771 // compare only with fields that are set and reset fieldSet[]
772 if (tmp
& (1 << fieldIndex
)) {
773 if (fieldSetValue
[fieldIndex
] != fieldValue
[fieldIndex
])
781 // NativeNumberMode has different meaning between Number and Calendar for Asian locales.
782 // Here is the mapping table
783 // calendar(q/y/m/d) zh_CN zh_TW ja ko
784 // NatNum1 NatNum1/1/7/7 NatNum1/1/7/7 NatNum1/1/4/4 NatNum1/1/7/7
785 // NatNum2 NatNum2/2/8/8 NatNum2/2/8/8 NatNum2/2/5/5 NatNum2/2/8/8
786 // NatNum3 NatNum3/3/3/3 NatNum3/3/3/3 NatNum3/3/3/3 NatNum3/3/3/3
787 // NatNum4 NatNum9/9/11/11
789 static sal_Int16 SAL_CALL
NatNumForCalendar(const com::sun::star::lang::Locale
& aLocale
,
790 sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
, sal_Int16 value
)
792 sal_Bool isShort
= ((nCalendarDisplayCode
== CalendarDisplayCode::SHORT_YEAR
||
793 nCalendarDisplayCode
== CalendarDisplayCode::LONG_YEAR
) && value
>= 100) ||
794 nCalendarDisplayCode
== CalendarDisplayCode::SHORT_QUARTER
||
795 nCalendarDisplayCode
== CalendarDisplayCode::LONG_QUARTER
;
796 sal_Bool isChinese
= aLocale
.Language
== "zh";
797 sal_Bool isJapanese
= aLocale
.Language
== "ja";
798 sal_Bool isKorean
= aLocale
.Language
== "ko";
800 if (isChinese
|| isJapanese
|| isKorean
) {
801 switch (nNativeNumberMode
) {
802 case NativeNumberMode::NATNUM1
:
804 nNativeNumberMode
= isJapanese
? NativeNumberMode::NATNUM4
: NativeNumberMode::NATNUM7
;
806 case NativeNumberMode::NATNUM2
:
808 nNativeNumberMode
= isJapanese
? NativeNumberMode::NATNUM5
: NativeNumberMode::NATNUM8
;
810 case NativeNumberMode::NATNUM3
:
812 case NativeNumberMode::NATNUM4
:
814 return isShort
? NativeNumberMode::NATNUM9
: NativeNumberMode::NATNUM11
;
819 return nNativeNumberMode
;
822 static sal_Int32 SAL_CALL
DisplayCode2FieldIndex(sal_Int32 nCalendarDisplayCode
)
824 switch( nCalendarDisplayCode
) {
825 case CalendarDisplayCode::SHORT_DAY
:
826 case CalendarDisplayCode::LONG_DAY
:
827 return CalendarFieldIndex::DAY_OF_MONTH
;
828 case CalendarDisplayCode::SHORT_DAY_NAME
:
829 case CalendarDisplayCode::LONG_DAY_NAME
:
830 case CalendarDisplayCode::NARROW_DAY_NAME
:
831 return CalendarFieldIndex::DAY_OF_WEEK
;
832 case CalendarDisplayCode::SHORT_QUARTER
:
833 case CalendarDisplayCode::LONG_QUARTER
:
834 case CalendarDisplayCode::SHORT_MONTH
:
835 case CalendarDisplayCode::LONG_MONTH
:
836 case CalendarDisplayCode::SHORT_MONTH_NAME
:
837 case CalendarDisplayCode::LONG_MONTH_NAME
:
838 case CalendarDisplayCode::NARROW_MONTH_NAME
:
839 case CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME
:
840 case CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME
:
841 case CalendarDisplayCode::NARROW_GENITIVE_MONTH_NAME
:
842 case CalendarDisplayCode::SHORT_PARTITIVE_MONTH_NAME
:
843 case CalendarDisplayCode::LONG_PARTITIVE_MONTH_NAME
:
844 case CalendarDisplayCode::NARROW_PARTITIVE_MONTH_NAME
:
845 return CalendarFieldIndex::MONTH
;
846 case CalendarDisplayCode::SHORT_YEAR
:
847 case CalendarDisplayCode::LONG_YEAR
:
848 return CalendarFieldIndex::YEAR
;
849 case CalendarDisplayCode::SHORT_ERA
:
850 case CalendarDisplayCode::LONG_ERA
:
851 return CalendarFieldIndex::ERA
;
852 case CalendarDisplayCode::SHORT_YEAR_AND_ERA
:
853 case CalendarDisplayCode::LONG_YEAR_AND_ERA
:
854 return CalendarFieldIndex::YEAR
;
861 Calendar_gregorian::getFirstDayOfWeek() throw(RuntimeException
)
863 // UCAL_SUNDAY == 1, Weekdays::SUNDAY == 0 => offset -1
864 // Check for underflow just in case we're called "out of sync".
865 return ::std::max( sal::static_int_cast
<sal_Int16
>(0),
866 sal::static_int_cast
<sal_Int16
>( static_cast<sal_Int16
>(
867 body
->getFirstDayOfWeek()) - 1));
871 Calendar_gregorian::setFirstDayOfWeek( sal_Int16 day
)
872 throw(RuntimeException
)
874 // Weekdays::SUNDAY == 0, UCAL_SUNDAY == 1 => offset +1
875 body
->setFirstDayOfWeek( static_cast<UCalendarDaysOfWeek
>( day
+ 1));
879 Calendar_gregorian::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days
) throw(RuntimeException
)
881 aCalendar
.MinimumNumberOfDaysForFirstWeek
= days
;
882 body
->setMinimalDaysInFirstWeek( static_cast<uint8_t>( days
));
886 Calendar_gregorian::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException
)
888 return aCalendar
.MinimumNumberOfDaysForFirstWeek
;
892 Calendar_gregorian::getNumberOfMonthsInYear() throw(RuntimeException
)
894 return (sal_Int16
) aCalendar
.Months
.getLength();
899 Calendar_gregorian::getNumberOfDaysInWeek() throw(RuntimeException
)
901 return (sal_Int16
) aCalendar
.Days
.getLength();
905 Sequence
< CalendarItem
> SAL_CALL
906 Calendar_gregorian::getDays() throw(RuntimeException
)
908 return LocaleData::downcastCalendarItems( aCalendar
.Days
);
912 Sequence
< CalendarItem
> SAL_CALL
913 Calendar_gregorian::getMonths() throw(RuntimeException
)
915 return LocaleData::downcastCalendarItems( aCalendar
.Months
);
919 Sequence
< CalendarItem2
> SAL_CALL
920 Calendar_gregorian::getDays2() throw(RuntimeException
)
922 return aCalendar
.Days
;
926 Sequence
< CalendarItem2
> SAL_CALL
927 Calendar_gregorian::getMonths2() throw(RuntimeException
)
929 return aCalendar
.Months
;
933 Sequence
< CalendarItem2
> SAL_CALL
934 Calendar_gregorian::getGenitiveMonths2() throw(RuntimeException
)
936 return aCalendar
.GenitiveMonths
;
940 Sequence
< CalendarItem2
> SAL_CALL
941 Calendar_gregorian::getPartitiveMonths2() throw(RuntimeException
)
943 return aCalendar
.PartitiveMonths
;
948 Calendar_gregorian::getDisplayName( sal_Int16 displayIndex
, sal_Int16 idx
, sal_Int16 nameType
) throw(RuntimeException
)
952 switch( displayIndex
) {
953 case CalendarDisplayIndex::AM_PM
:/* ==0 */
954 if (idx
== 0) aStr
= LocaleData().getLocaleItem(aLocale
).timeAM
;
955 else if (idx
== 1) aStr
= LocaleData().getLocaleItem(aLocale
).timePM
;
958 case CalendarDisplayIndex::DAY
:
959 if( idx
>= aCalendar
.Days
.getLength() ) throw ERROR
;
960 if (nameType
== 0) aStr
= aCalendar
.Days
[idx
].AbbrevName
;
961 else if (nameType
== 1) aStr
= aCalendar
.Days
[idx
].FullName
;
962 else if (nameType
== 2) aStr
= aCalendar
.Days
[idx
].NarrowName
;
965 case CalendarDisplayIndex::MONTH
:
966 if( idx
>= aCalendar
.Months
.getLength() ) throw ERROR
;
967 if (nameType
== 0) aStr
= aCalendar
.Months
[idx
].AbbrevName
;
968 else if (nameType
== 1) aStr
= aCalendar
.Months
[idx
].FullName
;
969 else if (nameType
== 2) aStr
= aCalendar
.Months
[idx
].NarrowName
;
972 case CalendarDisplayIndex::GENITIVE_MONTH
:
973 if( idx
>= aCalendar
.GenitiveMonths
.getLength() ) throw ERROR
;
974 if (nameType
== 0) aStr
= aCalendar
.GenitiveMonths
[idx
].AbbrevName
;
975 else if (nameType
== 1) aStr
= aCalendar
.GenitiveMonths
[idx
].FullName
;
976 else if (nameType
== 2) aStr
= aCalendar
.GenitiveMonths
[idx
].NarrowName
;
979 case CalendarDisplayIndex::PARTITIVE_MONTH
:
980 if( idx
>= aCalendar
.PartitiveMonths
.getLength() ) throw ERROR
;
981 if (nameType
== 0) aStr
= aCalendar
.PartitiveMonths
[idx
].AbbrevName
;
982 else if (nameType
== 1) aStr
= aCalendar
.PartitiveMonths
[idx
].FullName
;
983 else if (nameType
== 2) aStr
= aCalendar
.PartitiveMonths
[idx
].NarrowName
;
986 case CalendarDisplayIndex::ERA
:
987 if( idx
>= aCalendar
.Eras
.getLength() ) throw ERROR
;
988 if (nameType
== 0) aStr
= aCalendar
.Eras
[idx
].AbbrevName
;
989 else if (nameType
== 1) aStr
= aCalendar
.Eras
[idx
].FullName
;
992 case CalendarDisplayIndex::YEAR
:
1000 // Methods in XExtendedCalendar
1002 Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
)
1003 throw (RuntimeException
)
1005 sal_Int16 value
= getValue(sal::static_int_cast
<sal_Int16
>( DisplayCode2FieldIndex(nCalendarDisplayCode
) ));
1008 if (nCalendarDisplayCode
== CalendarDisplayCode::SHORT_QUARTER
||
1009 nCalendarDisplayCode
== CalendarDisplayCode::LONG_QUARTER
) {
1010 Sequence
< OUString
> xR
= LocaleData().getReservedWord(aLocale
);
1011 sal_Int16 quarter
= value
/ 3;
1012 // Since this base class method may be called by derived calendar
1013 // classes where a year consists of more than 12 months we need a check
1014 // to not run out of bounds of reserved quarter words. Perhaps a more
1015 // clean way (instead of dividing by 3) would be to first get the
1016 // number of months, divide by 4 and then use that result to divide the
1017 // actual month value.
1020 quarter
= sal::static_int_cast
<sal_Int16
>( quarter
+
1021 ((nCalendarDisplayCode
== CalendarDisplayCode::SHORT_QUARTER
) ?
1022 reservedWords::QUARTER1_ABBREVIATION
: reservedWords::QUARTER1_WORD
) );
1023 aOUStr
= xR
[quarter
];
1025 // The "#100211# - checked" comments serve for detection of "use of
1026 // sprintf is safe here" conditions. An sprintf encountered without
1027 // having that comment triggers alarm ;-)
1029 switch( nCalendarDisplayCode
) {
1030 case CalendarDisplayCode::SHORT_MONTH
:
1031 value
+= 1; // month is zero based
1033 case CalendarDisplayCode::SHORT_DAY
:
1034 sprintf(aStr
, "%d", value
); // #100211# - checked
1036 case CalendarDisplayCode::LONG_YEAR
:
1037 if ( aCalendar
.Name
== "gengou" )
1038 sprintf(aStr
, "%02d", value
); // #100211# - checked
1040 sprintf(aStr
, "%d", value
); // #100211# - checked
1042 case CalendarDisplayCode::LONG_MONTH
:
1043 value
+= 1; // month is zero based
1044 sprintf(aStr
, "%02d", value
); // #100211# - checked
1046 case CalendarDisplayCode::SHORT_YEAR
:
1047 // Take last 2 digits, or only one if value<10, for example,
1048 // in case of the Gengou calendar.
1049 // #i116701# For values in non-Gregorian era years use all
1051 if (value
< 100 || eraArray
)
1052 sprintf(aStr
, "%d", value
); // #100211# - checked
1054 sprintf(aStr
, "%02d", value
% 100); // #100211# - checked
1056 case CalendarDisplayCode::LONG_DAY
:
1057 sprintf(aStr
, "%02d", value
); // #100211# - checked
1060 case CalendarDisplayCode::SHORT_DAY_NAME
:
1061 return getDisplayName(CalendarDisplayIndex::DAY
, value
, 0);
1062 case CalendarDisplayCode::LONG_DAY_NAME
:
1063 return getDisplayName(CalendarDisplayIndex::DAY
, value
, 1);
1064 case CalendarDisplayCode::NARROW_DAY_NAME
:
1065 return getDisplayName(CalendarDisplayIndex::DAY
, value
, 2);
1066 case CalendarDisplayCode::SHORT_MONTH_NAME
:
1067 return getDisplayName(CalendarDisplayIndex::MONTH
, value
, 0);
1068 case CalendarDisplayCode::LONG_MONTH_NAME
:
1069 return getDisplayName(CalendarDisplayIndex::MONTH
, value
, 1);
1070 case CalendarDisplayCode::NARROW_MONTH_NAME
:
1071 return getDisplayName(CalendarDisplayIndex::MONTH
, value
, 2);
1072 case CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME
:
1073 return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH
, value
, 0);
1074 case CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME
:
1075 return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH
, value
, 1);
1076 case CalendarDisplayCode::NARROW_GENITIVE_MONTH_NAME
:
1077 return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH
, value
, 2);
1078 case CalendarDisplayCode::SHORT_PARTITIVE_MONTH_NAME
:
1079 return getDisplayName(CalendarDisplayIndex::PARTITIVE_MONTH
, value
, 0);
1080 case CalendarDisplayCode::LONG_PARTITIVE_MONTH_NAME
:
1081 return getDisplayName(CalendarDisplayIndex::PARTITIVE_MONTH
, value
, 1);
1082 case CalendarDisplayCode::NARROW_PARTITIVE_MONTH_NAME
:
1083 return getDisplayName(CalendarDisplayIndex::PARTITIVE_MONTH
, value
, 2);
1084 case CalendarDisplayCode::SHORT_ERA
:
1085 return getDisplayName(CalendarDisplayIndex::ERA
, value
, 0);
1086 case CalendarDisplayCode::LONG_ERA
:
1087 return getDisplayName(CalendarDisplayIndex::ERA
, value
, 1);
1089 case CalendarDisplayCode::SHORT_YEAR_AND_ERA
:
1090 return getDisplayString( CalendarDisplayCode::SHORT_ERA
, nNativeNumberMode
) +
1091 getDisplayString( CalendarDisplayCode::SHORT_YEAR
, nNativeNumberMode
);
1093 case CalendarDisplayCode::LONG_YEAR_AND_ERA
:
1094 return getDisplayString( CalendarDisplayCode::LONG_ERA
, nNativeNumberMode
) +
1095 getDisplayString( CalendarDisplayCode::LONG_YEAR
, nNativeNumberMode
);
1100 aOUStr
= OUString::createFromAscii(aStr
);
1102 if (nNativeNumberMode
> 0) {
1103 // For Japanese calendar, first year calls GAN, see bug 111668 for detail.
1104 if (eraArray
== gengou_eraArray
&& value
== 1
1105 && (nCalendarDisplayCode
== CalendarDisplayCode::SHORT_YEAR
||
1106 nCalendarDisplayCode
== CalendarDisplayCode::LONG_YEAR
)
1107 && (nNativeNumberMode
== NativeNumberMode::NATNUM1
||
1108 nNativeNumberMode
== NativeNumberMode::NATNUM2
)) {
1109 static sal_Unicode gan
= 0x5143;
1110 return OUString(&gan
, 1);
1112 sal_Int16 nNatNum
= NatNumForCalendar(aLocale
, nCalendarDisplayCode
, nNativeNumberMode
, value
);
1114 return aNatNum
.getNativeNumberString(aOUStr
, aLocale
, nNatNum
);
1119 // Methods in XExtendedCalendar
1121 Calendar_buddhist::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
)
1122 throw (RuntimeException
)
1124 // make year and era in different order for year before and after 0.
1125 if ((nCalendarDisplayCode
== CalendarDisplayCode::LONG_YEAR_AND_ERA
||
1126 nCalendarDisplayCode
== CalendarDisplayCode::SHORT_YEAR_AND_ERA
) &&
1127 getValue(CalendarFieldIndex::ERA
) == 0) {
1128 if (nCalendarDisplayCode
== CalendarDisplayCode::LONG_YEAR_AND_ERA
)
1129 return getDisplayString( CalendarDisplayCode::SHORT_YEAR
, nNativeNumberMode
) +
1130 getDisplayString( CalendarDisplayCode::SHORT_ERA
, nNativeNumberMode
);
1132 return getDisplayString( CalendarDisplayCode::LONG_YEAR
, nNativeNumberMode
) +
1133 getDisplayString( CalendarDisplayCode::LONG_ERA
, nNativeNumberMode
);
1135 return Calendar_gregorian::getDisplayString(nCalendarDisplayCode
, nNativeNumberMode
);
1139 Calendar_gregorian::getImplementationName(void) throw( RuntimeException
)
1141 return OUString::createFromAscii(cCalendar
);
1145 Calendar_gregorian::supportsService(const rtl::OUString
& rServiceName
) throw( RuntimeException
)
1147 return !rServiceName
.compareToAscii(cCalendar
);
1150 Sequence
< OUString
> SAL_CALL
1151 Calendar_gregorian::getSupportedServiceNames(void) throw( RuntimeException
)
1153 Sequence
< OUString
> aRet(1);
1154 aRet
[0] = OUString::createFromAscii(cCalendar
);
1160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */