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.
212 * This function determines the default timezone by querying the system once and storing the
213 * obtained timezone as default until the application terminates.
215 * To query the system for the current timezone, use i18n_timezone_detect_host_timezone().
217 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
219 * @param[out] timezone A default i18n_timezone_h. Clients are responsible for deleting the time zone object returned.
221 * @retval #I18N_ERROR_NONE Successful
223 int i18n_timezone_create_default(i18n_timezone_h *timezone);
226 * @brief Sets the default time zone (i.e., what's returned by #i18n_timezone_create_default()) to be the specified time zone.
227 * @details If NULL is specified for the time zone, the default time zone is set to the default host time zone.
228 * The caller remains responsible for deleting it. \n
229 * This function is not thread safe. It is an error for multiple threads to concurrently attempt to set
230 * the default time zone, or for any thread to attempt to reference the default zone while another thread is setting it.
232 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
233 * @remarks Do not use unless you know what you are doing.
235 * @param[in] timezone The given timezone.
237 * @retval #I18N_ERROR_NONE Successful
239 int i18n_timezone_set_default(i18n_timezone_h timezone);
242 * @brief Returns the timezone data version currently used by I18N.
243 * @remarks The specific error code can be obtained using the get_last_result()
244 * method. Error codes are described in #i18n_error_code_e description.
245 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
247 * @return the version string, such as "2007f"
248 * @exception #I18N_ERROR_NONE Successful
250 const char *i18n_timezone_get_tzdata_version(void);
253 * @brief Gets the region code associated with the given system time zone ID.
254 * @details The region code is either ISO 3166 2-letter country code or UN M.49 3-digit area code.
255 * When the time zone is not associated with a specific location, for example - "Etc/UTC",
256 * "EST5EDT", then this method returns "001" (UN M.49 area code for World).
257 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
259 * @param[in] timezone_id The system time zone ID.
260 * @param[out] region Output buffer for receiving the region code.
261 * @param[out] region_len The length of the region code.
262 * @param[in] region_capacity The size of the output buffer. If it is lower than required @a region buffer size,
263 * then I18N_ERROR_BUFFER_OVERFLOW error is returned.
265 * @return the version string, such as "2007f"
267 int i18n_timezone_get_region(const char *timezone_id, char *region, int32_t *region_len, int32_t region_capacity);
270 * @brief Returns the time zone raw and GMT offset for the given moment in time.
271 * @details Upon return, local-millis = GMT-millis + rawOffset + dstOffset. All computations are performed
272 * in the proleptic Gregorian calendar.
273 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
275 * @param[in] timezone The i18n_timezone_h to get an offset.
276 * @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'.
277 * @param[in] local output if true, `date' is local wall time; otherwise it is in GMT time.
278 * @param[out] raw_offset parameter to receive the raw offset, that is, the offset not including DST adjustments
279 * @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.
281 * @retval #I18N_ERROR_NONE Successful
283 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);
286 * @brief Sets the i18n_timezone_h's raw GMT offset
287 * (i.e., the number of milliseconds to add to GMT to get local time, before taking daylight savings time into account).
288 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
290 * @param[in] timezone The i18n_timezone_h to set a raw offset.
291 * @param[in] offset_milliseconds The new raw GMT offset for this time zone.
293 * @retval #I18N_ERROR_NONE Successful
295 int i18n_timezone_set_raw_offset(i18n_timezone_h timezone, int32_t offset_milliseconds);
298 * @brief Gets the i18n_timezone_h's raw GMT offset (i.e., the number of milliseconds
299 * to add to GMT to get local time, before taking daylight savings time into account).
300 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
302 * @param[in] timezone The i18n_timezone_h to get a raw offset.
303 * @param[out] offset_milliseconds The i18n_timezone_h's raw GMT offset.
305 * @retval #I18N_ERROR_NONE Successful
307 int i18n_timezone_get_raw_offset(i18n_timezone_h timezone, int32_t *offset_milliseconds);
310 * @brief Fills in "timezone_id" with the i18n_timezone_h's ID.
311 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
313 * @param[in] timezone The i18n_timezone_h to get a timezone ID.
314 * @param[out] timezone_id Receives this i18n_timezone_h's ID.
316 * @retval #I18N_ERROR_NONE Successful
318 int i18n_timezone_get_id(i18n_timezone_h timezone, char **timezone_id);
321 * @brief Sets the i18n_timezone_h's ID to the specified value.
322 * @details This doesn't affect any other fields. for example,\n
324 * i18n_timezone_h timezone = NULL;\n
325 * i18n_timezone_create ( &timezone, "America/New_York" );\n
326 * i18n_timezone_set_id ( "America/Los_Angeles" );\n
328 * the timezone's GMT offset and daylight-savings rules don't change to those for Los Angeles.
329 * They're still those for New York. Only the ID has changed.
330 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
332 * @param[in] timezone The i18n_timezone_h to set a timezone ID.
333 * @param[in] timezone_id The new time zone ID.
335 * @retval #I18N_ERROR_NONE Successful
337 int i18n_timezone_set_id(i18n_timezone_h timezone, const char *timezone_id);
340 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
341 * @details This method returns the long name, not including daylight savings.
342 * 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.
343 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
345 * @param[in] timezone The i18n_timezone_h to get a display name.
346 * @param[out] display_name The human-readable name of this time zone in the default locale.
348 * @retval #I18N_ERROR_NONE Successful
350 int i18n_timezone_get_display_name(i18n_timezone_h timezone, char **display_name);
353 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
354 * @details This method returns the long name, not including daylight savings.
355 * 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.
356 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
358 * @param[in] timezone The i18n_timezone_h to get a display name.
359 * @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.
360 * @param[in] country The country in which to supply the display name. This parameter can be NULL.
361 * @param[out] display_name The human-readable name of this time zone in the default locale.
363 * @retval #I18N_ERROR_NONE Successful
365 int i18n_timezone_get_display_name_with_locale(i18n_timezone_h timezone, const char *language, const char *country , char **display_name);
368 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
369 * @details If the display name is not available for the locale,
370 * then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm.
371 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
373 * @param[in] timezone The i18n_timezone_h to get a display name.
374 * @param[in] daylight If true, display_name is filled with the daylight savings name.
375 * @param[in] style The style displayed on.
376 * @param[out] display_name The human-readable name of this time zone in the default locale.
378 * @retval #I18N_ERROR_NONE Successful
380 int i18n_timezone_get_display_name_with_type(i18n_timezone_h timezone, i18n_ubool daylight, i18n_timezone_display_type_e style, char **display_name);
383 * @brief Returns a name of this time zone suitable for presentation to the user in the default locale.
384 * @details If the display name is not available for the locale,
385 * then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm.
386 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
388 * @param[in] timezone The i18n_timezone_h to get a display name.
389 * @param[in] daylight If true, display_name is filled with the daylight savings name.
390 * @param[in] style The style displayed on.
391 * @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.
392 * @param[in] country The country in which to supply the display name. This parameter can be NULL.
393 * @param[out] display_name The human-readable name of this time zone in the default locale.
395 * @retval #I18N_ERROR_NONE Successful
397 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);
400 * @brief Queries if this time zone uses daylight savings time.
401 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
403 * @param[in] timezone The i18n_timezone_h to know whether uses daylight savings time or not.
404 * @param[out] daylight_time True if this time zone uses daylight savings time, False, otherwise.
406 * @retval #I18N_ERROR_NONE Successful
408 int i18n_timezone_use_daylight_time(i18n_timezone_h timezone, i18n_ubool *daylight_time);
411 * @brief Returns true if this zone has the same rule and offset as another zone.
412 * @details That is, if this zone differs only in ID, if at all.
413 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
415 * @param[in] timezone The i18n_timezone_h to know whether has the same rule or not.
416 * @param[in] other The i18n_timezone_h to be compared with.
417 * @param[out] same_rule True if the given zone is the same as this one, with the possible exception of the ID.
419 * @retval #I18N_ERROR_NONE Successful
421 int i18n_timezone_has_same_rule(i18n_timezone_h timezone, i18n_timezone_h other, i18n_ubool *same_rule);
424 * @brief Clones i18n_timezone_h polymorphically.
425 * @details Clients are responsible for deleting the i18n_timezone_h cloned.
426 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
428 * @param[in] timezone The i18n_timezone_h to clone.
429 * @param[out] clone A new copy of this i18n_timezone_h.
431 * @retval #I18N_ERROR_NONE Successful
433 int i18n_timezone_clone(i18n_timezone_h timezone, i18n_timezone_h *clone);
436 * @brief Returns the amount of time to be added to local standard time to get local wall clock time.
437 * @details The default implementation always returns 3600000 milliseconds (i.e., one hour) if this time zone observes Daylight Saving Time.
438 * Otherwise, 0 (zero) is returned.\n
439 * If an underlying TimeZone implementation subclass supports historical Daylight Saving Time changes,
440 * this method returns the known latest daylight saving value.
441 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
443 * @param[in] timezone The i18n_timezone_h to get DST savings.
444 * @param[out] dst_savings The amount of saving time in milliseconds.
446 * @retval #I18N_ERROR_NONE Successful
448 int i18n_timezone_get_dst_savings(i18n_timezone_h timezone, int32_t *dst_savings);
451 * @brief Creates an #i18n_timezone_h detected from the current host system configuration.
452 * @details This function does not change the default time zone and does not update the current
453 * ICU's default. It may return a different #i18n_timezone_h from the one returned by
454 * i18n_timezone_create_default().
457 * @param[out] timezone A new instance of #i18n_timezone_h detected from the current host system
458 * configuration. Users are responsible for deleting the returned time zone object with
459 * i18n_timezone_destroy().
461 * @retval #I18N_ERROR_NONE Successful
462 * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter
464 int i18n_timezone_detect_host_timezone(i18n_timezone_h *timezone);
474 #endif /* __UTILS_I18N_TIMEZONE_H__*/