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 FLclLocaleData.cpp
20 * @brief This is the implementation file for _LocaleData class.
29 #include <runtime_info.h>
30 #include <unique_ptr.h>
31 #include <FBaseSysLog.h>
32 #include <FSysSettingInfo.h>
33 #include <FLclNumberSymbols.h>
34 #include <FApp_AppInfo.h>
35 #include "FBase_StringConverter.h"
36 #include "FLcl_DateTimeSymbolsImpl.h"
37 #include "FLcl_CalendarImpl.h"
38 #include "FLcl_IcuCalendarImpl.h"
39 #include "FLcl_LocaleData.h"
40 #include "FLcl_LocaleImpl.h"
44 #define LOCALE_DATA_NUM_OF_MILLISEC_IN_HOUR 3600000LL // number of mili second in a hour
45 #define LOCALE_DATA_NUM_OF_MILLISEC_IN_MINUTE 60000LL // number of mili second in a minute
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Utility;
51 namespace Tizen { namespace Locales
54 /////////////////////////////////////////////////////////////////////////////////////////////////////
57 // this function is to convert ICU FieldPosition from OSP _FieldPosition
59 _LocaleData::GetIcuFieldPosition(_FieldPosition pos)
61 IcuFieldPosition icuPos(pos.GetField()); // Create IcuFieldPosition with field value in pos
62 icuPos.setBeginIndex(pos.GetBeginIndex()); // Set Beginning index
63 icuPos.setEndIndex(pos.GetEndIndex()); // Set End index
67 U_ICU_NAMESPACE::UnicodeString
68 _LocaleData::GetIcuString(const String& ospStr)
70 IcuUnicodeString icuStr;
72 if (!ospStr.IsEmpty()) // if ospStr is not empty
74 ByteBuffer* pBuff = null;
75 pBuff = StringUtil::StringToUtf8N(ospStr); // Convert unicode value to UTF8
78 icuStr = IcuUnicodeString((const char*) pBuff->GetPointer()); // Create ICU string using UTF8 array
79 icuStr.setCharAt(0, icuStr.charAt(0)); // This is to handle ICU copy on write design
80 delete pBuff; // delete temporary buffer
87 // This function convert ICU string to OSP string
89 _LocaleData::GetOspString(const IcuUnicodeString& icuStr)
91 int len = icuStr.length(); // get length
92 if (len > 0) // if icuStr is not empty
94 wchar_t wstr[len + 1];
95 IcuUnicodeString tmpIcuStr(icuStr);
96 for (int i = 0; i < len ; i++)
99 icuChar = tmpIcuStr.charAt(i);
100 wstr[i] = (wchar_t)icuChar;
108 // This convert OSP string to ICU strings
110 _LocaleData::GetIcuString(const String& ospStr, IcuUnicodeString& icuStr)
112 if (!ospStr.IsEmpty()) // if ospStr is not empty
114 ByteBuffer* pBuff = null;
115 pBuff = StringUtil::StringToUtf8N(ospStr); // Convert unicode value to UTF8
118 icuStr = IcuUnicodeString((const char*) pBuff->GetPointer()); // Create ICU string using UTF8 array
119 icuStr.setCharAt(0, icuStr.charAt(0)); // This is to handle ICU copy on write design
120 delete pBuff; // delete temporary buffer
127 // This function return OSP array list of OSP string from ICU string list
129 _LocaleData::ConvertIcuStringArrayToOspArrayN(const IcuUnicodeString* pIcuStrList, int count)
131 result r = E_SUCCESS;
132 ArrayList* pTempArrayList = null;
133 if (pIcuStrList && count > 0) // validating inputs
135 pTempArrayList = new (std::nothrow) ArrayList();
136 if (pTempArrayList) // If allocation is successful
138 r = pTempArrayList->Construct(count);
139 if (!IsFailed(r)) // If ArrayList::Construct() is successful
141 for (int i = 0; i < count; i++)
143 String* pString = new (std::nothrow) String();
146 *pString = _LocaleData::GetOspString(pIcuStrList[i]); // Get OSP string from ICU string
148 if (!pString->IsEmpty())
150 pTempArrayList->Add(*pString); // Add OSP string to arraylist if it is not empty
162 SetLastResult(r); // Setting last result value
163 return pTempArrayList; // Return array list
166 // this function convert OSP string array list to ICU string array list
168 _LocaleData::ConvertOspArrayToIcuStringArrayN(const Tizen::Base::Collection::IList* pIcuStrList, int& count)
170 count = 0; // Setting count [Out param] to 0
171 SysTryReturn(NID_LCL, pIcuStrList, null, E_INVALID_ARG, "[%s] Invalid argument is used. pIcuStrList is null.", GetErrorMessage(E_INVALID_ARG));
173 count = pIcuStrList->GetCount();
174 if (count > 0) // if pIcuStrList is not empty
176 IcuUnicodeString* pIcuStrArray = new IcuUnicodeString[count];
177 if (pIcuStrArray) // if allocation is successful
179 IEnumerator* pEnum = pIcuStrList->GetEnumeratorN();
180 if (pEnum) // if pEnum is non null
184 while (pEnum->MoveNext() == E_SUCCESS) // if enum has more value
186 pObj = static_cast< String* >(pEnum->GetCurrent()); // Get object and cast it to String
187 if (pObj) // if String is non null
189 GetIcuString(*pObj, pIcuStrArray[i]); // Convert it to ICU string and set to array
194 delete pEnum; // Delete enumerator
195 return pIcuStrArray; // return ICU Array
197 delete[] pIcuStrArray;
201 return null; // return null in case of failure
206 _LocaleData::GetIcuLocale(const Locale& ospLocale)
209 String language = ospLocale.GetLanguageCodeString();
210 String country = ospLocale.GetCountryCodeString();
211 String variant = ospLocale.GetVariantCodeString();
213 const char* pLangStr = _StringConverter::CopyToCharArrayN(language);
214 const char* pCountryStr = _StringConverter::CopyToCharArrayN(country);
215 const char* pVariantStr = null;
217 if (!variant.IsEmpty())
219 pVariantStr = _StringConverter::CopyToCharArrayN(variant);
222 IcuLocale icuLocale = IcuLocale(pLangStr, pCountryStr, pVariantStr);
225 delete[] pCountryStr;
226 delete[] pVariantStr;
228 if (icuLocale.isBogus())
230 SetLastResult(E_SYSTEM);
238 _LocaleData::GetIcuLocale(void)
244 _LocaleData::IsLocaleSupported(void)
246 return !__icuLocale.isBogus();
250 _LocaleData::SetLocale(const Locale& ospLocale)
252 if (_LocaleImpl::IsSupported(ospLocale))
254 __icuLocale = GetIcuLocale(ospLocale);
258 __icuLocale.setToBogus();
259 return (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
263 _LocaleData::GetNumberSymbols(const Locale& locale, String symbols[])
265 UErrorCode status = U_ZERO_ERROR;
269 SysTryReturnResult(NID_LCL, IsLocaleSupported(), E_SYSTEM, "A System error has been occurred. Locale is not supported");
271 IcuDecimalFormatSymbols sym(__icuLocale, status);
272 SysTryReturnResult(NID_LCL, U_SUCCESS(status), E_SYSTEM, "A System error has been occurred. Unable to get ICU Decimal Format Symbols");
274 symbols[NUMBER_SYMBOL_DECIMAL_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kDecimalSeparatorSymbol));
275 symbols[NUMBER_SYMBOL_GROUPING_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kGroupingSeparatorSymbol));
276 symbols[NUMBER_SYMBOL_PATTERN_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPatternSeparatorSymbol));
277 symbols[NUMBER_SYMBOL_PERCENT] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPercentSymbol));
278 symbols[NUMBER_SYMBOL_ZERO_DIGIT] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kZeroDigitSymbol));
279 symbols[NUMBER_SYMBOL_DIGIT] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kDigitSymbol));
280 symbols[NUMBER_SYMBOL_CURRENCY] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
281 symbols[NUMBER_SYMBOL_INTL_CURRENCY] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
282 symbols[NUMBER_SYMBOL_MONETARY_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kMonetarySeparatorSymbol));
283 symbols[NUMBER_SYMBOL_PER_MILL] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPerMillSymbol));
284 symbols[NUMBER_SYMBOL_EXPONENTIAL] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kExponentialSymbol));
285 symbols[NUMBER_SYMBOL_PLUS_SIGN] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPlusSignSymbol));
286 symbols[NUMBER_SYMBOL_MINUS_SIGN] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kMinusSignSymbol));
292 _LocaleData::SetNumberFormatter(const Locale& locale, NumberFormatterStyle style)
294 if (__pIcuNumberFormatter)
296 delete __pIcuNumberFormatter;
297 __pIcuNumberFormatter = null;
300 IcuNumberFormat* pNumFmt = null;
301 UErrorCode ec = U_ZERO_ERROR;
302 result r = SetLocale(locale);
308 case NUM_FORMATTER_STYLE_NUMBER:
310 pNumFmt = IcuNumberFormat::createInstance(__icuLocale, ec);
314 case NUM_FORMATTER_STYLE_CURRENCY:
316 pNumFmt = IcuNumberFormat::createCurrencyInstance(__icuLocale, ec);
320 case NUM_FORMATTER_STYLE_PERCENT:
322 pNumFmt = IcuNumberFormat::createPercentInstance(__icuLocale, ec);
328 r = E_UNSUPPORTED_OPERATION;
340 if (pNumFmt && (pNumFmt->getDynamicClassID() == IcuDecimalFormat::getStaticClassID()))
342 __pIcuNumberFormatter = dynamic_cast< IcuDecimalFormat* >(pNumFmt);
343 if (__pIcuNumberFormatter)
351 return E_UNSUPPORTED_OPERATION;
355 _LocaleData::FormatNumber(long number, _FieldPosition& pos, Tizen::Base::String& str)
359 if (__pIcuNumberFormatter)
361 IcuUnicodeString icuStr;
362 IcuFieldPosition icuPos = GetIcuFieldPosition(pos);
363 icuStr = __pIcuNumberFormatter->format(static_cast< int32_t >(number), icuStr, icuPos);
365 str = _LocaleData::GetOspString(icuStr);
373 _LocaleData::FormatNumber(double number, _FieldPosition& pos, Tizen::Base::String& str)
377 if (__pIcuNumberFormatter)
379 IcuUnicodeString icuStr;
380 IcuFieldPosition icuPos = GetIcuFieldPosition(pos);
381 icuStr = __pIcuNumberFormatter->format(number, icuStr, icuPos);
383 str = _LocaleData::GetOspString(icuStr);
391 _LocaleData::ApplyNumberPattern(const Tizen::Base::String& pattern, bool localized)
393 if (__pIcuNumberFormatter)
395 IcuUnicodeString icuPattern;
396 icuPattern = __pIcuNumberFormatter->toPattern(icuPattern);
398 UErrorCode ec = U_ZERO_ERROR;
399 IcuUParseError parseError = {0};
400 IcuUnicodeString icuNewPatter;
401 GetIcuString(pattern, icuNewPatter);
405 __pIcuNumberFormatter->applyLocalizedPattern(icuNewPatter, parseError, ec);
409 __pIcuNumberFormatter->applyPattern(icuNewPatter, parseError, ec);
418 SysLog(NID_LCL, "Error [%d -> %s] in setting pattern to %ls at %d:%d",
419 ec, u_errorName(ec), pattern.GetPointer(), parseError.line, parseError.offset);
421 __pIcuNumberFormatter->applyPattern(icuPattern, ec);
425 return E_INVALID_ARG;
429 _LocaleData::GetNumberFormatterStringAttributes(NumberFormatterAttributes attrName)
431 IcuUnicodeString icuRetValue;
433 if (__pIcuNumberFormatter)
437 case NUM_FORMATTER_FIELD_CURRENCY:
439 icuRetValue = __pIcuNumberFormatter->getCurrency();
443 case NUM_FORMATTER_FIELD_POSITIVE_PREFIX:
445 icuRetValue = __pIcuNumberFormatter->getPositivePrefix(icuRetValue);
449 case NUM_FORMATTER_FIELD_NEGATIVE_PREFIX:
451 icuRetValue = __pIcuNumberFormatter->getNegativePrefix(icuRetValue);
455 case NUM_FORMATTER_FIELD_POSITIVE_SUFFIX:
457 icuRetValue = __pIcuNumberFormatter->getPositiveSuffix(icuRetValue);
461 case NUM_FORMATTER_FIELD_NEGATIVE_SUFFIX:
463 icuRetValue = __pIcuNumberFormatter->getNegativeSuffix(icuRetValue);
467 case NUM_FORMATTER_FIELD_PATTERN:
469 icuRetValue = __pIcuNumberFormatter->toPattern(icuRetValue);
473 case NUM_FORMATTER_FIELD_LOCALIZED_PATTERN:
475 icuRetValue = __pIcuNumberFormatter->toLocalizedPattern(icuRetValue);
485 return _LocaleData::GetOspString(icuRetValue);
488 return Tizen::Base::String("");
492 _LocaleData::SetNumberFormatterAttributes(const String& newValue, NumberFormatterAttributes attrName)
494 if (__pIcuNumberFormatter)
496 IcuUnicodeString icuNewValue;
497 GetIcuString(newValue, icuNewValue);
501 case NUM_FORMATTER_FIELD_CURRENCY:
503 __pIcuNumberFormatter->setCurrency(icuNewValue.getTerminatedBuffer());
507 case NUM_FORMATTER_FIELD_POSITIVE_PREFIX:
509 __pIcuNumberFormatter->setPositivePrefix(icuNewValue);
513 case NUM_FORMATTER_FIELD_NEGATIVE_PREFIX:
515 __pIcuNumberFormatter->setNegativePrefix(icuNewValue);
519 case NUM_FORMATTER_FIELD_POSITIVE_SUFFIX:
521 __pIcuNumberFormatter->setPositiveSuffix(icuNewValue);
525 case NUM_FORMATTER_FIELD_NEGATIVE_SUFFIX:
527 __pIcuNumberFormatter->setNegativeSuffix(icuNewValue);
540 _LocaleData::GetNumberFormatterIntAttributes(NumberFormatterAttributes attrName)
543 if (__pIcuNumberFormatter)
547 case NUM_FORMATTER_FIELD_MAX_INTEGER_DIGITS:
549 res = __pIcuNumberFormatter->getMaximumIntegerDigits();
553 case NUM_FORMATTER_FIELD_MIN_INTEGER_DIGITS:
555 res = __pIcuNumberFormatter->getMinimumIntegerDigits();
559 case NUM_FORMATTER_FIELD_MAX_FRACTION_DIGITS:
561 res = __pIcuNumberFormatter->getMaximumFractionDigits();
565 case NUM_FORMATTER_FIELD_MIN_FRACTION_DIGITS:
567 res = __pIcuNumberFormatter->getMinimumFractionDigits();
571 case NUM_FORMATTER_FIELD_MIN_EXPONENT_DIGITS:
573 res = __pIcuNumberFormatter->getMinimumExponentDigits();
577 case NUM_FORMATTER_FIELD_MULTIPLIER:
579 res = __pIcuNumberFormatter->getMultiplier();
583 case NUM_FORMATTER_FIELD_GROUPING_SIZE:
585 res = __pIcuNumberFormatter->getGroupingSize();
601 _LocaleData::SetNumberFormatterAttributes(const int newValue, NumberFormatterAttributes attrName)
603 if (__pIcuNumberFormatter)
607 case NUM_FORMATTER_FIELD_MAX_INTEGER_DIGITS:
609 __pIcuNumberFormatter->setMaximumIntegerDigits(newValue);
613 case NUM_FORMATTER_FIELD_MIN_INTEGER_DIGITS:
615 __pIcuNumberFormatter->setMinimumIntegerDigits(newValue);
619 case NUM_FORMATTER_FIELD_MAX_FRACTION_DIGITS:
621 __pIcuNumberFormatter->setMaximumFractionDigits(newValue);
625 case NUM_FORMATTER_FIELD_MIN_FRACTION_DIGITS:
627 __pIcuNumberFormatter->setMinimumFractionDigits(newValue);
631 case NUM_FORMATTER_FIELD_MIN_EXPONENT_DIGITS:
633 __pIcuNumberFormatter->setMinimumExponentDigits(newValue);
637 case NUM_FORMATTER_FIELD_MULTIPLIER:
639 __pIcuNumberFormatter->setMultiplier(newValue);
643 case NUM_FORMATTER_FIELD_GROUPING_SIZE:
645 __pIcuNumberFormatter->setGroupingSize(newValue);
658 _LocaleData::GetNumberFormatterBoolAttributes(NumberFormatterAttributes attrName)
661 if (__pIcuNumberFormatter)
665 case NUM_FORMATTER_FIELD_IS_GROUPING_USED:
667 res = __pIcuNumberFormatter->isGroupingUsed();
671 case NUM_FORMATTER_FIELD_IS_DECIMAL_SEPARATOR_ALWAYS_SHOWN:
673 res = __pIcuNumberFormatter->isDecimalSeparatorAlwaysShown();
677 case NUM_FORMATTER_FIELD_IS_POSITIVE_SIGN_ALWAYS_SHOWN:
679 IcuUnicodeString ps("+");
681 pp = __pIcuNumberFormatter->getPositivePrefix(pp);
699 _LocaleData::SetNumberFormatterAttributes(const bool newValue, NumberFormatterAttributes attrName)
701 if (__pIcuNumberFormatter)
705 case NUM_FORMATTER_FIELD_IS_GROUPING_USED:
707 __pIcuNumberFormatter->setGroupingUsed(newValue);
711 case NUM_FORMATTER_FIELD_IS_DECIMAL_SEPARATOR_ALWAYS_SHOWN:
713 __pIcuNumberFormatter->setDecimalSeparatorAlwaysShown(newValue);
717 case NUM_FORMATTER_FIELD_IS_POSITIVE_SIGN_ALWAYS_SHOWN:
719 IcuUnicodeString ps("+");
721 pp = __pIcuNumberFormatter->getPositivePrefix(pp);
725 __pIcuNumberFormatter->setPositivePrefix(ps);
731 __pIcuNumberFormatter->setPositivePrefix("");
746 _LocaleData::SetDateFormatSymbols(const Locale& locale)
748 if (__pIcuDateFormatSymbols)
750 delete __pIcuDateFormatSymbols;
751 __pIcuDateFormatSymbols = null;
754 UErrorCode ec = U_ZERO_ERROR;
755 result r = SetLocale(locale);
759 __pIcuDateFormatSymbols = new IcuDateFormatSymbols(__icuLocale, ec);
761 if (__pIcuDateFormatSymbols && U_SUCCESS(ec))
767 delete __pIcuDateFormatSymbols;
768 __pIcuDateFormatSymbols = null;
774 _LocaleData::GetDateFormatSymbolAttrArrayN(DateFormatSymbolsAttributes attrName)
776 if (__pIcuDateFormatSymbols)
780 const IcuUnicodeString* pIcuList = null;
784 case DATE_FORMAT_SYM_ERA_LIST:
786 pIcuList = __pIcuDateFormatSymbols->getEras(count);
790 case DATE_FORMAT_SYM_MONTH_LIST:
792 pIcuList = __pIcuDateFormatSymbols->getMonths(count);
796 case DATE_FORMAT_SYM_SHORT_MONTH_LIST:
798 pIcuList = __pIcuDateFormatSymbols->getShortMonths(count);
802 case DATE_FORMAT_SYM_WEEKDAY_LIST:
804 pIcuList = __pIcuDateFormatSymbols->getWeekdays(count);
808 case DATE_FORMAT_SYM_SHORT_WEEKDAY_LIST:
810 pIcuList = __pIcuDateFormatSymbols->getShortWeekdays(count);
814 case DATE_FORMAT_SYM_AM_PM_LIST:
816 pIcuList = __pIcuDateFormatSymbols->getAmPmStrings(count);
822 SetLastResult(E_UNSUPPORTED_OPERATION);
829 return ConvertIcuStringArrayToOspArrayN(pIcuList, count);
833 SetLastResult(E_INVALID_STATE);
839 _LocaleData::GetIcuDate(DateTime date)
841 DateTime icuBaseTime;
842 icuBaseTime.SetValue(1970, 1, 1);
843 DateTime ospBaseTime = DateTime::GetMinValue();
845 result r = icuBaseTime.Subtract(ospBaseTime.GetTime());
848 SysLogException(NID_LCL, r, "[%s] Propagated.", GetErrorMessage(r));
851 TimeSpan tsIcu = icuBaseTime.GetTime();
852 TimeSpan tsOsp = date.GetTime();
853 TimeSpan diff = tsOsp - tsIcu;
855 IcuUDate icuDate = diff.GetTicks();
860 _LocaleData::SetDateTimeFormatter(DateTimeStyle dateStyle, DateTimeStyle timeStyle, const Locale& locale)
862 IcuDateFormat* pIcuDateFormat = null;
864 result r = SetLocale(locale);
865 SysTryReturnResult(NID_LCL, !IsFailed(r), E_INVALID_ARG, "Locale setting failed.");
867 U_ICU_NAMESPACE::DateFormat::EStyle icuDateStyle = (U_ICU_NAMESPACE::DateFormat::EStyle) dateStyle;
868 U_ICU_NAMESPACE::DateFormat::EStyle icuTimeStyle = (U_ICU_NAMESPACE::DateFormat::EStyle) timeStyle;
870 if (dateStyle == DATE_TIME_STYLE_NONE)
872 if (timeStyle != DATE_TIME_STYLE_NONE)
874 pIcuDateFormat = IcuDateFormat::createTimeInstance(icuTimeStyle, __icuLocale);
879 if (timeStyle == DATE_TIME_STYLE_NONE)
881 pIcuDateFormat = IcuDateFormat::createDateInstance(icuDateStyle, __icuLocale);
885 pIcuDateFormat = IcuDateFormat::createDateTimeInstance(icuDateStyle, icuTimeStyle, __icuLocale);
891 if (__pIcuDateFormat)
893 delete __pIcuDateFormat;
894 __pIcuDateFormat = null;
896 __pIcuDateFormat = dynamic_cast< IcuSimpleDateFormat* >(pIcuDateFormat);
898 if (__pIcuDateFormat)
900 if (__pIcuDateFormatSymbols)
902 delete __pIcuDateFormatSymbols;
903 __pIcuDateFormatSymbols = null;
906 const IcuDateFormatSymbols* pDateTimeFormatSym = __pIcuDateFormat->getDateFormatSymbols();
908 if (pDateTimeFormatSym)
910 __pIcuDateFormatSymbols = new IcuDateFormatSymbols(*pDateTimeFormatSym);
917 delete pIcuDateFormat;
918 return E_INVALID_ARG;
922 _LocaleData::SetStartTimeRule(IcuSimpleTimeZone& zone, const TimeRule* pOspTimeRule)
926 UErrorCode status = U_ZERO_ERROR;
927 IcuDateTimeRule::TimeRuleType icuTimeRuleType;
929 DstRuleMode ospRuleMode = static_cast< DstRuleMode >(pOspTimeRule->GetRuleMode());
930 Tizen::System::TimeMode ospTimeMode = pOspTimeRule->GetTimeMode();
934 case Tizen::System::UTC_TIME:
936 icuTimeRuleType = IcuDateTimeRule::UTC_TIME;
940 case Tizen::System::STANDARD_TIME:
942 icuTimeRuleType = IcuDateTimeRule::STANDARD_TIME;
946 case Tizen::System::WALL_TIME:
949 icuTimeRuleType = IcuDateTimeRule::WALL_TIME;
954 int time = ((pOspTimeRule->GetHour() * 60) + pOspTimeRule->GetMinute()) * 60 * 1000;
961 pOspTimeRule->GetMonth(),
962 pOspTimeRule->GetDay(),
969 case DAY_OF_WEEK_IN_MONTH:
972 pOspTimeRule->GetMonth(),
973 pOspTimeRule->GetWeek(),
974 pOspTimeRule->GetDayOfWeek(),
981 case AFTER_THE_SPECIFIED_DAY:
984 pOspTimeRule->GetMonth(),
985 pOspTimeRule->GetDay(),
986 pOspTimeRule->GetDayOfWeek(),
993 case BEFORE_THE_SPECIFIED_DAY:
996 pOspTimeRule->GetMonth(),
997 pOspTimeRule->GetDay(),
998 -pOspTimeRule->GetDayOfWeek(),
1005 case BACKWARD_FROM_END_OF_MONTH:
1008 pOspTimeRule->GetMonth(),
1009 pOspTimeRule->GetWeek() * -1,
1017 return U_SUCCESS(status) ? E_SUCCESS : E_SYSTEM;
1019 return E_INVALID_ARG;
1023 _LocaleData::SetEndTimeRule(IcuSimpleTimeZone& zone, const TimeRule* pOspTimeRule)
1027 UErrorCode status = U_ZERO_ERROR;
1028 IcuDateTimeRule::TimeRuleType icuTimeRuleType;
1030 DstRuleMode ospRuleMode = static_cast< DstRuleMode >(pOspTimeRule->GetRuleMode());
1031 Tizen::System::TimeMode ospTimeMode = pOspTimeRule->GetTimeMode();
1033 switch (ospTimeMode)
1035 case Tizen::System::UTC_TIME:
1037 icuTimeRuleType = IcuDateTimeRule::UTC_TIME;
1041 case Tizen::System::STANDARD_TIME:
1043 icuTimeRuleType = IcuDateTimeRule::STANDARD_TIME;
1047 case Tizen::System::WALL_TIME:
1050 icuTimeRuleType = IcuDateTimeRule::WALL_TIME;
1055 int time = ((pOspTimeRule->GetHour() * 60) + pOspTimeRule->GetMinute()) * 60 * 1000;
1057 switch (ospRuleMode)
1062 pOspTimeRule->GetMonth(),
1063 pOspTimeRule->GetDay(),
1070 case DAY_OF_WEEK_IN_MONTH:
1073 pOspTimeRule->GetMonth(),
1074 pOspTimeRule->GetWeek(),
1075 pOspTimeRule->GetDayOfWeek(),
1082 case AFTER_THE_SPECIFIED_DAY:
1085 pOspTimeRule->GetMonth(),
1086 pOspTimeRule->GetDay(),
1087 pOspTimeRule->GetDayOfWeek(),
1094 case BEFORE_THE_SPECIFIED_DAY:
1097 pOspTimeRule->GetMonth(),
1098 pOspTimeRule->GetDay(),
1099 -pOspTimeRule->GetDayOfWeek(),
1106 case BACKWARD_FROM_END_OF_MONTH:
1109 pOspTimeRule->GetMonth(),
1110 pOspTimeRule->GetWeek() * -1,
1118 return U_SUCCESS(status) ? E_SUCCESS : E_SYSTEM;
1120 return E_INVALID_ARG;
1124 _LocaleData::FormatDateTime(const DateTime& date, String& str)
1126 std::auto_ptr <Calendar> pCal(Calendar::CreateInstanceN());
1127 SysTryReturnResult(NID_LCL, pCal.get(), E_OUT_OF_MEMORY, "Memory allocation failed");
1129 result r = pCal->SetTime(date);
1130 SysTryReturn(NID_LCL, r == E_SUCCESS, r, r, "[%s] Unable to set date time in default calendar");
1132 r = pCal->Clear(TIME_FIELD_MILLISECOND);
1133 SysTryReturn(NID_LCL, r == E_SUCCESS, r, r, "[%s] Unable to set date time in default calendar");
1135 return FormatDateTime(*pCal, str);
1139 _LocaleData::FormatDateTime(const Calendar& calendar, Tizen::Base::String& str)
1141 SysTryReturnResult(NID_LCL, __pIcuDateFormat, E_INVALID_STATE, "This instance is not constructed");
1144 const _IcuCalendarImpl* _pIcuCalendarImpl = _CalendarImpl::GetImpl(calendar);
1145 if (_pIcuCalendarImpl)
1147 IcuCalendar* pIcuCal = _pIcuCalendarImpl->GetIcuCalendarCloneN();
1150 IcuFieldPosition icuFp;
1151 IcuUnicodeString icuStr;
1153 GetIcuString(str,icuStr);
1154 icuStr = __pIcuDateFormat->format(*pIcuCal, icuStr, icuFp);
1155 str = _LocaleData::GetOspString(icuStr);
1158 return GetLastResult();
1166 _LocaleData::GetDateTimePattern()
1168 SysTryReturn(NID_LCL, __pIcuDateFormat, String(""), E_INVALID_STATE, "This instance is not constructed");
1169 IcuUnicodeString icuPattern;
1171 icuPattern = __pIcuDateFormat->toPattern(icuPattern);
1172 return _LocaleData::GetOspString(icuPattern);
1176 _LocaleData::SetDateTimePattern(const String& pattern)
1178 SysTryReturnResult(NID_LCL, __pIcuDateFormat, E_INVALID_STATE, "This instance is not constructed");
1179 IcuUnicodeString icuStr;
1181 GetIcuString(pattern, icuStr);
1183 __pIcuDateFormat->applyPattern(icuStr);
1188 _LocaleData::GetDateTimeSymbolsN(DateTimeSymbols* pDateTimeSymbols)
1190 SysTryReturn(NID_LCL, __pIcuDateFormatSymbols, null, E_INVALID_STATE, "[E_INVALID_STATE] This instance is not constructed");
1191 SysTryReturn(NID_LCL, pDateTimeSymbols, null, E_INVALID_ARG, "[%s] Invalid argument is used. pDateTimeSymbols is null.", GetErrorMessage(E_INVALID_ARG));
1193 _DateTimeSymbolsImpl* pDateTimeSymbolsImpl = _DateTimeSymbolsImpl::GetDateTimeSymbolsImpl(pDateTimeSymbols);
1195 if (pDateTimeSymbolsImpl)
1197 pDateTimeSymbolsImpl->ReleaseAll();
1199 pDateTimeSymbolsImpl->__pErasList = GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_ERA_LIST);
1200 pDateTimeSymbolsImpl->__pMonthsList = GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_MONTH_LIST);
1201 pDateTimeSymbolsImpl->__pShortMonthsList = GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_SHORT_MONTH_LIST);
1202 pDateTimeSymbolsImpl->__pWeekdaysList = GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_WEEKDAY_LIST);
1203 pDateTimeSymbolsImpl->__pShortWeekdaysList = GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_SHORT_WEEKDAY_LIST);
1204 pDateTimeSymbolsImpl->__pAmPmList = GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_AM_PM_LIST);
1206 return pDateTimeSymbols;
1212 // This function convert and set ICU DateTime symbols from OSP DateTimeSymbols
1214 _LocaleData::SetDateTimeSymbols(const DateTimeSymbols& newValue)
1216 UErrorCode ec = U_ZERO_ERROR;
1218 if (!__pIcuDateFormatSymbols)
1220 __pIcuDateFormatSymbols = new IcuDateFormatSymbols(ec);
1223 IcuUnicodeString* pIcuArray = null;
1226 if (U_SUCCESS(ec) && __pIcuDateFormatSymbols != null)
1228 pIcuArray = ConvertOspArrayToIcuStringArrayN(newValue.GetEras(), count);
1229 __pIcuDateFormatSymbols->setEras(pIcuArray, count);
1232 pIcuArray = ConvertOspArrayToIcuStringArrayN(newValue.GetMonths(), count);
1233 __pIcuDateFormatSymbols->setMonths(pIcuArray, count);
1236 pIcuArray = ConvertOspArrayToIcuStringArrayN(newValue.GetShortMonths(), count);
1237 __pIcuDateFormatSymbols->setShortMonths(pIcuArray, count);
1240 pIcuArray = ConvertOspArrayToIcuStringArrayN(newValue.GetWeekdays(), count);
1241 __pIcuDateFormatSymbols->setWeekdays(pIcuArray, count);
1244 pIcuArray = ConvertOspArrayToIcuStringArrayN(newValue.GetShortWeekdays(), count);
1245 __pIcuDateFormatSymbols->setShortWeekdays(pIcuArray, count);
1248 pIcuArray = ConvertOspArrayToIcuStringArrayN(newValue.GetAmPm(), count);
1249 __pIcuDateFormatSymbols->setAmPmStrings(pIcuArray, count);
1252 // From ICU Docs: SimpleDateFormat no longer use the zone strings stored in a DateFormatSymbols. Therefore, the time zone strings
1253 // set by this method have no effects in an instance of SimpleDateFormat for formatting time zones.
1254 // __pIcuDateFormatSymbols->setZoneStrings();
1259 return E_UNSUPPORTED_OPERATION;
1263 _LocaleData::SetGregorianWeekCountData(const Locale& ospLocale, DayOfWeek& firstDayOfWeek, short& minDaysInFirstWeek)
1265 UErrorCode success = U_ZERO_ERROR;
1266 IcuLocale icuLocale;
1268 icuLocale = GetIcuLocale(ospLocale);
1269 result r = GetLastResult();
1270 SysAssert(r == E_SUCCESS);
1272 GregorianCalendar gc(icuLocale, success);
1273 SysAssert(U_SUCCESS(success));
1275 firstDayOfWeek = (DayOfWeek) gc.getFirstDayOfWeek(); // Set __firstDayOfWeek from ICU data
1276 minDaysInFirstWeek = 1; // To align with 2.0 version
1277 // minDaysInFirstWeek = (short) gc.getMinimalDaysInFirstWeek(); // Set __minDaysInFirstWeek from ICU data
1280 _LocaleData::_LocaleData(void)
1282 , // default ICU locale
1283 __pIcuNumberFormatter(null)
1284 , __pIcuDateFormatSymbols(null)
1285 , __pIcuDateFormat(null)
1290 _LocaleData::~_LocaleData(void)
1292 if (__pIcuNumberFormatter) // Delete __pIcuNumberFormatter and set to null
1294 delete __pIcuNumberFormatter;
1295 __pIcuNumberFormatter = null;
1298 if (__pIcuDateFormatSymbols) // Delete __pIcuDateFormatSymbols and set to null
1300 delete __pIcuDateFormatSymbols;
1301 __pIcuDateFormatSymbols = null;
1304 if (__pIcuDateFormat) // Delete __pIcuDateFormat and set to null
1306 delete __pIcuDateFormat;
1307 __pIcuDateFormat = null;
1313 }; // Tizen::Locales