2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FLclTimeZone.h
19 * @brief This is the header file for the %TimeZone class.
20 * @see Tizen::Locales::Locale
22 * This header file contains the declarations of the %TimeZone class.
25 #ifndef _FLCL_TIME_ZONE_H_
26 #define _FLCL_TIME_ZONE_H_
28 #include <FBaseString.h>
29 #include <FBaseDateTime.h>
30 #include <FLclTimeRule.h>
32 namespace Tizen { namespace Locales
37 * @brief This class represents the time zones.
41 * @final This class is not intended for extension.
43 * The %TimeZone class represents a time zone offset and figures out Daylight Saving Time (DST).
45 * The form of time zone ID is "Area/Location". @n
47 * However, the specialized time zone IDs have the different form, such as CST6CDT, EST5EDT and so on. @n
49 * For more information on IDs, refer <a href="http://www.iana.org/time-zones" target="_blank">Time Zone Database</a>. @n
51 * The supported time zone list depends on the device. Therefore, it must be checked by using LocaleManager::GetAvailableTimeZonesN().
53 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/locales/time_zone.htm">Time Zones</a>.
55 * The following example demonstrates how to use the %TimeZone class.
63 using namespace Tizen::Locales;
66 MyClass::MyTimeZone(void)
68 // Gets the system time zone.
69 LocaleManager localeManager;
70 localeManager.Construct();
72 TimeZone timeZone = localeManager.GetSystemTimeZone();
74 String timeZoneId = timeZone.GetId();
75 int rawOffset = timeZone.GetRawOffset();
76 int dstSavings = timeZone.GetDstSavings();
78 // Gets the special time zone.
81 Tizen::System::SystemTime::GetCurrentTime(utcTime);
82 Tizen::Locales::TimeZone::GetTimeZone(L"Europe/Zurich", utcTime, timeZone2);
88 class _OSP_EXPORT_ TimeZone
89 : public Tizen::Base::Object
93 * This is the default constructor for this class.
101 * This is the destructor for this class. @n
102 * This destructor overrides Tizen::Base::Object::~Object().
106 virtual ~TimeZone(void);
110 * This is the copy constructor for the %TimeZone class. @n
111 * It initializes an instance of %TimeZone with the values of the specified instance of %TimeZone.
112 * Copying of objects using this copy constructor is allowed.
116 * @param[in] otherTimeZone An instance of %TimeZone
118 TimeZone(const TimeZone& otherTimeZone);
121 * Assigns the value of the specified instance to the current instance of %TimeZone. @n
122 * Copying of objects using this copy assignment operator is allowed.
126 * @return A reference value of the current instance
127 * @param[in] otherTimeZone An instance of %TimeZone
130 TimeZone& operator =(const TimeZone& otherTimeZone);
133 * Initializes this instance of %TimeZone with the specified raw GMT offset and the ID of the time zone without including DST.
137 * @param[in] rawOffset The base time zone offset to GMT in minutes
138 * @param[in] id The time zone ID
139 * @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
140 * However, the supported time zone list depends on the device. Therefore, it must be checked before using this method.
141 * @see LocaleManager::GetAvailableTimeZonesN()
143 TimeZone(int rawOffset, const Tizen::Base::String& id);
146 * Initializes this instance of %TimeZone with the specified raw GMT offset,
147 * the ID of the time zone, the rules for starting/ending DST, and the DST offset.
151 * @param[in] rawOffset The base time zone offset to GMT in minutes
152 * @param[in] id The time zone ID
153 * @param[in] startRule The DST starting rule
154 * @param[in] endRule The DST end rule
155 * @param[in] dstOffset The amount of time in minutes saved during DST
156 * @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
157 * However, the supported time zone list depends on the device. Therefore, it must be checked before using this method.
158 * @see LocaleManager::GetAvailableTimeZonesN()
160 TimeZone(int rawOffset, const Tizen::Base::String& id,
161 const TimeRule& startRule, const TimeRule& endRule, int dstOffset);
164 * Checks whether the specified instance of %TimeZone equals the value of the current instance.
168 * @return @c true if the two instances are equal, @n
170 * @param[in] otherTimeZone An instance of %TimeZone
172 bool operator ==(const TimeZone& otherTimeZone) const;
175 * Checks whether the %TimeZone instance is equal to the current instance.
179 * @return @c true if the two instances are not equal, @n
181 * @param[in] otherTimeZone An instance of %TimeZone
183 bool operator !=(const TimeZone& otherTimeZone) const;
186 * Compares the value of the specified instance to that of the current instance.
190 * @return @c true if the value of the specified instance is equal to that of the current instance, @n
192 * @param[in] obj The object to compare with the current instance
194 virtual bool Equals(const Tizen::Base::Object& obj) const;
197 * Gets the hash value of the current instance.
201 * @return The hash value of the current instance
203 virtual int GetHashCode(void) const;
210 * @param[in] dstSavings The amount of time in minutes @n
211 * The time is advanced with respect to the standard time when the DST rules are in effect.
213 void SetDstSavings(int dstSavings);
216 * Sets the DST starting and end rule.
220 * @return An error code
221 * @param[in] startRule The DST starting rule
222 * @param[in] endRule The DST end rule
223 * @param[in] dstSavings The DST offset in minutes
224 * @exception E_SUCCESS The method is successful.
225 * @exception E_OUT_OF_RANGE The specified @c dstSavings is less than 24 hours.
227 result SetDstRules(const TimeRule& startRule, const TimeRule& endRule, int dstSavings = 60);
230 * Sets the DST end rule.
234 * @param[in] endRule The DST end rule
236 void SetDstEndingRule(const TimeRule& endRule);
239 * Sets the DST starting rule.
243 * @param[in] startRule The DST starting rule
245 void SetDstStartingRule(const TimeRule& startRule);
248 * Sets the difference in minutes between the local standard time and GMT,
249 * without including DST (that is, raw offset).
253 * @param[in] rawOffset The difference in minutes between the local standard time and GMT, without including DST
255 void SetRawOffset(int rawOffset);
258 * Sets the DST starting year.
262 * @param[in] year The DST starting year
264 void SetDstStartingYear(int year);
267 * Sets the ID of the time zone.
271 * @param[in] id The ID of the time zone
273 void SetId(const Tizen::Base::String& id);
276 * Converts the Coordinated Universal Time (UTC) time to the standard time.
280 * @return The standard time
281 * @param[in] utcTime The UTC time
283 Tizen::Base::DateTime UtcTimeToStandardTime(const Tizen::Base::DateTime& utcTime);
286 * Converts the UTC time to the wall time.
290 * @return The wall time
291 * @param[in] utcTime The UTC time
293 Tizen::Base::DateTime UtcTimeToWallTime(const Tizen::Base::DateTime& utcTime);
296 * Converts the standard time to the UTC time.
300 * @return The UTC time
301 * @param[in] standardTime The standard time
303 Tizen::Base::DateTime StandardTimeToUtcTime(const Tizen::Base::DateTime& standardTime);
306 * Converts the wall time to the UTC time.
310 * @return The UTC time
311 * @param[in] wallTime The wall time
313 Tizen::Base::DateTime WallTimeToUtcTime(const Tizen::Base::DateTime& wallTime);
316 * Gets the amount of time in minutes to be added to the local standard time to get the local wall time.
320 * @return The amount of time in minutes
323 int GetDstSavings(void) const;
326 * Gets the starting year of the DST.
330 * @return The starting year of the DST set by the SetDstStartingYear() method, @n
331 * else @c 0 if the starting year of the DST is undefined
332 * @see SetDstStartingYear()
334 int GetDstStartingYear(void) const;
337 * Gets the raw and GMT offset for the specified instance of Tizen::Base::DateTime in the current time zone.
340 * @brief <i> [Compatibility] </i>
344 * @compatibility This method has compatibility issues with OSP compatible applications. @n
345 * For more information, see @ref CompTimeZoneGetOffsetPage "here".
348 * @return An error code
349 * @param[in] date An instance of Tizen::Base::DateTime
350 * @param[in] local Set to @c true if the date is in local wall time @n
351 * else @c false if it is in GMT time
352 * @param[out] rawOffset The time zone's raw offset in minutes
353 * @param[out] dstOffset The offset to add to @c rawOffset to obtain the total offset between the local and GMT time @n
354 * If DST is not in effect, it is zero.
355 * @exception E_SUCCESS The method is successful.
356 * @exception E_INVALID_ARG The specified @c date is invalid.
357 * @remarks Local millisecond = GMT milliseconds + rawOffset(in milliseconds) + dstOffset(in milliseconds).
358 * All computations are performed in Gregorian calendar.
360 result GetOffset(const Tizen::Base::DateTime& date, bool local, int& rawOffset, int& dstOffset) const;
363 * Gets the difference in minutes between the local standard time and GMT, taking into consideration both the raw offset and the effect of DST.
366 * @brief <i> [Compatibility] </i>
370 * @compatibility This method has compatibility issues with OSP compatible applications. @n
371 * For more information, see @ref CompTimeZoneGetOffsetPage "here".
374 * @return An error code
375 * @param[in] ticks The time ticks value @n
376 * The value is GMT time from starting day (Jan 1, 1.).
377 * @param[out] offset The offset between the local standard time and GMT, taking into consideration DST
378 * @exception E_SUCCESS The method is successful.
379 * @exception E_INVALID_ARG The specified @c ticks is invalid.
380 * @see Base::DateTime::GetTicks()
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 compatible 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 compatible 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_