2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 #ifndef __UTILS_I18N_TIMEZONE_H__
18 #define __UTILS_I18N_TIMEZONE_H__
20 #include <utils_i18n_types.h>
23 * @file utils_i18n_timezone.h
25 * @brief utils_i18n_timezone
33 * @ingroup CAPI_BASE_UTILS_I18N_MODULE
34 * @defgroup CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE Timezone
35 * @brief The Timezone module represents a time zone offset, and also figures out daylight savings.
36 * @section CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE_HEADER Required Header
37 * \#include <utils_i18n.h>
39 * @section CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE_OVERVIEW Overview
40 * @details The Timezone module represents a time zone offset, and also figures out daylight savings.\n
41 * Typically, you get an i18n_timezone_h using #i18n_timezone_create_default which creates a TimeZone based on the time zone
42 * where the program is running. For example, for a program running in Japan,
43 * #i18n_timezone_create_default creates an i18n_timezone_h based on Japanese Standard Time.\n
44 * You can also get an i18n_timezone_h using #i18n_timezone_create along with a time zone ID.
45 * For instance, the time zone ID for the US Pacific Time zone is "America/Los_Angeles".
46 * So, you can get a Pacific Time i18n_timezone_h with:\n
48 * i18n_timezone_h timezone;\n
49 * i18n_timezone_create(&timezone, "America/Los_Angeles");\n
51 * To create a new i18n_timezone_h, you call the factory function #i18n_timezone_create() and pass it a time zone ID.
52 * You can use the int #i18n_timezone_foreach_timezone_id() function to obtain a list of all the time zone IDs recognized by #i18n_timezone_create().\n
53 * You can also use #i18n_timezone_create_default() to create an i18n_timezone_h. This function uses platform-specific APIs to produce
54 * an i18n_timezone_h for the time zone corresponding to the client's computer's physical location.
55 * For example, if you're in Japan (assuming your machine is set up correctly), #i18n_timezone_create_default()
56 * will return an i18n_timezone_h for Japanese Standard Time ("Asia/Tokyo").
60 * @addtogroup CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE
65 * @brief Returns the "unknown" time zone.
66 * @details #i18n_timezone_create() returns a mutable clone of this time zone if the input ID is not recognized.
67 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
69 * @param[out] timezone the "unknown" time zone.
71 * @retval #I18N_ERROR_NONE Successful
72 * @see i18n_timezone_create()
73 * @see i18n_timezone_create_gmt()
75 int i18n_timezone_create_unknown ( i18n_timezone_h *timezone );
78 * @brief The GMT (=UTC) time zone has a raw offset of zero and does not use daylight savings time.
79 * @details This is a commonly used time zone.\n
80 * Note: For backward compatibility reason, the ID used by the time zone returned by this method is "GMT", although the I18N's canonical ID for the GMT time zone is "Etc/GMT".
81 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
83 * @param[out] timezone the GMT/UTC time zone.
85 * @retval #I18N_ERROR_NONE Successful
86 * @see i18n_timezone_create_unknown()
88 int i18n_timezone_create_gmt ( i18n_timezone_h *timezone );
91 * @brief Creates an i18n_timezone_h for the given timezone_id.
92 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
94 * @param[out] timezone the GMT/UTC time zone.
95 * @param[in] timezone_id the ID for an i18n_timezone_h, such as "America/Los_Angeles", or a custom ID such as "GMT-8:00".
97 * @retval #I18N_ERROR_NONE Successful
99 int i18n_timezone_create ( i18n_timezone_h *timezone, const char *timezone_id );
102 * @brief Destroys an i18n_timezone_h.
103 * @details Once destroyed, an i18n_timezone_h may no longer be used.
104 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
106 * @param[in] timezone The i18n_timezone_h to destroy.
108 * @retval #I18N_ERROR_NONE Successful
110 int i18n_timezone_destroy(i18n_timezone_h timezone);
113 * @brief Returns an enumeration over system time zone IDs with the given filter conditions.
114 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
116 * @param[in] timezone_type The system time zone type.
117 * @param[in] region The ISO 3166 two-letter country code or UN M.49 three-digit area code. When NULL, no filtering done by region.
118 * @param[in] raw_offset An offset from GMT in milliseconds, ignoring the effect of daylight savings time, if any. When NULL, no filtering done by zone offset.
119 * @param[in] cb The callback function to get an enumeration object, owned by the caller.
120 * @param[in] user_data The user data to be passed to the callback function.
122 * @retval #I18N_ERROR_NONE Successful
124 int i18n_timezone_foreach_timezone_id_by_region(i18n_system_timezone_type_e timezone_type, const char *region, const int32_t *raw_offset, i18n_timezone_id_cb cb, void* user_data);
127 * @brief Returns an enumeration over all recognized time zone IDs.
128 * (i.e., all strings that #i18n_timezone_create() accepts)
129 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
131 * @param[in] cb The callback function to get an enumeration object, owned by the caller.
132 * @param[in] user_data The user data to be passed to the callback function.
134 * @retval #I18N_ERROR_NONE Successful
136 int i18n_timezone_foreach_timezone_id(i18n_timezone_id_cb cb, void* user_data);
139 * @brief Returns an enumeration over time zone IDs with a given raw offset from GMT.
140 * @details There may be several times zones with the same GMT offset that differ in the way they
141 * handle daylight savings time. For example, the state of Arizona doesn't observe daylight
142 * savings time. If you ask for the time zone IDs corresponding to GMT-7:00,
143 * you'll get back an enumeration over two time zone IDs: "America/Denver,"
144 * which corresponds to Mountain Standard Time in the winter and Mountain Daylight Time in the summer,
145 * and "America/Phoenix", which corresponds to Mountain Standard Time year-round, even in the summer.
147 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
149 * @param[in] raw_offset an offset from GMT in milliseconds, ignoring the effect of daylight savings time, if any
150 * @param[in] cb The callback function to get an enumeration object, owned by the caller.
151 * @param[in] user_data The user data to be passed to the callback function.
153 * @retval #I18N_ERROR_NONE Successful
155 int i18n_timezone_foreach_timezone_id_with_offset(int32_t raw_offset, i18n_timezone_id_cb cb, void* user_data);
158 * @brief Returns an enumeration over time zone IDs associated with the given country.
159 * @details Some zones are affiliated with no country (e.g., "UTC"); these may also be retrieved, as a group.
160 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
162 * @param[in] country The ISO 3166 two-letter country code, or NULL to retrieve zones not affiliated with any country.
163 * @param[in] cb The callback function to get an enumeration object, owned by the caller.
164 * @param[in] user_data The user data to be passed to the callback function.
166 * @retval #I18N_ERROR_NONE Successful
168 int i18n_timezone_foreach_timezone_id_by_country(const char *country, i18n_timezone_id_cb cb, void* user_data);
171 * @brief Returns the number of IDs in the equivalency group that includes the given ID.
172 * @details An equivalency group contains zones that have the same GMT offset and rules.\n
173 * The returned count includes the given ID; it is always >= 1. The given ID must be a system time zone. If it is not, returns zero.
174 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
176 * @param[in] timezone_id a system time zone ID
177 * @param[out] count the number of zones in the equivalency group containing 'timezone_id', or zero if 'timezone_id' is not a valid system ID
179 * @retval #I18N_ERROR_NONE Successful
180 * @see i18n_timezone_get_equivalent_id()
182 int i18n_timezone_count_equivalent_ids(const char *timezone_id, int32_t *count);
185 * @brief Returns an ID in the equivalency group that includes the given ID.
186 * @details An equivalency group contains zones that have the same GMT offset and rules.\n
187 * The given index must be in the range 0..n-1, where n is the out parameter value
188 * from i18n_timezone_count_equivalent_ids(timezone_id, &n).
189 * For some value of 'index', the returned value will be equal to the given id.
190 * If the given id is not a valid system time zone,
191 * or if 'index' is out of range, then returns an empty string.
192 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
194 * @param[in] timezone_id a system time zone ID
195 * @param[in] index a value from 0 to n-1, where n is the out parameter value from i18n_timezone_count_equivalent_ids(timezone_id, &n)
196 * @param[out] equivalent_timezone_id the ID of the index-th zone in the equivalency group containing 'timezone_id',
197 * or an empty string if 'timezone_id' is not a valid system ID or 'index' is out of range
199 * @retval #I18N_ERROR_NONE Successful
200 * @see i18n_timezone_count_equivalent_ids()
202 int i18n_timezone_get_equivalent_id(const char *timezone_id, int32_t index, char **equivalent_timezone_id);
205 * @brief Creates a new copy of the default i18n_timezone_h for this host.
206 * @details Unless the default time zone has already been set using #i18n_timezone_set_default(),
207 * the default is determined by querying the system using methods in TPlatformUtilities.
208 * If the system routines fail, or if they specify an i18n_timezone_h or i18n_timezone_h offset
209 * which is not recognized, the i18n_timezone_h indicated by the ID kLastResortID
210 * is instantiated and made the default.
211 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
213 * @param[out] timezone A default i18n_timezone_h. Clients are responsible for deleting the time zone object returned.
215 * @retval #I18N_ERROR_NONE Successful
217 int i18n_timezone_create_default ( i18n_timezone_h *timezone );
220 * @brief Sets the default time zone (i.e., what's returned by #i18n_timezone_create_default()) to be the specified time zone.
221 * @details If NULL is specified for the time zone, the default time zone is set to the default host time zone.
222 * The caller remains responsible for deleting it. \n
223 * This function is not thread safe. It is an error for multiple threads to concurrently attempt to set
224 * the default time zone, or for any thread to attempt to reference the default zone while another thread is setting it.
226 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
227 * @remarks Do not use unless you know what you are doing.
229 * @param[in] timezone The given timezone.
231 * @retval #I18N_ERROR_NONE Successful
233 int i18n_timezone_set_default( i18n_timezone_h timezone );
236 * @brief Returns the timezone data version currently used by I18N.
237 * @remarks The specific error code can be obtained using the get_last_result()
238 * method. Error codes are described in #i18n_error_code_e description.
239 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
241 * @return the version string, such as "2007f"
242 * @exception #I18N_ERROR_NONE Successful
244 const char* i18n_timezone_get_tzdata_version(void);
247 * @brief Gets the region code associated with the given system time zone ID.
248 * @details The region code is either ISO 3166 2-letter country code or UN M.49 3-digit area code.
249 * When the time zone is not associated with a specific location, for example - "Etc/UTC",
250 * "EST5EDT", then this method returns "001" (UN M.49 area code for World).
251 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
253 * @param[in] timezone_id The system time zone ID.
254 * @param[out] region Output buffer for receiving the region code.
255 * @param[out] region_len The length of the region code.
256 * @param[in] region_capacity The size of the output buffer. If it is lower than required @a region buffer size,
257 * then I18N_ERROR_BUFFER_OVERFLOW error is returned.
259 * @return the version string, such as "2007f"
261 int i18n_timezone_get_region(const char *timezone_id, char *region, int32_t *region_len, int32_t region_capacity);
264 * @brief Returns the time zone raw and GMT offset for the given moment in time.
265 * @details Upon return, local-millis = GMT-millis + rawOffset + dstOffset. All computations are performed
266 * in the proleptic Gregorian calendar.
267 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
269 * @param[in] timezone The i18n_timezone_h to get an offset.
270 * @param[in] date moment in time for which to return offsets, in units of milliseconds from January 1, 1970 0:00 GMT, either GMT time or local wall time, depending on `local'.
271 * @param[in] local output if true, `date' is local wall time; otherwise it is in GMT time.
272 * @param[out] raw_offset parameter to receive the raw offset, that is, the offset not including DST adjustments
273 * @param[out] dst_offset output parameter to receive the DST offset, that is, the offset to be added to `raw_offset' to obtain the total offset between local and GMT time. If DST is not in effect, this value is zero; otherwise it is a positive value, typically one hour.
275 * @retval #I18N_ERROR_NONE Successful
277 int i18n_timezone_get_offset_with_date(i18n_timezone_h timezone, i18n_udate date, i18n_ubool local, int32_t *raw_offset, int32_t *dst_offset);
280 * @brief Sets the i18n_timezone_h's raw GMT offset
281 * (i.e., the number of milliseconds to add to GMT to get local time, before taking daylight savings time into account).
282 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
284 * @param[in] timezone The i18n_timezone_h to set a raw offset.
285 * @param[in] offset_milliseconds The new raw GMT offset for this time zone.
287 * @retval #I18N_ERROR_NONE Successful
289 int i18n_timezone_set_raw_offset(i18n_timezone_h timezone, int32_t offset_milliseconds);
292 * @brief Gets the region code associated with the given system time zone ID.
293 * @details The region code is either ISO 3166 2-letter country code or UN M.49 3-digit area code. When the time zone is not associated with a specific location, for example - "Etc/UTC", "EST5EDT", then this method returns "001" (UN M.49 area code for World).
294 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
296 * @param[in] timezone The i18n_timezone_h to get a raw offset.
297 * @param[out] offset_milliseconds The i18n_timezone_h's raw GMT offset.
299 * @retval #I18N_ERROR_NONE Successful
301 int i18n_timezone_get_raw_offset(i18n_timezone_h timezone, int32_t *offset_milliseconds);
304 * @brief Fills in "timezone_id" with the i18n_timezone_h's ID.
305 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
307 * @param[in] timezone The i18n_timezone_h to get a timezone ID.
308 * @param[out] timezone_id Receives this i18n_timezone_h's ID.
310 * @retval #I18N_ERROR_NONE Successful
312 int i18n_timezone_get_id(i18n_timezone_h timezone, char **timezone_id);
315 * @brief Sets the i18n_timezone_h's ID to the specified value.
316 * @details This doesn't affect any other fields. for example,\n
318 * i18n_timezone_h timezone = NULL;\n
319 * i18n_timezone_create ( &timezone, "America/New_York" );\n
320 * i18n_timezone_set_id ( "America/Los_Angeles" );\n
322 * the timezone's GMT offset and daylight-savings rules don't change to those for Los Angeles.
323 * They're still those for New York. Only the ID has changed.
324 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
326 * @param[in] timezone The i18n_timezone_h to set a timezone ID.
327 * @param[in] timezone_id The new time zone ID.
329 * @retval #I18N_ERROR_NONE Successful
331 int i18n_timezone_set_id(i18n_timezone_h timezone, const char *timezone_id);
334 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
335 * @details This method returns the long name, not including daylight savings.
336 * If the display name is not available for the locale, then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm.
337 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
339 * @param[in] timezone The i18n_timezone_h to get a display name.
340 * @param[out] display_name The human-readable name of this time zone in the default locale.
342 * @retval #I18N_ERROR_NONE Successful
344 int i18n_timezone_get_display_name(i18n_timezone_h timezone, char **display_name);
347 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
348 * @details This method returns the long name, not including daylight savings.
349 * If the display name is not available for the locale, then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm.
350 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
352 * @param[in] timezone The i18n_timezone_h to get a display name.
353 * @param[in] language The language in which to supply the display name. This parameter can be NULL; if so, the locale is initialized to match the current default locale.
354 * @param[in] country The country in which to supply the display name. This parameter can be NULL.
355 * @param[out] display_name The human-readable name of this time zone in the default locale.
357 * @retval #I18N_ERROR_NONE Successful
359 int i18n_timezone_get_display_name_with_locale(i18n_timezone_h timezone, const char *language, const char *country , char **display_name);
362 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
363 * @details If the display name is not available for the locale,
364 * then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm.
365 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
367 * @param[in] timezone The i18n_timezone_h to get a display name.
368 * @param[in] daylight If true, display_name is filled with the daylight savings name.
369 * @param[in] style The style displayed on.
370 * @param[out] display_name The human-readable name of this time zone in the default locale.
372 * @retval #I18N_ERROR_NONE Successful
374 int i18n_timezone_get_display_name_with_type(i18n_timezone_h timezone, i18n_ubool daylight, i18n_timezone_display_type_e style, char **display_name);
377 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
378 * @details If the display name is not available for the locale,
379 * then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm.
380 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
382 * @param[in] timezone The i18n_timezone_h to get a display name.
383 * @param[in] daylight If true, display_name is filled with the daylight savings name.
384 * @param[in] style The style displayed on.
385 * @param[in] language The language in which to supply the display name. This parameter can be NULL; if so, the locale is initialized to match the current default locale.
386 * @param[in] country The country in which to supply the display name. This parameter can be NULL.
387 * @param[out] display_name The human-readable name of this time zone in the default locale.
389 * @retval #I18N_ERROR_NONE Successful
391 int i18n_timezone_get_display_name_with_type_locale(i18n_timezone_h timezone, i18n_ubool daylight, i18n_timezone_display_type_e style, const char *language, const char *country, char **display_name);
394 * @brief Queries if this time zone uses daylight savings time.
395 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
397 * @param[in] timezone The i18n_timezone_h to know whether uses daylight savings time or not.
398 * @param[out] daylight_time True if this time zone uses daylight savings time, False, otherwise.
400 * @retval #I18N_ERROR_NONE Successful
402 int i18n_timezone_use_daylight_time(i18n_timezone_h timezone, i18n_ubool *daylight_time);
405 * @brief Queries if the given date is in daylight savings time in this time zone.
406 * @details This method is wasteful since it creates a new GregorianCalendar and deletes it each time it is called.
409 * @deprecated Deprecated since 2.3.1. Use i18n_ucalendar_is_in_daylight_time() instead.
411 * @param[in] timezone The i18n_timezone_h to know whether in daylight savings time or not.
412 * @param[in] date the given i18n_udate.
413 * @param[out] daylight_time True if the given date is in daylight savings time, False, otherwise.
415 * @retval #I18N_ERROR_NONE Successful
417 int i18n_timezone_in_daylight_time(i18n_timezone_h timezone, i18n_udate date, i18n_ubool *daylight_time);
420 * @brief Returns true if this zone has the same rule and offset as another zone.
421 * @details That is, if this zone differs only in ID, if at all.
422 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
424 * @param[in] timezone The i18n_timezone_h to know whether has the same rule or not.
425 * @param[in] other The i18n_timezone_h to be compared with.
426 * @param[out] same_rule True if the given zone is the same as this one, with the possible exception of the ID.
428 * @retval #I18N_ERROR_NONE Successful
430 int i18n_timezone_has_same_rule(i18n_timezone_h timezone, i18n_timezone_h other, i18n_ubool *same_rule);
433 * @brief Clones i18n_timezone_h polymorphically.
434 * @details Clients are responsible for deleting the i18n_timezone_h cloned.
435 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
437 * @param[in] timezone The i18n_timezone_h to clone.
438 * @param[out] clone A new copy of this i18n_timezone_h.
440 * @retval #I18N_ERROR_NONE Successful
442 int i18n_timezone_clone(i18n_timezone_h timezone, i18n_timezone_h *clone);
445 * @brief Returns the amount of time to be added to local standard time to get local wall clock time.
446 * @details The default implementation always returns 3600000 milliseconds (i.e., one hour) if this time zone observes Daylight Saving Time.
447 * Otherwise, 0 (zero) is returned.\n
448 * If an underlying TimeZone implementation subclass supports historical Daylight Saving Time changes,
449 * this method returns the known latest daylight saving value.
450 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
452 * @param[in] timezone The i18n_timezone_h to get DST savings.
453 * @param[out] dst_savings The amount of saving time in milliseconds.
455 * @retval #I18N_ERROR_NONE Successful
457 int i18n_timezone_get_dst_savings(i18n_timezone_h timezone, int32_t *dst_savings);
467 #endif /* __UTILS_I18N_TIMEZONE_H__*/