Apply historical dst offset for timezone.
[platform/framework/native/appfw.git] / src / locales / FLcl_TimeZoneImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FLcl_TimeZoneImpl.h
19  * @brief       This is the header file for the _TimeZoneImpl class.
20  *
21  * This header file contains declarations of the _TimeZoneImpl class.
22  *
23  */
24
25 #ifndef _FLCL_INTERNAL_TIME_ZONE_IMPL_H_
26 #define _FLCL_INTERNAL_TIME_ZONE_IMPL_H_
27
28 #include <unicode/simpletz.h>
29
30 #include <FBaseObject.h>
31 #include <FBaseString.h>
32 #include <FLclTimeRule.h>
33 #include <FLclTimeZone.h>
34
35 namespace Tizen { namespace Locales
36 {
37
38 class _TimeZoneImpl
39         : public Tizen::Base::Object
40 {
41 public:
42
43         _TimeZoneImpl(void);
44         _TimeZoneImpl(int rawOffset, const Tizen::Base::String& id);
45         _TimeZoneImpl(int rawOffset, const Tizen::Base::String& id, const TimeRule& startRule, const TimeRule& endRule, int dstOffset);
46         _TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone);
47         _TimeZoneImpl(U_ICU_NAMESPACE::TimeZone* pIcuTimeZone, UDate icuDate);
48
49         _TimeZoneImpl(const _TimeZoneImpl& otherTimeZone);
50
51         virtual ~_TimeZoneImpl(void);
52
53         _TimeZoneImpl& operator =(const _TimeZoneImpl& otherTimeZone);
54         _TimeZoneImpl* CloneN(void);
55
56         bool operator ==(const _TimeZoneImpl& otherTimeZone) const;
57         bool operator !=(const _TimeZoneImpl& otherTimeZone) const;
58         virtual bool Equals(const Tizen::Base::Object& obj) const;
59         virtual int GetHashCode(void) const;
60
61         Tizen::Base::String GetId(void) const;
62         void SetId(const Tizen::Base::String& id);
63
64         int GetRawOffset(void) const;
65         void SetRawOffset(int rawOffset);
66
67         int GetDstStartingYear(void) const;
68         void SetDstStartingYear(int year);
69
70         int GetDstSavings(void) const;
71         void SetDstSavings(int dstSavings);
72
73         const TimeRule* GetDstStartingRule(void) const;
74         void SetDstStartingRule(const TimeRule& startRule);
75
76         const TimeRule* GetDstEndingRule(void) const;
77         void SetDstEndingRule(const TimeRule& endRule);
78
79         result SetDstRules(const TimeRule& startRule, const TimeRule& endRule, int dstSavings = 60);
80
81         result GetOffset(const Tizen::Base::DateTime& date, bool local, int& rawOffset, int& dstOffset) const;
82         result GetOffset(long long ticks, int& offset) const;
83         bool IsDstUsed(void) const;
84
85         U_ICU_NAMESPACE::TimeZone* GetIcuTimeZone(void) const;
86
87         static const _TimeZoneImpl* GetTimeZoneImpl(const TimeZone& ospTimeZone);
88         static result GetTimeZone(const Tizen::Base::String& id, Tizen::Locales::TimeZone& timeZone);
89         static result GetTimeZone(const Tizen::Base::String& id, const Tizen::Base::DateTime& utcTime, Tizen::Locales::TimeZone& timeZone);
90
91 private:
92         void GetIcuTimeRuleValue(const TimeRule& ospRule, int& month, int& dayOfWeekInMonth, int& dayOfWeek, int& time, int& mode);
93         result GetTimeRuleFromIcuDateTimeRule(const U_ICU_NAMESPACE::DateTimeRule* pIcuRule, TimeRule& ospRule);
94
95 public:
96         static const int ONE_MIN_IN_MILLISEC = 60 * 1000;
97         static const int ONE_HOUR_IN_MILLISEC = 60 * ONE_MIN_IN_MILLISEC;
98         static const int ONE_DAY_IN_MILLISEC = 24 * ONE_HOUR_IN_MILLISEC;
99         static const int ONE_DAY_IN_MINUTE = 24 * 60;
100
101 private:
102         U_ICU_NAMESPACE::TimeZone* __pIcuTimeZone;
103
104         int __dstSaving;
105         int __dstStartingYear;
106         TimeRule __startingRule;
107         TimeRule __endingRule;
108         bool __isCustomizing;
109
110         static const int DAY_UNDEFINED = -1;
111 }; // _TimeZoneImpl
112
113 }} // Tizen::Locales
114 #endif //_FLCL_INTERNAL_TIME_ZONE_IMPL_H_
115