BDE 4.14.0 Production release
|
Provide a concrete baltzo::Loader
for Zoneinfo binary files.
baltzo::Loader
for Zoneinfo binary dataThis component provides a mechanism, baltzo::DataFileLoader
, that is a concrete implementation of the baltzo::Loader
protocol for loading, into a baltzo::Zoneinfo
object, the properties of a time zone described in a Zoneinfo binary database file. The following inheritance hierarchy diagram shows the classes involved and their methods:
A baltzo::DataFileLoader
is supplied a file-system location using the configureRootPath
method. This location should correspond to the root directory of a hierarchy containing Zoneinfo binary data files, where each Zoneinfo time-zone identifier indicates a relative path from the root directory to the binary data file containing the information for that time zone. Accordingly, baltzo::DataFileLoader
provides a method that, given a time-zone identifier, will open the corresponding data file (relative to the root directory tree supplied at construction), and load, into a baltzo::Zoneinfo
object, the data from that file.
The Zoneinfo database, also referred to as either the TZ database or the Olson database (after its creator, Arthur Olson), is a standard public-domain time-zone information distribution used by many software systems (including a number of Unix variants and the Java Runtime Environment). Information about the Zoneinfo database can be found online at http://www.twinsun.com/tz/tz-link.htm
, including the time-zone rules for the supported time zones, and source code for the zic
compiler (for compiling those rules into the binary representation used by this component). See baltzo_zoneinfobinaryreader for more information about the binary file format.
Zoneinfo database files are typically held in a standard file-system directory hierarchy. Zoneinfo time-zone identifiers (e.g., "America/New_York") serve not only as an identifier, but as a relative path (using the UNIX file separator, /
) to the file containing data for the time zone. So, given a hypothetical root directory "/etc/time_zones", the time-zone data file for "America/New_York" will be located in "/etc/time_zones/America/New_York".
baltzo::DataFileLoader
is const thread-safe, meaning that accessors may be invoked concurrently from different threads, but it is not safe to access or modify a baltzo::DataFileLoader
in one thread while another thread modifies the same object.
The following examples illustrate how to use a baltzo::DataFileLoader
to load the Zoneinfo time-zone data for a time zone.
First we need to create one time-zone data file on which to operate. In practice, clients should not generate data files in this manner. Data files are typically created using the zic
compiler – a publicly available tool provided as part of the standard Zoneinfo distribution (see http://www.twinsun.com/tz/tz-link.htm
) – and deployed in a standard directory location (see baltzo_defaultzoneinfocache ).
We start by defining static binary data for "Asia/Bangkok", (chosen because it is relatively small):
Then we create a testing sub-directory "test/Asia" that will hold the data file for Bangkok. Note that "Asia/Bangkok" is the time-zone identifier for Bangkok and "Asia/Bangkok" also serves as a relative path (from our "./test" sub-directory) to that data file.
Now we create a file for Bangkok and write the binary time-zone data to that file.
The file Bangkok
should now appear in the Asia
sub-directory, under out test
directory.
In this example we demonstrate how to use a baltzo::DataFileLoader
to load a time-zone data file into a baltzo::Zoneinfo
object. We start by creating a baltzo::DataFileLoader
object, loader
, and configure it with the relative path "test" which we created in Example 1 (Prologue).
Then we use the loadTimeZoneFilePath
method to verify that loader
will correctly locate the test data file we've created:
Now we create a baltzo::Zoneinfo
object, timeZone
, and load it using loader
:
Finally we confirm that certain properties of the timezone
object are in agreement with the properties defined in the binary data (see baltzo_zoneinfobinaryreader ): (1) That the object's identifier is "Asia/Bangkok", and (2) the object contains three local time descriptors, "LMT" (Local Mean Time), "BMT" (Bangkok Mean Time) and "ICT" (Indochina Time), in that order:
The timeZone
object can now be use for time-zone calculations. See baltzo_zoneinfoutil .
The file hierarchy we created Example 1 solely for Example 2, is no longer needed, and is removed by: