BDE 4.14.0 Production release
|
Provide an attribute class for characterizing local time values.
This component provides a single, simply constrained (value-semantic) attribute class, baltzo::LocalTimeDescriptor
, that is used to characterize subsets of local time values within time zones. Note that this class is consistent with the "local-time types" found in the "Zoneinfo" representation of a time zone (see baltzo_zoneinfo ).
description
: non-canonical, non-localized name (intended for debugging).dstInEffectFlag
: true
if the described local times are Daylight-Saving-Time (DST) values.utcOffsetInSeconds
: offset from UTC of the described local times.For example, in New York on January 1, 2011, the local time is Eastern Standard Time, Daylight-Saving Time (DST) is not in effect, and the offset from UTC is -5 hours. We can represent this information using a baltzo::LocalTimeDescriptor
object whose description
is "EST", dstInEffectFlag
is false
, and utcOffsetInSeconds
is -18,000 (-5*60*60)
. Note that description
is not canonical, and is intended for development and debugging only.
This section illustrates intended use of this component.
When using the "Zoneinfo" database, we want to represent and access the local time information contained in the "Zoneinfo" binary data files. Once we have obtained this information, we can use it to convert times from one time zone to another. The following code illustrates how to perform such conversions using baltzo::LocalTimeDescriptor
.
First, we define a baltzo::LocalTimeDescriptor
object that characterizes the local time in effect for New York Daylight-Saving Time in 2010:
Then, we create a bdlt::Datetime
representing the time "Jul 20, 2010 11:00" in New York:
Next, we convert newYorkDatetime
to its corresponding UTC value using the newYorkDst
descriptor (created above); note that, when converting from a local time to a UTC time, the signed offset from UTC is subtracted from the local time:
Then, we verify that the result corresponds to the expected UTC time, "Jul 20, 2010 15:00":
Next, we define a baltzo::LocalTimeDescriptor
object that describes the local time in effect for Rome in the summer of 2010:
Now, we convert utcDatetime
to its corresponding local-time value in Rome using the romeDst
descriptor (created above):
Notice that, when converting from UTC time to local time, the signed offset from UTC is added to UTC time rather than subtracted.
Finally, we verify that the result corresponds to the expected local time, "Jul 20, 2010 17:00":