BDE 4.14.0 Production release
|
Provide a protocol for obtaining information about a time zone.
This component provides a protocol, baltzo::Loader
, for obtaining information about a time zone from some data-source. The protocol's primary method, loadTimeZone
, loads a baltzo::Zoneinfo
object describing the time zone identified by a user supplied time-zone string identifier.
Implementations of baltzo::Loader
must return a baltzo::Zoneinfo
object that is well-formed (see baltzo::ZoneinfoUtil::isWellFormed
), and whose identifier
property matches the requested time zone id. Implementations not meeting these constraints will generally not interoperate with other components in this package that enforce those constraints on provided baltzo::Zoneinfo
objects, e.g., baltzo_zoneinfocache .
This section illustrates intended use of this component.
This example demonstrates an implementation of baltzo::Loader
that can only return data for "America/New_York".
Note that in general, an implementation of baltzo::Loader
should obtain time-zone information from an external data source (see baltzo_datafileloader ).
First, we define the interface of our implementation:
Then, we implement the creators, trivially, as this class contains no instance data members.
Next, we implement the loadTimeZone
function:
Then, we check the timeZoneId
equals to "America/New_York" as this implementation is designed to demonstrate only one time zone:
Next, we load result
with the time zone identifier for New York
Then, we create two local-time descriptors, one for standard time and one for daylight-saving time.
Next, we create a series of transitions between these local time descriptors for the years 2007-2011. Note that the United States transitions to daylight saving time on the second Sunday in March, at 2am local time (7am UTC), and transition back to standard time on the first Sunday in November at 2am local time (6am UTC), resulting in an even number of transitions. Also note that, the rules for generating these transitions were changed in 2007, and may be changed again at some point in the future.
Finally, we define a function f
that instantiates an object of type MyLoaderImp
:
In this example we use a MyLoaderImpl
to load the data for one time zone, and print the time transitions, contained in the obtained time zone data, to standard output. Note that, the implementation of this example is for illustrative purpose only, and in general, clients should use an implementation that loads data from an external data source (e.g., baltzo_datafileloader ).
First, we obtain a MyLoaderImpl
reference to myLoader
we constructed in the previous example:
Now, we load the time zone data for New York:
Then, we verify some basic properties of the time zone:
Finally, we write to standard output the information about the daylight-saving time transitions of the loaded time zone, in New York local time:
The resulting output will look like: