From: Hokwon Song Date: Tue, 13 Aug 2013 08:32:42 +0000 (+0900) Subject: Fix a timezone defect. X-Git-Tag: submit/tizen/20131210.080830^2^2~179^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1185b7388d1ed02fd42e0e2e7c0521b3e9506f51;p=platform%2Fframework%2Fnative%2Fappfw.git Fix a timezone defect. Change-Id: I5821845cb440729525b2989e05bb1a90c0abd298 Signed-off-by: Hokwon Song --- diff --git a/inc/FLclCalendar.h b/inc/FLclCalendar.h index 2d6e30f..45d3e66 100644 --- a/inc/FLclCalendar.h +++ b/inc/FLclCalendar.h @@ -669,7 +669,6 @@ public: /** * Creates an instance of %Calendar of the specified type with the GMT time zone and the system locale. @n - * The time zone is used for the zone offset and the DST offset. * An instance has weekdata which are the first of week, minimal days in the first week, weekend on set, and weekend cease. * The weekdata are set as default values by the locale. * @@ -708,7 +707,6 @@ public: /** * Creates an instance of %Calendar of the specified type with the specified @c locale and the GMT time zone. @n - * The time zone is used for the zone offset and the DST offset. * An instance has weekdata which are the first of week, minimal days in the first week, weekend on set, and weekend cease. * The weekdata are set as default values by the specified @c locale. * diff --git a/src/locales/FLcl_IcuCalendarImpl.cpp b/src/locales/FLcl_IcuCalendarImpl.cpp index 2c27038..8b1fe7e 100644 --- a/src/locales/FLcl_IcuCalendarImpl.cpp +++ b/src/locales/FLcl_IcuCalendarImpl.cpp @@ -79,7 +79,7 @@ _IcuCalendarImpl::Construct(const TimeZone& timeZone, const Locale& locale, int if (pTimeZoneImpl) { IcuErrorCode err; - __pIcuCalendar = IcuCalendar::createInstance(pTimeZoneImpl->GetIcuTimeZone().clone(), icuLocale, err); + __pIcuCalendar = IcuCalendar::createInstance(pTimeZoneImpl->GetIcuTimeZone()->clone(), icuLocale, err); r = GetOspException(err); } } @@ -543,7 +543,7 @@ _IcuCalendarImpl::SetTimeZone(const TimeZone& timeZone) const _TimeZoneImpl* pTimeZoneImpl = _TimeZoneImpl::GetTimeZoneImpl(timeZone); if (pTimeZoneImpl) { - __pIcuCalendar->adoptTimeZone(pTimeZoneImpl->GetIcuTimeZone().clone()); + __pIcuCalendar->adoptTimeZone(pTimeZoneImpl->GetIcuTimeZone()->clone()); } return E_SUCCESS; } diff --git a/src/locales/FLcl_TimeZoneImpl.cpp b/src/locales/FLcl_TimeZoneImpl.cpp index ae5853c..9d6873a 100644 --- a/src/locales/FLcl_TimeZoneImpl.cpp +++ b/src/locales/FLcl_TimeZoneImpl.cpp @@ -53,90 +53,93 @@ namespace Tizen { namespace Locales { _TimeZoneImpl::_TimeZoneImpl(void) - : __icuTimeZone(0, "") + : __pIcuTimeZone(null) , __dstStartingYear(0) , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED) , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED) + , __isCustomizing(true) { - + __pIcuTimeZone = new U_ICU_NAMESPACE::SimpleTimeZone(0, ""); + SysTryReturn(NID_LCL, __pIcuTimeZone, , E_OUT_OF_MEMORY, "It is not enough memory."); } _TimeZoneImpl::_TimeZoneImpl(int rawOffset, const String& id) - : __icuTimeZone(rawOffset * ONE_MIN_IN_MILLISEC, _LocaleData::GetIcuString(id)) + : __pIcuTimeZone(null) , __dstStartingYear(0) , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED) , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED) + , __isCustomizing(true) { - + UnicodeString icuId(_LocaleData::GetIcuString(id)); + __pIcuTimeZone = new U_ICU_NAMESPACE::SimpleTimeZone(rawOffset * ONE_MIN_IN_MILLISEC, icuId); + SysTryReturn(NID_LCL, __pIcuTimeZone, , E_OUT_OF_MEMORY, "It is not enough memory."); } _TimeZoneImpl::_TimeZoneImpl(int rawOffset, const String& id, const TimeRule& startRule, const TimeRule& endRule, int dstOffset) - : __icuTimeZone(rawOffset * ONE_MIN_IN_MILLISEC, _LocaleData::GetIcuString(id)) + : __pIcuTimeZone(null) , __dstStartingYear(0) , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED) , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED) + , __isCustomizing(true) { + UnicodeString icuId(_LocaleData::GetIcuString(id)); + __pIcuTimeZone = new U_ICU_NAMESPACE::SimpleTimeZone(rawOffset * ONE_MIN_IN_MILLISEC, icuId); + SysTryReturn(NID_LCL, __pIcuTimeZone, , E_OUT_OF_MEMORY, "It is not enough memory."); SetDstRules(startRule, endRule, dstOffset); } _TimeZoneImpl::_TimeZoneImpl(const _TimeZoneImpl& otherTimeZone) - : __icuTimeZone(otherTimeZone.__icuTimeZone) + : __pIcuTimeZone(null) , __dstStartingYear(otherTimeZone.__dstStartingYear) , __startingRule(otherTimeZone.__startingRule) , __endingRule(otherTimeZone.__endingRule) + , __isCustomizing(otherTimeZone.__isCustomizing) { + __pIcuTimeZone = otherTimeZone.__pIcuTimeZone->clone(); + SysTryReturn(NID_LCL, __pIcuTimeZone, , E_OUT_OF_MEMORY, "It is not enough memory."); } -_TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone& icuTimeZone) - : __icuTimeZone(0, "") +_TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone) + : __pIcuTimeZone(null) , __dstStartingYear(0) , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED) , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED) + , __isCustomizing(true) { - U_ICU_NAMESPACE::UnicodeString id; - __icuTimeZone.setID(icuTimeZone.getID(id)); - __icuTimeZone.setRawOffset(icuTimeZone.getRawOffset()); + __pIcuTimeZone = pIcuTimeZone; } -_TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone& icuTimeZone, UDate icuDate) - : __icuTimeZone(0, "") +_TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone, UDate icuDate) + : __pIcuTimeZone(null) , __dstStartingYear(0) , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED) , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED) + , __isCustomizing(false) { - U_ICU_NAMESPACE::UnicodeString id; - __icuTimeZone.setID(icuTimeZone.getID(id)); - __icuTimeZone.setRawOffset(icuTimeZone.getRawOffset()); + __pIcuTimeZone = pIcuTimeZone; - U_ICU_NAMESPACE::BasicTimeZone* pIcuTz = dynamic_cast(&icuTimeZone); + U_ICU_NAMESPACE::BasicTimeZone* pIcuTz = dynamic_cast(pIcuTimeZone); if (pIcuTz) { - TimeRule startingRule(MONTH_UNDEFINED, DAY_UNDEFINED); - TimeRule endingRule(MONTH_UNDEFINED, DAY_UNDEFINED); - - int dstSaving = 0; UErrorCode status = U_ZERO_ERROR; U_ICU_NAMESPACE::InitialTimeZoneRule* pInitial = null; U_ICU_NAMESPACE::AnnualTimeZoneRule* pStd = null; U_ICU_NAMESPACE::AnnualTimeZoneRule* pDst = null; pIcuTz->getSimpleRulesNear(icuDate, pInitial, pStd, pDst, status); + if (pStd && pDst) { - result r = GetTimeRuleFromIcuDateTimeRule(pDst->getRule(), startingRule); + result r = GetTimeRuleFromIcuDateTimeRule(pDst->getRule(), __startingRule); if (r == E_SUCCESS) { - dstSaving = pIcuTz->getDSTSavings() / ONE_MIN_IN_MILLISEC; - GetTimeRuleFromIcuDateTimeRule(pStd->getRule(), endingRule); + GetTimeRuleFromIcuDateTimeRule(pStd->getRule(), __endingRule); + __dstStartingYear = pDst->getStartYear(); } - - int dstStartingYear = pDst->getStartYear(); - SetDstStartingYear(dstStartingYear); } delete pInitial; delete pStd; delete pDst; - SetDstRules(startingRule, endingRule, dstSaving); } } @@ -151,30 +154,34 @@ _TimeZoneImpl::operator =(const _TimeZoneImpl& otherTimeZone) { if (*this != otherTimeZone) { - __icuTimeZone = otherTimeZone.__icuTimeZone; + __pIcuTimeZone = otherTimeZone.__pIcuTimeZone; __dstStartingYear = otherTimeZone.__dstStartingYear; __startingRule = otherTimeZone.__startingRule; __endingRule = otherTimeZone.__endingRule; + __isCustomizing = otherTimeZone.__isCustomizing; } return *this; } _TimeZoneImpl::~_TimeZoneImpl(void) { - + if (__pIcuTimeZone) + { + delete __pIcuTimeZone; + } } -U_ICU_NAMESPACE::SimpleTimeZone +U_ICU_NAMESPACE::TimeZone* _TimeZoneImpl::GetIcuTimeZone(void) const { - return __icuTimeZone; + return __pIcuTimeZone; } bool _TimeZoneImpl::operator ==(const _TimeZoneImpl& otherTimeZone) const { - return __icuTimeZone == otherTimeZone.__icuTimeZone; + return *__pIcuTimeZone == *otherTimeZone.__pIcuTimeZone; } bool @@ -198,7 +205,8 @@ int _TimeZoneImpl::GetHashCode(void) const { int hashCode = GetId().GetHashCode(); - Integer intValues = GetRawOffset() + GetDstSavings() + GetDstStartingYear() + IsDstUsed(); + int customizing = (__isCustomizing == false) ? 0 : __dstStartingYear; + Integer intValues = GetRawOffset() + GetDstSavings() + IsDstUsed() + customizing; hashCode = (hashCode << 5) - hashCode + intValues.GetHashCode(); hashCode = (hashCode << 5) - hashCode + __startingRule.GetHashCode(); hashCode = (hashCode << 5) - hashCode + __endingRule.GetHashCode(); @@ -210,26 +218,27 @@ String _TimeZoneImpl::GetId(void) const { U_ICU_NAMESPACE::UnicodeString icuStr; - return _LocaleData::GetOspString(__icuTimeZone.getID(icuStr)); + __pIcuTimeZone->getID(icuStr); + return _LocaleData::GetOspString(icuStr); } void _TimeZoneImpl::SetId(const String& id) { U_ICU_NAMESPACE::UnicodeString icuStr = _LocaleData::GetIcuString(id); - __icuTimeZone.setID(icuStr); + __pIcuTimeZone->setID(icuStr); } int _TimeZoneImpl::GetRawOffset(void) const { - return __icuTimeZone.getRawOffset() / ONE_MIN_IN_MILLISEC; + return __pIcuTimeZone->getRawOffset() / ONE_MIN_IN_MILLISEC; } void _TimeZoneImpl::SetRawOffset(int rawOffset) { - __icuTimeZone.setRawOffset(rawOffset * ONE_MIN_IN_MILLISEC); + __pIcuTimeZone->setRawOffset(rawOffset * ONE_MIN_IN_MILLISEC); } int @@ -242,20 +251,46 @@ void _TimeZoneImpl::SetDstStartingYear(int year) { __dstStartingYear = year; - __icuTimeZone.setStartYear(year); + U_ICU_NAMESPACE::SimpleTimeZone* pStz = dynamic_cast(__pIcuTimeZone); + + if (pStz == null) + { + U_ICU_NAMESPACE::UnicodeString id; + __pIcuTimeZone->getID(id); + pStz = new U_ICU_NAMESPACE::SimpleTimeZone(__pIcuTimeZone->getRawOffset(), id); + SysTryReturn(NID_LCL, pStz, ,E_OUT_OF_MEMORY, "It is not enough memory."); + delete __pIcuTimeZone; + __pIcuTimeZone = pStz; + } + + pStz->setStartYear(year); + __isCustomizing = true; } int _TimeZoneImpl::GetDstSavings(void) const { - return __icuTimeZone.getDSTSavings() / ONE_MIN_IN_MILLISEC; + return __pIcuTimeZone->getDSTSavings() / ONE_MIN_IN_MILLISEC; } void _TimeZoneImpl::SetDstSavings(int dstSavings) { UErrorCode ec = U_ZERO_ERROR; - __icuTimeZone.setDSTSavings(dstSavings * ONE_MIN_IN_MILLISEC, ec); + + U_ICU_NAMESPACE::SimpleTimeZone* pStz = dynamic_cast(__pIcuTimeZone); + + if (pStz == null) + { + U_ICU_NAMESPACE::UnicodeString id; + __pIcuTimeZone->getID(id); + pStz = new U_ICU_NAMESPACE::SimpleTimeZone(__pIcuTimeZone->getRawOffset(), id); + SysTryReturn(NID_LCL, pStz, ,E_OUT_OF_MEMORY, "It is not enough memory."); + delete __pIcuTimeZone; + __pIcuTimeZone = pStz; + } + pStz->setDSTSavings(dstSavings * ONE_MIN_IN_MILLISEC, ec); + __isCustomizing = true; } const TimeRule* @@ -277,8 +312,21 @@ _TimeZoneImpl::SetDstStartingRule(const TimeRule& startRule) GetIcuTimeRuleValue(startRule, month, dayOfWeekInMonth, dayOfWeek, time, mode); U_ICU_NAMESPACE::SimpleTimeZone::TimeMode timeMode = static_cast (mode); - __icuTimeZone.setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, timeMode, ec); + U_ICU_NAMESPACE::SimpleTimeZone* pStz = dynamic_cast(__pIcuTimeZone); + + if (pStz == null) + { + U_ICU_NAMESPACE::UnicodeString id; + __pIcuTimeZone->getID(id); + pStz = new U_ICU_NAMESPACE::SimpleTimeZone(__pIcuTimeZone->getRawOffset(), id); + SysTryReturn(NID_LCL, pStz, ,E_OUT_OF_MEMORY, "It is not enough memory."); + delete __pIcuTimeZone; + __pIcuTimeZone = pStz; + } + + pStz->setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, timeMode, ec); __startingRule = startRule; + __isCustomizing = true; } const TimeRule* @@ -300,8 +348,21 @@ _TimeZoneImpl::SetDstEndingRule(const TimeRule& endRule) GetIcuTimeRuleValue(endRule, month, dayOfWeekInMonth, dayOfWeek, time, mode); U_ICU_NAMESPACE::SimpleTimeZone::TimeMode timeMode = static_cast (mode); - __icuTimeZone.setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, timeMode, ec); + U_ICU_NAMESPACE::SimpleTimeZone* pStz = dynamic_cast(__pIcuTimeZone); + + if (pStz == null) + { + U_ICU_NAMESPACE::UnicodeString id; + __pIcuTimeZone->getID(id); + pStz = new U_ICU_NAMESPACE::SimpleTimeZone(__pIcuTimeZone->getRawOffset(), id); + SysTryReturn(NID_LCL, pStz, ,E_OUT_OF_MEMORY, "It is not enough memory."); + delete __pIcuTimeZone; + __pIcuTimeZone = pStz; + } + + pStz->setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, timeMode, ec); __endingRule = endRule; + __isCustomizing = true; } result @@ -321,7 +382,7 @@ result _TimeZoneImpl::GetOffset(const DateTime& date, bool local, int& rawOffset, int& dstOffset) const { UErrorCode ec = U_ZERO_ERROR; - __icuTimeZone.getOffset(_LocaleData::GetIcuDate(date), local, rawOffset, dstOffset, ec); + __pIcuTimeZone->getOffset(_LocaleData::GetIcuDate(date), local, rawOffset, dstOffset, ec); rawOffset /= ONE_MIN_IN_MILLISEC; dstOffset /= ONE_MIN_IN_MILLISEC; return U_SUCCESS(ec) ? E_SUCCESS : E_INVALID_ARG; @@ -337,7 +398,7 @@ _TimeZoneImpl::GetOffset(long long ticks, int& offset) const int rawOffset = 0; int dstOffset = 0; UErrorCode ec = U_ZERO_ERROR; - __icuTimeZone.getOffset(_LocaleData::GetIcuDate(date), false, rawOffset, dstOffset, ec); + __pIcuTimeZone->getOffset(_LocaleData::GetIcuDate(date), false, rawOffset, dstOffset, ec); offset = (rawOffset + dstOffset) / ONE_MIN_IN_MILLISEC; return U_SUCCESS(ec) ? E_SUCCESS : E_INVALID_ARG; } @@ -345,7 +406,7 @@ _TimeZoneImpl::GetOffset(long long ticks, int& offset) const bool _TimeZoneImpl::IsDstUsed(void) const { - return __icuTimeZone.useDaylightTime(); + return __pIcuTimeZone->useDaylightTime(); } const _TimeZoneImpl* @@ -365,16 +426,15 @@ _TimeZoneImpl::GetTimeZone(const String& id, Tizen::Locales::TimeZone& timeZone) SysTryReturnResult(NID_LCL, pIcuTimeZone->getID(retIcuStr) == icuStr, E_INVALID_ARG, "Unsupported timezone id [%ls]", id.GetPointer()); - U_ICU_NAMESPACE::SimpleTimeZone icuTimeZone(pIcuTimeZone->getRawOffset(), icuStr); - std::unique_ptr<_TimeZoneImpl> pTimeZoneImpl(new (std::nothrow) _TimeZoneImpl(icuTimeZone)); - if (pTimeZoneImpl) - { - delete timeZone.__pTimeZoneImpl; - timeZone.__pTimeZoneImpl = pTimeZoneImpl.release(); - return E_SUCCESS; - } + std::unique_ptr pIcuSimpleTimeZone(new U_ICU_NAMESPACE::SimpleTimeZone(pIcuTimeZone->getRawOffset(), icuStr)); + SysTryReturnResult(NID_LCL, pIcuSimpleTimeZone, E_OUT_OF_MEMORY, "It is enough memory."); + std::unique_ptr<_TimeZoneImpl> pTimeZoneImpl(new (std::nothrow) _TimeZoneImpl(pIcuSimpleTimeZone.get())); + SysTryReturnResult(NID_LCL, pTimeZoneImpl, E_OUT_OF_MEMORY, "It is enough memory."); - return E_INVALID_ARG; + delete timeZone.__pTimeZoneImpl; + timeZone.__pTimeZoneImpl = pTimeZoneImpl.release(); + pIcuSimpleTimeZone.release(); + return E_SUCCESS; } result @@ -388,15 +448,13 @@ _TimeZoneImpl::GetTimeZone(const String& id, const DateTime& utcTime, Tizen::Loc SysTryReturnResult(NID_LCL, pIcuTimeZone->getID(retIcuStr) == icuStr, E_INVALID_ARG, "Unsupported timezone id [%ls]", id.GetPointer()); - std::unique_ptr<_TimeZoneImpl> pTimeZoneImpl(new (std::nothrow) _TimeZoneImpl(*pIcuTimeZone, _LocaleData::GetIcuDate(utcTime))); - if (pTimeZoneImpl) - { - delete timeZone.__pTimeZoneImpl; - timeZone.__pTimeZoneImpl = pTimeZoneImpl.release(); - return E_SUCCESS; - } + std::unique_ptr<_TimeZoneImpl> pTimeZoneImpl(new (std::nothrow) _TimeZoneImpl(pIcuTimeZone.get(), _LocaleData::GetIcuDate(utcTime))); + SysTryReturnResult(NID_LCL, pTimeZoneImpl, E_OUT_OF_MEMORY, "It is enough memory."); - return E_INVALID_ARG; + delete timeZone.__pTimeZoneImpl; + timeZone.__pTimeZoneImpl = pTimeZoneImpl.release(); + pIcuTimeZone.release(); + return E_SUCCESS; } void @@ -496,7 +554,6 @@ _TimeZoneImpl::GetTimeRuleFromIcuDateTimeRule(const U_ICU_NAMESPACE::DateTimeRul ospRule.SetValue(month, day, week, dayOfWeek, onOrAfterDay, hour, minute, timeMode); - return E_SUCCESS; } @@ -505,6 +562,3 @@ _TimeZoneImpl::GetTimeRuleFromIcuDateTimeRule(const U_ICU_NAMESPACE::DateTimeRul }; }; // Tizen::Locales - - - diff --git a/src/locales/FLcl_TimeZoneImpl.h b/src/locales/FLcl_TimeZoneImpl.h index 48e336c..ed5c7f8 100644 --- a/src/locales/FLcl_TimeZoneImpl.h +++ b/src/locales/FLcl_TimeZoneImpl.h @@ -43,8 +43,8 @@ public: _TimeZoneImpl(void); _TimeZoneImpl(int rawOffset, const Tizen::Base::String& id); _TimeZoneImpl(int rawOffset, const Tizen::Base::String& id, const TimeRule& startRule, const TimeRule& endRule, int dstOffset); - _TimeZoneImpl(U_ICU_NAMESPACE::TimeZone& icuTimeZone); - _TimeZoneImpl(U_ICU_NAMESPACE::TimeZone& icuTimeZone, UDate icuDate); + _TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone); + _TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone, UDate icuDate); _TimeZoneImpl(const _TimeZoneImpl& otherTimeZone); @@ -82,7 +82,7 @@ public: result GetOffset(long long ticks, int& offset) const; bool IsDstUsed(void) const; - U_ICU_NAMESPACE::SimpleTimeZone GetIcuTimeZone(void) const; + U_ICU_NAMESPACE::TimeZone* GetIcuTimeZone(void) const; static const _TimeZoneImpl* GetTimeZoneImpl(const TimeZone& ospTimeZone); static result GetTimeZone(const Tizen::Base::String& id, Tizen::Locales::TimeZone& timeZone); @@ -99,11 +99,12 @@ public: static const int ONE_DAY_IN_MINUTE = 24 * 60; private: - U_ICU_NAMESPACE::SimpleTimeZone __icuTimeZone; + U_ICU_NAMESPACE::TimeZone* __pIcuTimeZone; int __dstStartingYear; TimeRule __startingRule; TimeRule __endingRule; + bool __isCustomizing; static const int DAY_UNDEFINED = -1; }; // _TimeZoneImpl