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.h
20 * @brief This is the header file for the %TimeZone class.
21 * @see Tizen::Locales::Locale
23 * This header file contains the declarations of the %TimeZone class.
26 #ifndef _FLCL_TIME_ZONE_H_
27 #define _FLCL_TIME_ZONE_H_
29 #include <FBaseString.h>
30 #include <FBaseDateTime.h>
31 #include <FLclTimeRule.h>
33 namespace Tizen { namespace Locales
38 * @brief This class represents the time zones.
42 * @final This class is not intended for extension.
44 * The %TimeZone class represents a time zone offset and figures out Daylight Saving Time (DST).
46 * The form of time zone ID is "Area/Location". @n
48 * However, the specialized time zone IDs have the different form, such as CST6CDT, EST5EDT and so on. @n
50 * For more information on IDs, refer <a href="http://www.iana.org/time-zones" target="_blank">Time Zone Database</a>. @n
52 * The supported time zone list depends on the device. Therefore, it must be checked by using LocaleManager::GetAvailableTimeZonesN().
54 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/locales/time_zone.htm">Time Zones</a>.
56 * The following example demonstrates how to use the %TimeZone class.
64 using namespace Tizen::Locales;
67 MyClass::MyTimeZone(void)
69 // Gets the system time zone.
70 LocaleManager localeManager;
71 localeManager.Construct();
73 TimeZone timeZone = localeManager.GetSystemTimeZone();
75 String timeZoneId = timeZone.GetId();
76 int rawOffset = timeZone.GetRawOffset();
77 int dstSavings = timeZone.GetDstSavings();
79 // Gets the special time zone.
82 Tizen::System::SystemTime::GetCurrentTime(utcTime);
83 Tizen::Locales::TimeZone::GetTimeZone(L"Europe/Zurich", utcTime, timeZone2);
89 class _OSP_EXPORT_ TimeZone
90 : public Tizen::Base::Object
94 * This is the default constructor for this class.
102 * This is the destructor for this class. @n
103 * This destructor overrides Tizen::Base::Object::~Object().
107 virtual ~TimeZone(void);
111 * This is the copy constructor for the %TimeZone class. @n
112 * It initializes an instance of %TimeZone with the values of the specified instance of %TimeZone.
113 * Copying of objects using this copy constructor is allowed.
117 * @param[in] otherTimeZone An instance of %TimeZone
119 TimeZone(const TimeZone& otherTimeZone);
122 * Assigns the value of the specified instance to the current instance of %TimeZone. @n
123 * Copying of objects using this copy assignment operator is allowed.
127 * @return A reference value of the current instance
128 * @param[in] otherTimeZone An instance of %TimeZone
131 TimeZone& operator =(const TimeZone& otherTimeZone);
134 * Initializes this instance of %TimeZone with the specified raw GMT offset and the ID of the time zone without including DST.
138 * @param[in] rawOffset The base time zone offset to GMT in minutes
139 * @param[in] id The time zone ID
140 * @remarks The form of time zone @c id is "Area/Location". @n For more information on IDs, refer <a href="http://www.iana.org/time-zones" target="_blank">here</a>. @n
141 * However, the supported time zone list depends on the device. Therefore, it must be checked before using this method.
142 * @see LocaleManager::GetAvailableTimeZonesN()
144 TimeZone(int rawOffset, const Tizen::Base::String& id);
147 * Initializes this instance of %TimeZone with the specified raw GMT offset,
148 * the ID of the time zone, the rules for starting/ending DST, and the DST offset.
152 * @param[in] rawOffset The base time zone offset to GMT in minutes
153 * @param[in] id The time zone ID
154 * @param[in] startRule The DST starting rule
155 * @param[in] endRule The DST end rule
156 * @param[in] dstOffset The amount of time in minutes saved during DST
157 * @remarks The form of time zone @c id is "Area/Location". @n For more information on IDs, refer <a href="http://www.iana.org/time-zones" target="_blank">here</a>. @n
158 * However, the supported time zone list depends on the device. Therefore, it must be checked before using this method.
159 * @see LocaleManager::GetAvailableTimeZonesN()
161 TimeZone(int rawOffset, const Tizen::Base::String& id,
162 const TimeRule& startRule, const TimeRule& endRule, int dstOffset);
165 * Checks whether the specified instance of %TimeZone equals the value of the current instance.
169 * @return @c true if the two instances are equal, @n
171 * @param[in] otherTimeZone An instance of %TimeZone
173 bool operator ==(const TimeZone& otherTimeZone) const;
176 * Checks whether the %TimeZone instance is equal to the current instance.
180 * @return @c true if the two instances are not equal, @n
182 * @param[in] otherTimeZone An instance of %TimeZone
184 bool operator !=(const TimeZone& otherTimeZone) const;
187 * Compares the value of the specified instance to that of the current instance.
191 * @return @c true if the value of the specified instance is equal to that of the current instance, @n
193 * @param[in] obj The object to compare with the current instance
195 virtual bool Equals(const Tizen::Base::Object& obj) const;
198 * Gets the hash value of the current instance.
202 * @return The hash value of the current instance
204 virtual int GetHashCode(void) const;
211 * @param[in] dstSavings The amount of time in minutes @n
212 * The time is advanced with respect to the standard time when the DST rules are in effect.
214 void SetDstSavings(int dstSavings);
217 * Sets the DST starting and end rule.
221 * @return An error code
222 * @param[in] startRule The DST starting rule
223 * @param[in] endRule The DST end rule
224 * @param[in] dstSavings The DST offset in minutes
225 * @exception E_SUCCESS The method is successful.
226 * @exception E_OUT_OF_RANGE The specified @c dstSavings is less than 24 hours.
228 result SetDstRules(const TimeRule& startRule, const TimeRule& endRule, int dstSavings = 60);
231 * Sets the DST end rule.
235 * @param[in] endRule The DST end rule
237 void SetDstEndingRule(const TimeRule& endRule);
240 * Sets the DST starting rule.
244 * @param[in] startRule The DST starting rule
246 void SetDstStartingRule(const TimeRule& startRule);
249 * Sets the difference in minutes between the local standard time and GMT,
250 * without including DST (that is, raw offset).
254 * @param[in] rawOffset The difference in minutes between the local standard time and GMT, without including DST
256 void SetRawOffset(int rawOffset);
259 * Sets the DST starting year.
263 * @param[in] year The DST starting year
265 void SetDstStartingYear(int year);
268 * Sets the ID of the time zone.
272 * @param[in] id The ID of the time zone
274 void SetId(const Tizen::Base::String& id);
277 * Converts the Coordinated Universal Time (UTC) time to the standard time.
281 * @return The standard time
282 * @param[in] utcTime The UTC time
284 Tizen::Base::DateTime UtcTimeToStandardTime(const Tizen::Base::DateTime& utcTime);
287 * Converts the UTC time to the wall time.
291 * @return The wall time
292 * @param[in] utcTime The UTC time
294 Tizen::Base::DateTime UtcTimeToWallTime(const Tizen::Base::DateTime& utcTime);
297 * Converts the standard time to the UTC time.
301 * @return The UTC time
302 * @param[in] standardTime The standard time
304 Tizen::Base::DateTime StandardTimeToUtcTime(const Tizen::Base::DateTime& standardTime);
307 * Converts the wall time to the UTC time.
311 * @return The UTC time
312 * @param[in] wallTime The wall time
314 Tizen::Base::DateTime WallTimeToUtcTime(const Tizen::Base::DateTime& wallTime);
317 * Gets the amount of time in minutes to be added to the local standard time to get the local wall time.
321 * @return The amount of time in minutes
324 int GetDstSavings(void) const;
327 * Gets the starting year of the DST.
331 * @return The starting year of the DST set by the SetDstStartingYear() method, @n
332 * else @c 0 if the starting year of the DST is undefined
333 * @see SetDstStartingYear()
335 int GetDstStartingYear(void) const;
338 * Gets the raw and GMT offset for the specified instance of Tizen::Base::DateTime in the current time zone.
341 * @brief <i> [Compatibility] </i>
345 * @compatibility This method has compatibility issues with OSP compatibile applications. @n
346 * For more information, see @ref CompTimeZoneGetOffsetPage "here".
349 * @return An error code
350 * @param[in] date An instance of Tizen::Base::DateTime
351 * @param[in] local Set to @c true if the date is in local wall time @n
352 * else @c false if it is in GMT time
353 * @param[out] rawOffset The time zone's raw offset in minutes
354 * @param[out] dstOffset The offset to add to @c rawOffset to obtain the total offset between the local and GMT time @n
355 * If DST is not in effect, it is zero.
356 * @exception E_SUCCESS The method is successful.
357 * @exception E_INVALID_ARG The specified @c date is invalid.
358 * @remarks Local millisecond = GMT milliseconds + rawOffset(in milliseconds) + dstOffset(in milliseconds).
359 * All computations are performed in Gregorian calendar.
361 result GetOffset(const Tizen::Base::DateTime& date, bool local, int& rawOffset, int& dstOffset) const;
364 * Gets the difference in minutes between the local standard time and GMT, taking into consideration both the raw offset and the effect of DST.
367 * @brief <i> [Compatibility] </i>
371 * @compatibility This method has compatibility issues with OSP compatibile applications. @n
372 * For more information, see @ref CompTimeZoneGetOffsetPage "here".
375 * @return An error code
376 * @param[in] ticks The time ticks value @n
377 * The value is GMT time.
378 * @param[out] offset The offset between the local standard time and GMT, taking into consideration DST
379 * @exception E_SUCCESS The method is successful.
380 * @exception E_INVALID_ARG The specified @c ticks is invalid.
382 result GetOffset(long long ticks, int& offset) const;
386 * @page CompTimeZoneGetOffsetPage Compatibility for GetOffset()
387 * @section CompTimeZoneGetOffsetIssueSection Issues
388 * Implementation of this method in OSP compatible applications has the following issue: @n
389 * -# The method returns E_OUT_OF_RANGE if an argument is invalid.
391 * @section CompTimeZoneGetOffsetSolutionSection Resolutions
392 * This issue has been resolved in Tizen.
393 * @par When working in Tizen:
394 * -# The method returns E_INVALID_ARG if an argument is invalid.
399 * Gets the difference in minutes between the local standard time and GMT, without including DST (that is, raw offset).
403 * @return The raw offset
406 int GetRawOffset(void) const;
409 * Gets the ID of the time zone.
413 * @return The ID of the time zone
415 Tizen::Base::String GetId(void) const;
418 * Gets the DST starting rule.
422 * @return A pointer to the DST start rule, @n
423 * else a @c null pointer if the DST start rule is undefined
425 const TimeRule* GetDstStartingRule(void) const;
428 * Gets the DST end rule.
432 * @return A pointer to the DST end rule, @n
433 * else a @c null pointer if the DST end rule is undefined
435 const TimeRule* GetDstEndingRule(void) const;
438 * Checks whether the current instance of %TimeZone uses DST.
442 * @return @c true if the current instance uses DST, @n
445 bool IsDstUsed(void) const;
448 * Gets the GMT time zone. @n
449 * The GMT time zone has a raw offset of @c 0 and does not use DST.
453 * @return The GMT time zone
455 static TimeZone GetGmtTimeZone(void);
458 * Gets the time zone instance from the given ID.
461 * @brief <i> [Compatibility] </i>
465 * @compatibility This method has compatibility issues with OSP compatibile applications. @n
466 * For more information, see @ref CompTimeZoneGetTimeZonePage "here".
469 * @return An error code
470 * @param[in] id The time zone ID
471 * @param[out] timeZone The time zone for the given ID
472 * @exception E_SUCCESS The method is successful.
473 * @exception E_INVALID_ARG The specified @c id is invalid.
474 * @remarks The %TimeZone instance for the specified @c id does not contain the DST information.
475 * The supported time zone list depends on the device. Therefore, it should be checked before using this method.
476 * @see LocaleManager::GetAvailableTimeZonesN()
478 static result GetTimeZone(const Tizen::Base::String& id, Tizen::Locales::TimeZone& timeZone);
481 * Gets the %TimeZone instance from the specified ID and UTC time.
484 * @brief <i> [Compatibility] </i>
488 * @compatibility This method has compatibility issues with OSP compatibile applications. @n
489 * For more information, see @ref CompTimeZoneGetTimeZonePage "here".
492 * @return An error code
493 * @param[in] id The time zone ID
494 * @param[in] utcTime The UTC time
495 * @param[out] timeZone The time zone for the specified ID and UTC time
496 * @exception E_SUCCESS The method is successful.
497 * @exception E_INVALID_ARG The specified @c id is invalid.
498 * @remarks The %TimeZone instance for the specified ID and UTC time contains the DST information.
499 * The supported time zone list depends on the device. Therefore, it should be checked before using this method.
500 * @see LocaleManager::GetAvailableTimeZonesN()
502 static result GetTimeZone(const Tizen::Base::String& id, const Tizen::Base::DateTime& utcTime, Tizen::Locales::TimeZone& timeZone);
506 * @page CompTimeZoneGetTimeZonePage Compatibility for GetTimeZone()
507 * @section CompTimeZoneGetTimeZoneIssueSection Issues
508 * Implementation of this method in OSP compatible applications has the following issue: @n
509 * -# The method returns E_UNSUPPORTED_OPERATION if the time zone ID is invalid.
511 * @section CompTimeZoneGetTimeZoneSolutionSection Resolutions
512 * This issue has been resolved in Tizen.
513 * @par When working in Tizen:
514 * -# The method returns E_INVALID_ARG if the time zone ID is invalid.
519 * Converts the UTC time to the standard time.
523 * @return The standard time
524 * @param[in] utcTime The UTC time
525 * @param[in] rawOffset The time zone's raw offset in minutes
527 static Tizen::Base::DateTime UtcTimeToStandardTime(const Tizen::Base::DateTime& utcTime, int rawOffset);
530 * Converts the standard time to the UTC time.
534 * @return The UTC time
535 * @param[in] standardTime The standard time
536 * @param[in] rawOffset The time zone's raw offset in minutes
538 static Tizen::Base::DateTime StandardTimeToUtcTime(const Tizen::Base::DateTime& standardTime, int rawOffset);
541 * Converts the UTC time to the wall time.
545 * @return The wall time
546 * @param[in] utcTime The UTC time
547 * @param[in] rawOffset The time zone's raw offset in minutes
548 * @param[in] dstOffset The amount of time in minutes saved during DST
550 static Tizen::Base::DateTime UtcTimeToWallTime(const Tizen::Base::DateTime& utcTime, int rawOffset, int dstOffset);
553 * Converts the wall time to the UTC time.
557 * @return The UTC time
558 * @param[in] wallTime The wall time
559 * @param[in] rawOffset The time zone's raw offset in minutes
560 * @param[in] dstOffset The amount of time in minutes saved during DST
562 static Tizen::Base::DateTime WallTimeToUtcTime(const Tizen::Base::DateTime& wallTime, int rawOffset, int dstOffset);
566 friend class _TimeZoneImpl;
567 class _TimeZoneImpl* __pTimeZoneImpl;
569 friend class _LocaleData;
573 #endif // _FLCL_TIME_ZONE_H_