BDE 4.14.0 Production release
|
Provide a representation of a date with time zone offset.
This component provides a single value-semantic class, bdlt::DateTz
, that represents a date value in a particular time zone. Each bdlt::DateTz
object contains a time zone offset from UTC (in minutes) and a bdlt::Date
value in that time zone. For logical consistency, the date value and offset should correspond to a geographically valid time zone, but such consistency is the user's responsibility. This component does not enforce logical constraints on any values.
A bdlt::DateTz
value is intended to be interpreted as a value in a local time zone, along with the offset of that value from UTC. However, there are some problems with this simple interpretation. First of all, the offset value may not correspond to any time zone that has ever existed. For example, the offset value could be set to one minute, or to 1,234 minutes. The meaning of the resulting "local time" value is always clear, but the local time might not correspond to any geographical or historical time zone.
The second problem is more subtle. A given offset from UTC might be "valid" in that it corresponds to a real time zone, but the actual date value might not exist in that time zone. To make matters worse, a "valid" offset may not (indeed, rarely will) specify one time zone uniquely. Moreover, the date value might be valid in one time zone corresponding to a given offset, and not in another time zone.
For these reasons (and others), this component cannot and does not perform any validation relating to time zones or offsets. The user must take care to honor the "local date" contract of this component.
A common standard text representation of a date and time value is described by ISO 8601. BDE provides the bdlt_iso8601util component for conversion to and from the standard ISO8601 format.
This section illustrates intended use of this component.
Suppose that we need to compare dates in different time zones. The bdlt::DateTz
type helps us to accomplish this by providing the utcStartTime
method, which returns a bdlt::Datetime
value corresponding to the UTC "point in time" when the local date starts (i.e. 000 hours local time).
First, we default construct an object dateTz1
, which has an offset of 0, implying that the object represents a date in the UTC time zone.
Notice the value of a default contructed bdlt::DateTz
object is the same as that of a default constructed bdlt::Date
object.
Then, we construct two objects dateTz2
and dateTz3
to have a local date of 2013/12/31 in the EST time zone (UTC-5) and the pacific time zone (UTC-8) respectively:
Next, we compare the local dates of the two DateTz
objects, and verify that they compare equal:
Now, we compare the starting time of the two DateTz
objects using the utcStartTime
method: