Merge "sync code for tizen_2.2" into devel_3.0_main
[platform/framework/native/appfw.git] / src / locales / FLcl_TimeZoneImpl.cpp
index 9d6873a..b117542 100644 (file)
@@ -23,6 +23,8 @@
 #include <unicode/timezone.h>
 #include <unicode/basictz.h>
 #include <unicode/simpletz.h>
+#include <unicode/tztrans.h>
+#include <unicode/tzrule.h>
 
 #include <FBaseInteger.h>
 #include <FBaseSysLog.h>
@@ -54,6 +56,7 @@ namespace Tizen { namespace Locales
 
 _TimeZoneImpl::_TimeZoneImpl(void)
        : __pIcuTimeZone(null)
+       , __dstSaving(60)
        , __dstStartingYear(0)
        , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
        , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
@@ -65,6 +68,7 @@ _TimeZoneImpl::_TimeZoneImpl(void)
 
 _TimeZoneImpl::_TimeZoneImpl(int rawOffset, const String& id)
        : __pIcuTimeZone(null)
+       , __dstSaving(60)
        , __dstStartingYear(0)
        , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
        , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
@@ -77,6 +81,7 @@ _TimeZoneImpl::_TimeZoneImpl(int rawOffset, const String& id)
 
 _TimeZoneImpl::_TimeZoneImpl(int rawOffset, const String& id, const TimeRule& startRule, const TimeRule& endRule, int dstOffset)
        : __pIcuTimeZone(null)
+       , __dstSaving(dstOffset)
        , __dstStartingYear(0)
        , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
        , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
@@ -90,6 +95,7 @@ _TimeZoneImpl::_TimeZoneImpl(int rawOffset, const String& id, const TimeRule& st
 
 _TimeZoneImpl::_TimeZoneImpl(const _TimeZoneImpl& otherTimeZone)
        : __pIcuTimeZone(null)
+       , __dstSaving(otherTimeZone.__dstSaving)
        , __dstStartingYear(otherTimeZone.__dstStartingYear)
        , __startingRule(otherTimeZone.__startingRule)
        , __endingRule(otherTimeZone.__endingRule)
@@ -101,6 +107,7 @@ _TimeZoneImpl::_TimeZoneImpl(const _TimeZoneImpl& otherTimeZone)
 
 _TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone)
        : __pIcuTimeZone(null)
+       , __dstSaving(60)
        , __dstStartingYear(0)
        , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
        , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
@@ -111,13 +118,13 @@ _TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone)
 
 _TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone, UDate icuDate)
        : __pIcuTimeZone(null)
+       , __dstSaving(60)
        , __dstStartingYear(0)
        , __startingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
        , __endingRule(MONTH_UNDEFINED, DAY_UNDEFINED)
        , __isCustomizing(false)
 {
        __pIcuTimeZone = pIcuTimeZone;
-
        U_ICU_NAMESPACE::BasicTimeZone* pIcuTz = dynamic_cast<U_ICU_NAMESPACE::BasicTimeZone*>(pIcuTimeZone);
        if (pIcuTz)
        {
@@ -134,9 +141,32 @@ _TimeZoneImpl::_TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone, UDate icuD
                        {
                                GetTimeRuleFromIcuDateTimeRule(pStd->getRule(), __endingRule);
                                __dstStartingYear = pDst->getStartYear();
+                               __dstSaving = pIcuTz->getDSTSavings() / ONE_MIN_IN_MILLISEC;
+                       }
+               }
+               else
+               {
+                       U_ICU_NAMESPACE::TimeZoneTransition transition;
+                       bool result = pIcuTz->getPreviousTransition(icuDate, true, transition);
+                       if (result)
+                       {
+                               const U_ICU_NAMESPACE::TimeZoneRule* pTzFromRule = transition.getFrom();
+                               const U_ICU_NAMESPACE::TimeZoneRule* pTzToRule = transition.getTo();
+
+                               if (pTzFromRule->getDSTSavings())
+                               {
+                                       __dstSaving = pTzFromRule->getDSTSavings() / ONE_MIN_IN_MILLISEC;
+                               }
+                               else if (pTzToRule->getDSTSavings())
+                               {
+                                       __dstSaving = pTzToRule->getDSTSavings() / ONE_MIN_IN_MILLISEC;
+                               }
+                               else //if (pTzFromRule->getDSTSavings() == 0 && pTzToRule->getDSTSavings() == 0)
+                               {
+                                       __dstSaving = 0;
+                               }
                        }
                }
-
                delete pInitial;
                delete pStd;
                delete pDst;
@@ -155,6 +185,7 @@ _TimeZoneImpl::operator =(const _TimeZoneImpl& otherTimeZone)
        if (*this != otherTimeZone)
        {
                __pIcuTimeZone = otherTimeZone.__pIcuTimeZone;
+               __dstSaving = otherTimeZone.__dstSaving;
                __dstStartingYear = otherTimeZone.__dstStartingYear;
                __startingRule = otherTimeZone.__startingRule;
                __endingRule = otherTimeZone.__endingRule;
@@ -270,7 +301,11 @@ _TimeZoneImpl::SetDstStartingYear(int year)
 int
 _TimeZoneImpl::GetDstSavings(void) const
 {
-       return __pIcuTimeZone->getDSTSavings() / ONE_MIN_IN_MILLISEC;
+       if (__isCustomizing)
+       {
+               return __pIcuTimeZone->getDSTSavings() / ONE_MIN_IN_MILLISEC;
+       }
+       return __dstSaving;
 }
 
 void
@@ -290,6 +325,7 @@ _TimeZoneImpl::SetDstSavings(int dstSavings)
                 __pIcuTimeZone = pStz;
        }
        pStz->setDSTSavings(dstSavings * ONE_MIN_IN_MILLISEC, ec);
+       __dstSaving = dstSavings;
        __isCustomizing = true;
 }
 
@@ -393,7 +429,8 @@ _TimeZoneImpl::GetOffset(long long ticks, int& offset) const
 {
        TimeSpan ts(ticks);
        DateTime date;
-       date.SetValue(ts.GetTicks());
+       result r = date.SetValue(ts.GetTicks());
+       SysTryReturnResult(NID_LCL, r == E_SUCCESS, E_INVALID_ARG, "It is an invalid argument.");
 
        int rawOffset = 0;
        int dstOffset = 0;