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 FLclTimeZone.cpp
20 * @brief This is the implementation file for TimeZone class.
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.h>
27 #include <FLclTimeZone.h>
28 #include <FLclTimeRule.h>
30 #include "FLcl_TimeZoneImpl.h"
33 using namespace Tizen::Base;
35 namespace Tizen { namespace Locales
38 enum GregorianCalendarEras
40 GREGORIAN_CALENDAR_BC = 0, // BC
41 GREGORIAN_CALENDAR_AD = 1, // AD
44 TimeZone::TimeZone(void)
45 : __pTimeZoneImpl(null)
47 __pTimeZoneImpl = new (std::nothrow) _TimeZoneImpl;
48 SysAssert(__pTimeZoneImpl);
52 TimeZone::~TimeZone(void)
54 delete __pTimeZoneImpl;
58 TimeZone::TimeZone(const TimeZone& tz)
59 : __pTimeZoneImpl(null)
61 __pTimeZoneImpl = new (std::nothrow) _TimeZoneImpl(*tz.__pTimeZoneImpl);
62 SysAssert(__pTimeZoneImpl);
66 // This method constructs an instance of TimeZone with the given raw GMT offset
67 // and the name of time zone with no pDst.
68 TimeZone::TimeZone(int rawOffset, const String& id)
69 : __pTimeZoneImpl(null)
71 __pTimeZoneImpl = new (std::nothrow) _TimeZoneImpl(rawOffset, id);
72 SysAssert(__pTimeZoneImpl);
76 // This method constructs an instance of TimeZone with the name, offset, and given pDst rules.
77 TimeZone::TimeZone(int rawOffset, const String& id, const TimeRule& startingRule, const TimeRule& endingRule, int dstOffset)
78 : __pTimeZoneImpl(null)
80 __pTimeZoneImpl = new (std::nothrow) _TimeZoneImpl(rawOffset, id, startingRule, endingRule, dstOffset);
81 SysAssert(__pTimeZoneImpl);
85 // This method compares the equality of obj and the current instance.
87 TimeZone::operator ==(const TimeZone& timeZone) const
89 return *__pTimeZoneImpl == *timeZone.__pTimeZoneImpl;
93 TimeZone::Equals(const Object& obj) const
96 const TimeZone* pOtherTimeZone = dynamic_cast< const TimeZone* >(&obj);
97 if (pOtherTimeZone != null)
99 return *this == *pOtherTimeZone;
105 TimeZone::GetHashCode(void) const
108 return __pTimeZoneImpl->GetHashCode();
112 // This method gets the amount of time to be added to local standard time to get local wall clock time.
114 TimeZone::GetDstSavings(void) const
117 return __pTimeZoneImpl->GetDstSavings(); // method return value in minutes
122 TimeZone::GetDstStartingYear(void) const
125 return __pTimeZoneImpl->GetDstStartingYear();
129 // This method gets the difference in minutes between local time and GMT,
130 // taking into consideration both the raw offset and the effect of dst offset.
132 TimeZone::GetOffset(const DateTime& date, bool local, int& rawOffset, int& dstOffset) const
135 return __pTimeZoneImpl->GetOffset(date, local, rawOffset, dstOffset);
139 // This method gets the difference in minutes between local time and GMT,
140 // taking into consideration both the raw offset and the effect of pDst.
142 TimeZone::GetOffset(long long ticks, int& offset) const
145 return __pTimeZoneImpl->GetOffset(ticks, offset);
149 // This method gets the difference in milliseconds between local time and GMT, not including pDst.(i.e. Raw offset)
151 TimeZone::GetRawOffset(void) const
154 return __pTimeZoneImpl->GetRawOffset(); // method return value in minutes
158 // This method gets the id of time zone.
160 TimeZone::GetId(void) const
163 return __pTimeZoneImpl->GetId();
168 TimeZone::GetDstStartingRule(void) const
171 return __pTimeZoneImpl->GetDstStartingRule();
176 TimeZone::GetDstEndingRule(void) const
179 return __pTimeZoneImpl->GetDstEndingRule();
183 // This method checks that the current instance uses pDst.
185 TimeZone::IsDstUsed(void) const
188 return __pTimeZoneImpl->IsDstUsed();
192 // This method sets the amount of time in minute that the clock is advanced during pDst.
194 TimeZone::SetDstSavings(int dstSavings)
197 __pTimeZoneImpl->SetDstSavings(dstSavings);
201 // This method sets the pDst starting/end rule.
203 TimeZone::SetDstRules(const TimeRule& startingRule, const TimeRule& endingRule, int dstSavings)
206 return __pTimeZoneImpl->SetDstRules(startingRule, endingRule, dstSavings);
210 // This method sets the pDst end rule
212 TimeZone::SetDstEndingRule(const TimeRule& endingRule)
215 __pTimeZoneImpl->SetDstEndingRule(endingRule);
219 // This method sets the pDst starting rule
221 TimeZone::SetDstStartingRule(const TimeRule& startingRule)
224 __pTimeZoneImpl->SetDstStartingRule(startingRule);
228 // This method sets the difference in minutes between local time and GMT, not including pDst.(i.e. Raw offset)
230 TimeZone::SetRawOffset(int rawOffset)
233 __pTimeZoneImpl->SetRawOffset(rawOffset); // rawOffset is in minutes
237 // This method sets the pDst starting year.
239 TimeZone::SetDstStartingYear(int year)
242 __pTimeZoneImpl->SetDstStartingYear(year);
246 // This method sets the id of time zone.
248 TimeZone::SetId(const String& id)
251 __pTimeZoneImpl->SetId(id);
255 // This operator assigns the specified @c TimeZone instance to the current instance.
257 TimeZone::operator =(const TimeZone& otherTimeZone)
260 if (otherTimeZone != *this)
262 delete __pTimeZoneImpl;
263 __pTimeZoneImpl = otherTimeZone.__pTimeZoneImpl->CloneN();
269 // This inequality operator returns @c true if the specified @c TimeZone instance is not equals to the
270 // current instance. Otherwise, the operator returns @c false.
272 TimeZone::operator !=(const TimeZone& otherTimeZone) const
275 return !operator ==(otherTimeZone);
279 // This method converts the UTC time to the standard time.
280 Tizen::Base::DateTime
281 TimeZone::UtcTimeToStandardTime(const Tizen::Base::DateTime& utcTime)
284 DateTime standardTime = utcTime;
285 standardTime.AddMinutes(__pTimeZoneImpl->GetRawOffset());
290 // This method converts the UTC time to the wall time.
291 Tizen::Base::DateTime
292 TimeZone::UtcTimeToWallTime(const Tizen::Base::DateTime& utcTime)
295 DateTime wallTime = utcTime;
299 result r = __pTimeZoneImpl->GetOffset(utcTime, false, rawOffset, dstOffset);
302 wallTime.AddMinutes(rawOffset + dstOffset);
308 // This method converts the standard time to the UTC time.
309 Tizen::Base::DateTime
310 TimeZone::StandardTimeToUtcTime(const Tizen::Base::DateTime& standardTime)
313 DateTime utcTime = standardTime;
314 utcTime.AddMinutes(-GetRawOffset());
319 // This method converts the wall time to the UTC time.
320 Tizen::Base::DateTime
321 TimeZone::WallTimeToUtcTime(const Tizen::Base::DateTime& wallTime)
324 DateTime utcTime = wallTime;
328 result r = GetOffset(wallTime, true, rawOffset, dstOffset);
329 SysAssert(r == E_SUCCESS);
331 utcTime.AddMinutes(-(rawOffset + dstOffset));
336 // This method gets the GMT.
337 // The GMT time zone has a raw offset of zero and does not use daylight savings time.
339 TimeZone::GetGmtTimeZone(void)
342 return TimeZone(0, L"Europe/London");
346 TimeZone::GetTimeZone(const Tizen::Base::String& id, Tizen::Locales::TimeZone& timeZone)
349 return _TimeZoneImpl::GetTimeZone(id, timeZone);
353 TimeZone::GetTimeZone(const Tizen::Base::String& id, const Tizen::Base::DateTime& utcTime, Tizen::Locales::TimeZone& timeZone)
356 return _TimeZoneImpl::GetTimeZone(id, utcTime, timeZone);
361 TimeZone::UtcTimeToStandardTime(const DateTime& utcTime, int rawOffset)
364 DateTime dt = utcTime;
365 dt.AddMinutes(rawOffset);
372 TimeZone::StandardTimeToUtcTime(const DateTime& standardTime, int rawOffset)
375 DateTime dt = standardTime;
376 dt.AddMinutes(rawOffset);
383 TimeZone::UtcTimeToWallTime(const DateTime& utcTime, int rawOffset, int dstOffset)
386 DateTime dt = utcTime;
387 dt.AddMinutes(rawOffset + dstOffset);
394 TimeZone::WallTimeToUtcTime(const DateTime& wallTime, int rawOffset, int dstOffset)
397 DateTime dt = wallTime;
398 dt.AddMinutes(rawOffset + dstOffset);