BDE 4.14.0 Production release
Loading...
Searching...
No Matches
baltzo_windowstimezoneutil.h
Go to the documentation of this file.
1/// @file baltzo_windowstimezoneutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// baltzo_windowstimezoneutil.h -*-C++-*-
8#ifndef INCLUDED_BALTZO_WINDOWSTIMEZONEUTIL
9#define INCLUDED_BALTZO_WINDOWSTIMEZONEUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup baltzo_windowstimezoneutil baltzo_windowstimezoneutil
15/// @brief Provide utilities to map Zoneinfo identifiers to other systems.
16/// @addtogroup bal
17/// @{
18/// @addtogroup baltzo
19/// @{
20/// @addtogroup baltzo_windowstimezoneutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#baltzo_windowstimezoneutil-purpose"> Purpose</a>
25/// * <a href="#baltzo_windowstimezoneutil-classes"> Classes </a>
26/// * <a href="#baltzo_windowstimezoneutil-description"> Description </a>
27/// * <a href="#baltzo_windowstimezoneutil-windows-time-zone-identifiers"> Windows Time-Zone Identifiers </a>
28/// * <a href="#baltzo_windowstimezoneutil-differences-from-cldr"> Differences from CLDR </a>
29/// * <a href="#baltzo_windowstimezoneutil-usage"> Usage </a>
30/// * <a href="#baltzo_windowstimezoneutil-example-1-converting-between-windows-and-zoneinfo-time-zone-identifiers"> Example 1: Converting Between Windows and Zoneinfo Time-Zone Identifiers </a>
31/// * <a href="#baltzo_windowstimezoneutil-example-2-creating-a-baltzo-localdatetime-object-on-windows"> Example 2: Creating a baltzo::LocalDatetime Object on Windows </a>
32///
33/// # Purpose {#baltzo_windowstimezoneutil-purpose}
34/// Provide utilities to map Zoneinfo identifiers to other systems.
35///
36/// # Classes {#baltzo_windowstimezoneutil-classes}
37///
38/// - baltzo::WindowsTimeZoneUtil: utilities for mapping Zoneinfo time-zone ids
39///
40/// @see bsitzo_tzdftimezoneutil
41///
42/// # Description {#baltzo_windowstimezoneutil-description}
43/// This component provides a namespace,
44/// `baltzo::WindowsTimeZoneUtil`, containing utility functions supporting the
45/// use of Windows time-zone facilities with `baltzo` facilities. Currently,
46/// this component provides functions that map Windows time-zone identifiers to
47/// and from `baltzo` (Zoneinfo) time-zone identifiers.
48///
49/// ## Windows Time-Zone Identifiers {#baltzo_windowstimezoneutil-windows-time-zone-identifiers}
50///
51///
52/// The mapping from Windows to Zoneinfo identifiers used by the `baltzo`
53/// package is defined in the table titled "Mapping for: windows" at
54/// `http://unicode.org/cldr/charts/32/supplemental/zone_tzid.html` (with any
55/// differences noted in the section {Differences from CLDR} below). The
56/// Zoneinfo values on the unicode webpage are given in the column labeled
57/// "TZID". Each Windows identifier is qualified by one or more "Region"
58/// attributes so, in general, there may be more than one Zoneinfo identifier
59/// for a given Windows identifier. The mapping in this component uses the
60/// default mapping (Region "001"). The 99 entries are:
61/// @code
62/// +--------------------------------+---------------------+
63/// |Windows Identifier | Zoneinfo Identifier |
64/// +--------------------------------+---------------------+
65/// | AUS Central Standard Time | Australia/Darwin |
66/// | AUS Eastern Standard Time | Australia/Sydney |
67/// | Afghanistan Standard Time | Asia/Kabul |
68/// | Alaskan Standard Time | America/Anchorage |
69/// | Arab Standard Time | Asia/Riyadh |
70/// | Arabian Standard Time | Asia/Dubai |
71/// | Arabic Standard Time | Asia/Baghdad |
72/// | Argentina Standard Time | America/Buenos_Aires|
73/// | Atlantic Standard Time | America/Halifax |
74/// | Azerbaijan Standard Time | Asia/Baku |
75/// | Azores Standard Time | Atlantic/Azores |
76/// | Bahia Standard Time | America/Bahia |
77/// | Bangladesh Standard Time | Asia/Dhaka |
78/// | Canada Central Standard Time | America/Regina |
79/// | Cape Verde Standard Time | Atlantic/Cape_Verde |
80/// | Caucasus Standard Time | Asia/Yerevan |
81/// | Cen. Australia Standard Time | Australia/Adelaide |
82/// | Central America Standard Time | America/Guatemala |
83/// | Central Asia Standard Time | Asia/Almaty |
84/// |Central Brazilian Standard Time | America/Cuiaba |
85/// | Central Europe Standard Time | Europe/Budapest |
86/// | Central European Standard Time | Europe/Warsaw |
87/// | Central Pacific Standard Time | Pacific/Guadalcanal |
88/// | Central Standard Time | America/Chicago |
89/// | Central Standard Time (Mexico) | America/Mexico_City |
90/// | China Standard Time | Asia/Shanghai |
91/// | Dateline Standard Time | Etc/GMT+12 |
92/// | E. Africa Standard Time | Africa/Nairobi |
93/// | E. Australia Standard Time | Australia/Brisbane |
94/// | E. Europe Standard Time | Asia/Nicosia |
95/// | E. South America Standard Time | America/Sao_Paulo |
96/// | Eastern Standard Time | America/New_York |
97/// | Egypt Standard Time | Africa/Cairo |
98/// | Ekaterinburg Standard Time | Asia/Yekaterinburg |
99/// | FLE Standard Time | Europe/Kiev |
100/// | Fiji Standard Time | Pacific/Fiji |
101/// | GMT Standard Time | Europe/London |
102/// | GTB Standard Time | Europe/Bucharest |
103/// | Georgian Standard Time | Asia/Tbilisi |
104/// | Greenland Standard Time | America/Godthab |
105/// | Greenwich Standard Time | Atlantic/Reykjavik |
106/// | Hawaiian Standard Time | Pacific/Honolulu |
107/// | India Standard Time | Asia/Kolkata |
108/// | Iran Standard Time | Asia/Tehran |
109/// | Israel Standard Time | Asia/Jerusalem |
110/// | Jordan Standard Time | Asia/Amman |
111/// | Kaliningrad Standard Time | Europe/Kaliningrad |
112/// | Korea Standard Time | Asia/Seoul |
113/// | Magadan Standard Time | Asia/Magadan |
114/// | Mauritius Standard Time | Indian/Mauritius |
115/// | Middle East Standard Time | Asia/Beirut |
116/// | Montevideo Standard Time | America/Montevideo |
117/// | Morocco Standard Time | Africa/Casablanca |
118/// | Mountain Standard Time | America/Denver |
119/// |Mountain Standard Time (Mexico) | America/Chihuahua |
120/// | Myanmar Standard Time | Asia/Rangoon |
121/// | N. Central Asia Standard Time | Asia/Novosibirsk |
122/// | Namibia Standard Time | Africa/Windhoek |
123/// | Nepal Standard Time | Asia/Katmandu |
124/// | New Zealand Standard Time | Pacific/Auckland |
125/// | Newfoundland Standard Time | America/St_Johns |
126/// | North Asia East Standard Time | Asia/Irkutsk |
127/// | North Asia Standard Time | Asia/Krasnoyarsk |
128/// | Pacific SA Standard Time | America/Santiago |
129/// | Pacific Standard Time | America/Los_Angeles |
130/// | Pacific Standard Time (Mexico) | America/Santa_Isabel|
131/// | Pakistan Standard Time | Asia/Karachi |
132/// | Paraguay Standard Time | America/Asuncion |
133/// | Romance Standard Time | Europe/Paris |
134/// | Russian Standard Time | Europe/Moscow |
135/// | SA Eastern Standard Time | America/Cayenne |
136/// | SA Pacific Standard Time | America/Bogota |
137/// | SA Western Standard Time | America/La_Paz |
138/// | SE Asia Standard Time | Asia/Bangkok |
139/// | Samoa Standard Time | Pacific/Apia |
140/// | Singapore Standard Time | Asia/Singapore |
141/// | South Africa Standard Time | Africa/Johannesburg |
142/// | Sri Lanka Standard Time | Asia/Colombo |
143/// | Syria Standard Time | Asia/Damascus |
144/// | Taipei Standard Time | Asia/Taipei |
145/// | Tasmania Standard Time | Australia/Hobart |
146/// | Tokyo Standard Time | Asia/Tokyo |
147/// | Tonga Standard Time | Pacific/Tongatapu |
148/// | Turkey Standard Time | Europe/Istanbul |
149/// | US Eastern Standard Time | America/Indianapolis|
150/// | US Mountain Standard Time | America/Phoenix |
151/// | UTC | Etc/GMT |
152/// | UTC+12 | Etc/GMT-12 |
153/// | UTC-02 | Etc/GMT+2 |
154/// | UTC-11 | Etc/GMT+11 |
155/// | Ulaanbaatar Standard Time | Asia/Ulaanbaatar |
156/// | Venezuela Standard Time | America/Caracas |
157/// | Vladivostok Standard Time | Asia/Vladivostok |
158/// | W. Australia Standard Time | Australia/Perth |
159/// |W. Central Africa Standard Time | Africa/Lagos |
160/// | W. Europe Standard Time | Europe/Berlin |
161/// | West Asia Standard Time | Asia/Tashkent |
162/// | West Pacific Standard Time | Pacific/Port_Moresby|
163/// | Yakutsk Standard Time | Asia/Yakutsk |
164/// +--------------------------------+---------------------+
165/// @endcode
166///
167/// ## Differences from CLDR {#baltzo_windowstimezoneutil-differences-from-cldr}
168///
169///
170/// Current differences from canonical CLDR data:
171/// * "Asia/Calcutta" -> "Asia/Kolkata". The city was renamed, and the IANA
172/// time zone identifier changed in 1993 but CLDR incorrectly uses the old
173/// name for the city. There is an open issue for this:
174/// `https://unicode-org.atlassian.net/browse/CLDR-9892`.
175///
176/// ## Usage {#baltzo_windowstimezoneutil-usage}
177///
178///
179/// In this section we show intended use of this component.
180///
181/// ### Example 1: Converting Between Windows and Zoneinfo Time-Zone Identifiers {#baltzo_windowstimezoneutil-example-1-converting-between-windows-and-zoneinfo-time-zone-identifiers}
182///
183///
184/// This example shows how to find the Zoneinfo time-zone time-zone identifier
185/// for a given Windows time-zone identifier, and the inverse operation.
186///
187/// First, given the "Central Standard Time (Mexico)" Windows time-zone
188/// identifier, use the `getZoneinfoId` method to find the corresponding
189/// Zoneinfo time-zone identifier.
190/// @code
191/// int rc;
192/// const char *timeZoneId;
193/// const char *windowsTimeZoneId;
194///
195/// rc = baltzo::WindowsTimeZoneUtil::getZoneinfoId(
196/// &timeZoneId,
197/// "Central Standard Time (Mexico)");
198/// assert(0 == rc);
199/// assert(0 == bsl::strcmp("America/Mexico_City", timeZoneId));
200/// @endcode
201/// Notice that the corresponding Zoneinfo time-zone identifier is
202/// "America/Mexico_City".
203///
204/// Next, use `getWindowsTimeZoneId` method to find the Windows time-zone
205/// identifier corresponding to "America/Mexico_City".
206/// @code
207/// rc = baltzo::WindowsTimeZoneUtil::getWindowsTimeZoneId(
208/// &windowsTimeZoneId,
209/// "America/Mexico_City");
210/// assert(0 == rc);
211/// assert(0 == bsl::strcmp("Central Standard Time (Mexico)",
212/// windowsTimeZoneId));
213/// @endcode
214/// Notice that the time zone returned is "Central Standard Time (Mexico)", the
215/// original time-zone identifier.
216///
217/// ### Example 2: Creating a baltzo::LocalDatetime Object on Windows {#baltzo_windowstimezoneutil-example-2-creating-a-baltzo-localdatetime-object-on-windows}
218///
219///
220/// The following example demonstrates how to create on a Windows platform a
221/// `baltzo::LocalDatetime` object with the value of the current time.
222///
223/// First, use the Windows `GetTimeZoneInformation` function to load a
224/// `TIME_ZONE_INFORMATION` structure.
225/// @code
226/// int rc;
227/// TIME_ZONE_INFORMATION tzi;
228/// rc = GetTimeZoneInformation(&tzi);
229/// assert(TIME_ZONE_ID_UNKNOWN == rc
230/// || TIME_ZONE_ID_STANDARD == rc
231/// || TIME_ZONE_ID_DAYLIGHT == rc);
232/// @endcode
233/// The `StandardName` member of the structure, of type `WCHAR[32]`, contains
234/// the Windows time-zone identifier for Standard Time for the system's local
235/// time zone.
236///
237/// Next, use the `wcstombs_s` function to convert the wide string in the
238/// `StandardName` member to its multi-byte equivalent in the `standardName`
239/// buffer, and assign the result to `localTimezone`. Note that every Windows
240/// time-zone identifier mapped by this component consists entirely of 7-bit
241/// ASCII characters.
242/// @code
243/// bsl::string localTimezone;
244///
245/// {
246/// // Convert 'StandardName' field ('WCHAR[32]') to 'bsl::string'.
247///
248/// char standardName[sizeof(tzi.StandardName) * 2 + 1] = { '\0' };
249/// errno_t error = wcstombs_s(NULL,
250/// standardName,
251/// sizeof(standardName),
252/// tzi.StandardName,
253/// _TRUNCATE);
254/// assert(0 == errno);
255/// localTimezone.assign(standardName);
256/// }
257/// assert("Arab Standard Time" == localTimezone);
258/// @endcode
259/// Now, use the `getZoneinfoId` method to find the corresponding Zoneinfo
260/// time-zone identifier.
261/// @code
262/// const char *zoneinfoId;
263/// rc = baltzo::WindowsTimeZoneUtil::getZoneinfoId(&zoneinfoId,
264/// localTimezone.c_str());
265/// assert(0 == rc);
266/// assert(0 == bsl::strcmp("Asia/Riyadh", zoneinfoId));
267/// @endcode
268/// Then, use the Windows `GetSystemTime` function to load an `SYSTEMTIME`
269/// structure with UTC time information. The returned information includes
270/// year, month (`[1 .. 12]`), day-of-month (`[1 .. 31]`), and hour-of-day
271/// (`[0 .. 23]`). Note @ref bdlt_date and @ref bdlt_time use the same numerical
272/// values to represent month, day, etc. The range of years is different but
273/// practically the same as they overlap for several centuries around the
274/// current time.
275/// @code
276/// SYSTEMTIME systemTime;
277/// GetSystemTime(&systemTime);
278/// @endcode
279/// Finally, use these Windows SystemTime values and the calculated Zoneinfo
280/// time-zone identifier to set the value of a `baltzo::LocalDatetime` object.
281/// @code
282/// baltzo::LocalDatetime localDatetime;
283///
284/// rc = baltzo::TimeZoneUtil::convertUtcToLocalTime(
285/// &localDatetime,
286/// zoneinfoId,
287/// bdlt::Datetime(systemTime.wYear,
288/// systemTime.wMonth,
289/// systemTime.wDay,
290/// systemTime.wHour));
291/// assert(0 == rc);
292/// assert("Asia/Riyadh" == localDatetime.timeZoneId());
293/// @endcode
294/// @}
295/** @} */
296/** @} */
297
298/** @addtogroup bal
299 * @{
300 */
301/** @addtogroup baltzo
302 * @{
303 */
304/** @addtogroup baltzo_windowstimezoneutil
305 * @{
306 */
307
308#include <balscm_version.h>
309
310
311namespace baltzo {
312 // ==========================
313 // struct WindowsTimeZoneUtil
314 // ==========================
315
316/// This `struct` provides a namespace for utility functions that convert
317/// Zoneinfo time-zone identifiers both to and Windows time-zone
318/// identifiers.
320
321 // CLASS METHODS
322
323 /// Load into the specified `result` the address of a 0 terminated
324 /// C-string containing the default Zoneinfo time-zone identifier for
325 /// the specified `windowsTimeZoneId`. Return 0 on success, and
326 /// non-zero value with no other effect otherwise. The returned address
327 /// is valid for the life-time of the process.
328 static int getZoneinfoId(const char **result,
329 const char *windowsTimeZoneId);
330
331 /// Load into the specified `result` the address of a 0 terminated
332 /// C-string containing the Windows time-zone identifier for the
333 /// specified `zoneinfoId`. Return 0 on success, and non-zero value
334 /// with no other effect otherwise. The returned address is valid for
335 /// the life-time of the process.
336 static int getWindowsTimeZoneId(const char **result,
337 const char *zoneinfoId);
338};
339
340} // close package namespace
341
342
343#endif
344
345// ----------------------------------------------------------------------------
346// Copyright 2015 Bloomberg Finance L.P.
347//
348// Licensed under the Apache License, Version 2.0 (the "License");
349// you may not use this file except in compliance with the License.
350// You may obtain a copy of the License at
351//
352// http://www.apache.org/licenses/LICENSE-2.0
353//
354// Unless required by applicable law or agreed to in writing, software
355// distributed under the License is distributed on an "AS IS" BASIS,
356// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
357// See the License for the specific language governing permissions and
358// limitations under the License.
359// ----------------------------- END-OF-FILE ----------------------------------
360
361/** @} */
362/** @} */
363/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition baltzo_datafileloader.h:263
Definition baltzo_windowstimezoneutil.h:319
static int getZoneinfoId(const char **result, const char *windowsTimeZoneId)
static int getWindowsTimeZoneId(const char **result, const char *zoneinfoId)