2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FLcl_IcuCalendarImpl.cpp
20 * @brief This is the implementation file for _IcuCalendarImpl class.
23 #include <unique_ptr.h>
24 #include <unicode/errorcode.h>
25 #include <unicode/simpletz.h>
26 #include <unicode/calendar.h>
27 #include <unicode/gregocal.h>
29 #include <FLclLocale.h>
30 #include <FLclTimeZone.h>
31 #include <FLclCalendar.h>
33 #include <FBase_StringConverter.h>
34 #include <FBaseSysLog.h>
36 #include "FLcl_LocaleData.h"
37 #include "FLcl_IcuCalendarImpl.h"
38 #include "FLcl_TimeZoneImpl.h"
41 typedef U_ICU_NAMESPACE::ErrorCode IcuErrorCode;
42 typedef U_ICU_NAMESPACE::Locale IcuLocale;
43 typedef U_ICU_NAMESPACE::Calendar IcuCalendar;
44 typedef U_ICU_NAMESPACE::GregorianCalendar IcuGregorianCalendar;
45 typedef U_ICU_NAMESPACE::TimeZone IcuTimeZone;
46 typedef U_ICU_NAMESPACE::SimpleTimeZone IcuSimpleTimeZone;
48 using namespace Tizen::Base;
50 static const long long _EPOCH_OFFSET_IN_MILLISEC = 62135596800000LL;
51 static const int _GREGORIAN_DEFAULT_YEAR = 1970;
53 namespace Tizen { namespace Locales
56 _IcuCalendarImpl::_IcuCalendarImpl()
57 : __pIcuCalendar(null)
58 , __isEraFieldOverFlowed(false)
62 _IcuCalendarImpl::~_IcuCalendarImpl()
64 delete __pIcuCalendar;
65 __pIcuCalendar = null;
69 _IcuCalendarImpl::Construct(const TimeZone& timeZone, const Locale& locale, int calendarType)
71 // Object is not allowed to construct twice
72 SysAssertf(__pIcuCalendar == null,
73 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
75 IcuLocale icuLocale = GetIcuLocale(locale, calendarType);
76 result r = GetLastResult();
79 const _TimeZoneImpl* pTimeZoneImpl = _TimeZoneImpl::GetTimeZoneImpl(timeZone);
83 __pIcuCalendar = IcuCalendar::createInstance(pTimeZoneImpl->GetIcuTimeZone().clone(), icuLocale, err);
84 r = GetOspException(err);
91 _IcuCalendarImpl::CloneN(void)
93 std::unique_ptr< _IcuCalendarImpl > pIcuCalendar(new (std::nothrow) _IcuCalendarImpl);
94 SysTryReturn(NID_LCL, pIcuCalendar != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
96 if (__pIcuCalendar != null)
98 pIcuCalendar->__pIcuCalendar = __pIcuCalendar->clone();
99 if (pIcuCalendar->__pIcuCalendar != null)
101 pIcuCalendar->__isEraFieldOverFlowed = __isEraFieldOverFlowed;
105 return pIcuCalendar.release();
109 _IcuCalendarImpl::AddTimeField(int field, int amount)
111 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
113 // Uncomment these lines if OSP values are set to be in minutes
114 // if (field == TIME_FIELD_ZONE_OFFSET || field == TIME_FIELD_DST_OFFSET)
116 // amount *= Calendar::ONE_MINUTE_IN_MILLISEC;
120 __pIcuCalendar->add(static_cast< UCalendarDateFields >(GetIcuTimeField(field)), amount, err);
122 return GetOspException(err);
126 _IcuCalendarImpl::After(const _IcuCalendarImpl& otherInstance, bool& after)
128 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
129 SysTryReturnResult(NID_LCL, otherInstance.__pIcuCalendar, E_INVALID_ARG, "otherInstance is not constructed");
131 result r = ValidateFieldsForOverFlow();
132 SysTryReturn(NID_LCL, !IsFailed(r), r, r, "[%s] Fields values are not valid", GetErrorMessage(r));
134 r = otherInstance.ValidateFieldsForOverFlow();
135 SysTryReturn(NID_LCL, !IsFailed(r), r, r, "[%s] otherInstance's Fields values are not valid", GetErrorMessage(r));
138 after = __pIcuCalendar->after(*(otherInstance.__pIcuCalendar), err);
139 return GetOspException(err);
143 _IcuCalendarImpl::Before(const _IcuCalendarImpl& otherInstance, bool& before)
145 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
146 SysTryReturnResult(NID_LCL, otherInstance.__pIcuCalendar, E_INVALID_ARG, "otherInstance is not constructed");
148 result r = ValidateFieldsForOverFlow();
149 SysTryReturn(NID_LCL, !IsFailed(r), r, r, "[%s] Fields values are not valid", GetErrorMessage(r));
151 r = otherInstance.ValidateFieldsForOverFlow();
152 SysTryReturn(NID_LCL, !IsFailed(r), r, r, "[%s] otherInstance's Fields values are not valid", GetErrorMessage(r));
155 before = __pIcuCalendar->before(*(otherInstance.__pIcuCalendar), err);
156 return GetOspException(err);
160 _IcuCalendarImpl::Clear(void)
162 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
164 __pIcuCalendar->clear();
169 _IcuCalendarImpl::Clear(int field)
171 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
173 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
174 SysTryReturnResult(NID_LCL, icuTimeField != UCAL_FIELD_COUNT,
175 E_INVALID_ARG, "Invalid argument is used. Input field value is not supported");
177 // Hack to reset year field to 1970 while clearing TIME_FIELD_YEAR in GregorianCalendar
178 if (icuTimeField == UCAL_YEAR)
180 IcuGregorianCalendar* pCal = dynamic_cast< IcuGregorianCalendar* >(__pIcuCalendar);
184 pCal->set(UCAL_YEAR, _GREGORIAN_DEFAULT_YEAR);
189 __pIcuCalendar->clear(icuTimeField);
194 _IcuCalendarImpl::Equals(const _IcuCalendarImpl& otherInstance)
196 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
197 if (otherInstance.__pIcuCalendar != null)
199 return *__pIcuCalendar == *otherInstance.__pIcuCalendar;
205 _IcuCalendarImpl::GetActualMaxTimeField(int field) const
207 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
209 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
210 if (icuTimeField != UCAL_FIELD_COUNT)
213 int value = __pIcuCalendar->getActualMaximum(icuTimeField, err);
216 SetLastResult(E_SUCCESS);
217 return ConvertToOspTimeFieldValue(field, value);
221 SetLastResult(E_INVALID_ARG);
226 _IcuCalendarImpl::GetActualMinTimeField(int field) const
228 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
230 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
231 if (icuTimeField != UCAL_FIELD_COUNT)
234 int value = __pIcuCalendar->getActualMinimum(icuTimeField, err);
237 SetLastResult(E_SUCCESS);
238 return ConvertToOspTimeFieldValue(field, value);
240 SetLastResult(E_SYSTEM);
243 SetLastResult(E_INVALID_ARG);
248 _IcuCalendarImpl::GetFirstDayOfWeek(void) const
250 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
253 int value = __pIcuCalendar->getFirstDayOfWeek(err); // ICU DAY of week and OSP day of week are similar
263 _IcuCalendarImpl::GetGreatestMinTimeField(int field) const
265 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
267 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
268 if (icuTimeField != UCAL_FIELD_COUNT)
270 SetLastResult(E_SUCCESS);
271 int value = __pIcuCalendar->getGreatestMinimum(icuTimeField);
272 return ConvertToOspTimeFieldValue(field, value);
275 SetLastResult(E_INVALID_ARG);
280 _IcuCalendarImpl::GetHashCode(void) const
282 return (int) E_UNSUPPORTED_OPERATION;
286 _IcuCalendarImpl::GetLeastMaxTimeField(int field) const
288 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
290 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
291 if (icuTimeField != UCAL_FIELD_COUNT)
293 SetLastResult(E_SUCCESS);
294 int value = __pIcuCalendar->getLeastMaximum(icuTimeField);
295 return ConvertToOspTimeFieldValue(field, value);
298 SetLastResult(E_INVALID_ARG);
303 _IcuCalendarImpl::GetMaxTimeField(int field) const
305 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
307 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
308 if (icuTimeField != UCAL_FIELD_COUNT)
310 SetLastResult(E_SUCCESS);
311 int value = __pIcuCalendar->getMaximum(icuTimeField);
312 return ConvertToOspTimeFieldValue(field, value);
315 SetLastResult(E_INVALID_ARG);
320 _IcuCalendarImpl::GetMinDaysInFirstWeek(void) const
322 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
323 return __pIcuCalendar->getMinimalDaysInFirstWeek();
327 _IcuCalendarImpl::GetMinTimeField(int field) const
329 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
331 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
332 if (icuTimeField != UCAL_FIELD_COUNT)
334 SetLastResult(E_SUCCESS);
335 int value = __pIcuCalendar->getMinimum(icuTimeField);
336 return ConvertToOspTimeFieldValue(field, value);
339 SetLastResult(E_INVALID_ARG);
344 _IcuCalendarImpl::GetTimeField(int field) const
346 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
348 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
349 if (icuTimeField != UCAL_FIELD_COUNT)
352 int value = __pIcuCalendar->get(icuTimeField, err);
355 return ConvertToOspTimeFieldValue(field, value);
357 SetLastResult(GetOspException(err));
364 _IcuCalendarImpl::GetTimeInMillisec(long long& millisec) const
366 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
368 result r = ValidateFieldsForOverFlow();
369 SysTryReturn(NID_LCL, !IsFailed(r), r, r, "[%s]Instance is not constructed", GetErrorMessage(r));
372 millisec = __pIcuCalendar->getTime(err);
375 millisec += _EPOCH_OFFSET_IN_MILLISEC;
378 return GetOspException(err);
382 _IcuCalendarImpl::IsInDst(bool& isInDst) const
384 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
386 result r = ValidateFieldsForOverFlow();
387 SysTryReturn(NID_LCL, !IsFailed(r), r, r, "[%s] Fields values are not valid", GetErrorMessage(r));
390 isInDst = __pIcuCalendar->inDaylightTime(err);
391 return GetOspException(err);
395 _IcuCalendarImpl::IsLeapYear(int year) const
397 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
399 IcuGregorianCalendar* pCal = dynamic_cast< IcuGregorianCalendar* >(__pIcuCalendar);
404 year = 1 - year; // to adjust year as year 0 to 1 BC, -1 to 2 BC and so on
406 return pCal->isLeapYear(year);
412 _IcuCalendarImpl::IsLenient(void) const
414 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
415 return __pIcuCalendar->isLenient();
419 _IcuCalendarImpl::IsSet(int field) const
421 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
423 UCalendarDateFields icuTimeField = static_cast< UCalendarDateFields >(GetIcuTimeField(field));
424 if (icuTimeField != UCAL_FIELD_COUNT)
426 return __pIcuCalendar->isSet(icuTimeField);
433 _IcuCalendarImpl::Roll(int field, int amount)
435 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
437 result r = ValidateFieldsForOverFlow();
440 // Non Roll-able fields
441 if (field == TIME_FIELD_ZONE_OFFSET || field == TIME_FIELD_DST_OFFSET)
443 return E_INVALID_ARG;
446 field = GetIcuTimeField(field);
447 if (field != UCAL_FIELD_COUNT)
450 __pIcuCalendar->roll(static_cast< UCalendarDateFields >(field), amount, err);
451 return GetOspException(err);
453 return E_INVALID_ARG;
459 _IcuCalendarImpl::SetFirstDayOfWeek(int dayOfWeek)
461 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
463 if (dayOfWeek >= UCAL_SUNDAY && dayOfWeek <= UCAL_SATURDAY)
465 __pIcuCalendar->setFirstDayOfWeek(static_cast< UCalendarDaysOfWeek >(dayOfWeek));
468 return E_INVALID_ARG;
473 _IcuCalendarImpl::SetLenient(bool lenient)
475 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
477 __pIcuCalendar->setLenient(lenient);
482 _IcuCalendarImpl::SetMinDaysInFirstWeek(short value)
484 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
486 __pIcuCalendar->setMinimalDaysInFirstWeek(static_cast< byte >(value));
491 _IcuCalendarImpl::SetTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
493 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
494 UErrorCode ec = U_ZERO_ERROR;
495 UDate old = __pIcuCalendar->getTime(ec);
496 __pIcuCalendar->set(year, month - 1, day, hour, minute, second);
497 __pIcuCalendar->set(UCAL_MILLISECOND, millisecond);
500 __pIcuCalendar->getTime(ec);
504 __pIcuCalendar->setTime(old, ec);
505 return E_OUT_OF_RANGE;
512 _IcuCalendarImpl::SetTimeField(int field, int value)
514 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
516 field = GetIcuTimeField(field);
517 if (field != UCAL_FIELD_COUNT)
519 CheckInputFieldValueForOverFlow(field, value);
521 __pIcuCalendar->set(static_cast< UCalendarDateFields >(field), ConvertFromOspTimeFieldValue(field, value));
524 return E_INVALID_ARG;
528 _IcuCalendarImpl::SetTimeInMillisec(long long millisec)
530 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
532 millisec -= _EPOCH_OFFSET_IN_MILLISEC;
535 __pIcuCalendar->setTime(static_cast< UDate >(millisec), err);
536 return GetOspException(err);
540 _IcuCalendarImpl::SetTimeZone(const TimeZone& timeZone)
542 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
544 const _TimeZoneImpl* pTimeZoneImpl = _TimeZoneImpl::GetTimeZoneImpl(timeZone);
547 __pIcuCalendar->adoptTimeZone(pTimeZoneImpl->GetIcuTimeZone().clone());
553 _IcuCalendarImpl::GetGregorianChange(void) const
555 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
556 IcuGregorianCalendar* pCal = dynamic_cast< IcuGregorianCalendar* >(__pIcuCalendar);
559 return pCal->getGregorianChange() + _EPOCH_OFFSET_IN_MILLISEC;
565 _IcuCalendarImpl::SetGregorianChange(long long change)
567 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
568 IcuGregorianCalendar* pCal = dynamic_cast< IcuGregorianCalendar* >(__pIcuCalendar);
571 change -= _EPOCH_OFFSET_IN_MILLISEC;
573 pCal->setGregorianChange(change, err);
574 return GetOspException(err);
576 return E_UNSUPPORTED_OPERATION;
580 _IcuCalendarImpl::GetJulianDay(void) const
582 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
583 IcuGregorianCalendar* pCal = dynamic_cast< IcuGregorianCalendar* >(__pIcuCalendar);
587 return pCal->get(UCAL_JULIAN_DAY, err);
593 _IcuCalendarImpl::SetJulianDay(int julianDay)
595 SysAssertf(__pIcuCalendar != null, "Not yet constructed! Construct() should be called before use.");
596 IcuGregorianCalendar* pCal = dynamic_cast< IcuGregorianCalendar* >(__pIcuCalendar);
599 pCal->set(UCAL_JULIAN_DAY, julianDay);
602 return E_UNSUPPORTED_OPERATION;
606 _IcuCalendarImpl::GetOspException(IcuErrorCode icuException) const
608 if (U_SUCCESS(icuException))
613 //SysTryLog(NID_LCL, false, "ICU Exception: %s", icuException.errorName());
615 result r = E_SUCCESS;
616 switch (icuException)
618 case U_ILLEGAL_ARGUMENT_ERROR:
628 case U_MEMORY_ALLOCATION_ERROR:
643 _IcuCalendarImpl::GetIcuTimeField(int field) const
645 int res = UCAL_FIELD_COUNT;
654 case TIME_FIELD_YEAR:
660 case TIME_FIELD_MONTH:
666 case TIME_FIELD_WEEK_OF_YEAR:
668 res = UCAL_WEEK_OF_YEAR;
672 case TIME_FIELD_WEEK_OF_MONTH:
674 res = UCAL_WEEK_OF_MONTH;
678 case TIME_FIELD_DAY_OF_MONTH:
680 res = UCAL_DAY_OF_MONTH;
684 case TIME_FIELD_DAY_OF_YEAR:
686 res = UCAL_DAY_OF_YEAR;
690 case TIME_FIELD_DAY_OF_WEEK:
692 res = UCAL_DAY_OF_WEEK;
696 case TIME_FIELD_DAY_OF_WEEK_IN_MONTH:
698 res = UCAL_DAY_OF_WEEK_IN_MONTH;
702 case TIME_FIELD_AM_PM:
708 case TIME_FIELD_HOUR:
714 case TIME_FIELD_HOUR_OF_DAY:
716 res = UCAL_HOUR_OF_DAY;
720 case TIME_FIELD_MINUTE:
726 case TIME_FIELD_SECOND:
732 case TIME_FIELD_MILLISECOND:
734 res = UCAL_MILLISECOND;
738 case TIME_FIELD_ZONE_OFFSET:
740 res = UCAL_ZONE_OFFSET;
744 case TIME_FIELD_DST_OFFSET:
746 res = UCAL_DST_OFFSET;
752 res = UCAL_FIELD_COUNT;
760 _IcuCalendarImpl::ConvertFromOspTimeFieldValue(int field, int value) const
765 case TIME_FIELD_MONTH:
769 case TIME_FIELD_ZONE_OFFSET: // fall through
770 case TIME_FIELD_DST_OFFSET: // fall through
771 // Uncomment these lines if OSP values are set to be in minutes
772 // res *= Calendar::ONE_MINUTE_IN_MILLISEC;
775 case TIME_FIELD_ERA: // fall through
776 case TIME_FIELD_YEAR: // fall through
777 case TIME_FIELD_WEEK_OF_YEAR: // fall through
778 case TIME_FIELD_WEEK_OF_MONTH: // fall through
779 case TIME_FIELD_DAY_OF_MONTH: // fall through
780 case TIME_FIELD_DAY_OF_YEAR: // fall through
781 case TIME_FIELD_DAY_OF_WEEK: // fall through
782 case TIME_FIELD_DAY_OF_WEEK_IN_MONTH: // fall through
783 case TIME_FIELD_AM_PM: // fall through
784 case TIME_FIELD_HOUR: // fall through
785 case TIME_FIELD_HOUR_OF_DAY: // fall through
786 case TIME_FIELD_MINUTE: // fall through
787 case TIME_FIELD_SECOND: // fall through
788 case TIME_FIELD_MILLISECOND: // fall through
797 _IcuCalendarImpl::ConvertToOspTimeFieldValue(int field, int value) const
802 case TIME_FIELD_MONTH:
806 case TIME_FIELD_ZONE_OFFSET: // fall through
807 case TIME_FIELD_DST_OFFSET: // fall through
808 // Uncomment these lines if OSP values are set to be in minutes
809 // res /= Calendar::ONE_MINUTE_IN_MILLISEC;
812 case TIME_FIELD_ERA: // fall through
813 case TIME_FIELD_YEAR: // fall through
814 case TIME_FIELD_WEEK_OF_YEAR: // fall through
815 case TIME_FIELD_WEEK_OF_MONTH: // fall through
816 case TIME_FIELD_DAY_OF_MONTH: // fall through
817 case TIME_FIELD_DAY_OF_YEAR: // fall through
818 case TIME_FIELD_DAY_OF_WEEK: // fall through
819 case TIME_FIELD_DAY_OF_WEEK_IN_MONTH: // fall through
820 case TIME_FIELD_AM_PM: // fall through
821 case TIME_FIELD_HOUR: // fall through
822 case TIME_FIELD_HOUR_OF_DAY: // fall through
823 case TIME_FIELD_MINUTE: // fall through
824 case TIME_FIELD_SECOND: // fall through
825 case TIME_FIELD_MILLISECOND: // fall through
834 _IcuCalendarImpl::GetIcuLocale(const Locale& ospLocale, int type) const
837 String localeStr = ospLocale.GetLocaleCodeString();
838 if (!localeStr.IsEmpty())
842 case CALENDAR_GREGORIAN:
843 localeStr += "@calendar=gregorian";
846 case CALENDAR_BUDDHIST:
847 localeStr += "@calendar=buddhist";
850 case CALENDAR_CHINESE:
851 localeStr += "@calendar=chinese";
854 case CALENDAR_COPTIC:
855 localeStr += "@calendar=coptic";
858 case CALENDAR_ETHIOPIC_AMETE_ALEM:
859 localeStr += "@calendar=ethiopic-amete-alem";
862 case CALENDAR_ETHIOPIC:
863 localeStr += "@calendar=ethiopic";
866 case CALENDAR_HEBREW:
867 localeStr += "@calendar=hebrew";
870 case CALENDAR_INDIAN:
871 localeStr += "@calendar=indian";
874 case CALENDAR_ISLAMIC:
875 localeStr += "@calendar=islamic";
878 case CALENDAR_ISLAMIC_CIVIL:
879 localeStr += "@calendar=islamic-civil";
882 case CALENDAR_JAPANESE:
883 localeStr += "@calendar=japanese";
886 case CALENDAR_PERSIAN:
887 localeStr += "@calendar=persian";
891 localeStr += "@calendar=roc";
894 case CALENDAR_TAIWAN:
895 localeStr += "@calendar=taiwan";
898 case CALENDAR_ISO8601:
899 localeStr += "@calendar=iso8601";
903 localeStr += "@calendar=gregorian";
908 std::unique_ptr< char [] > pLclStr(_StringConverter::CopyToCharArrayN(localeStr));
909 IcuLocale icuLocale = IcuLocale(pLclStr.get());
910 if (icuLocale.isBogus())
912 SetLastResult(E_SYSTEM);
919 _IcuCalendarImpl::GetIcuTimeZone(const TimeZone& ospTimeZone) const
921 String timeZoneId = ospTimeZone.GetId();
922 std::unique_ptr< char [] > pTimezoneStr(_StringConverter::CopyToCharArrayN(timeZoneId));
923 if (pTimezoneStr != null)
925 int rawOffset = ospTimeZone.GetRawOffset() * 60 * 1000;
926 std::unique_ptr< IcuSimpleTimeZone > pIcuTimeZone(new IcuSimpleTimeZone(rawOffset, pTimezoneStr.get()));
927 if (pIcuTimeZone != null)
930 result r = lclData.SetStartTimeRule(*pIcuTimeZone, ospTimeZone.GetDstStartingRule());
933 r = lclData.SetEndTimeRule(*pIcuTimeZone, ospTimeZone.GetDstEndingRule());
936 // ClearLastResult();
937 // return pIcuTimeZone;
941 return pIcuTimeZone.release();
945 SetLastResult(E_SYSTEM);
950 _IcuCalendarImpl::CheckInputFieldValueForOverFlow(int field, int value)
952 if (field == TIME_FIELD_ERA)
954 __isEraFieldOverFlowed = (value < GetMinTimeField(TIME_FIELD_ERA)) || (value > GetMaxTimeField(TIME_FIELD_ERA));
959 _IcuCalendarImpl::ValidateFieldsForOverFlow(void) const
961 if (__isEraFieldOverFlowed)
965 return E_OUT_OF_RANGE;
967 return E_INVALID_STATE;
973 _IcuCalendarImpl::GetIcuCalendarCloneN(void) const
977 return __pIcuCalendar->clone();