|
BDE 4.14.0 Production release
|
Provide functions to convert between time-interval representations.
This component provides a utility struct, bdlt::IntervalConversionUtil, that defines functions to convert between C++ value types providing different representations of time intervals, (e.g., bsls::TimeInterval and bdlt::DatetimeInterval).
This section illustrates intended use of this component.
Some APIs, such as bsls::SystemTime, use bsls::TimeInterval in their interface. In order to use those APIs in components implemented in terms of bdlt::DatetimeInterval, it is necessary to convert between the bsls::TimeInterval and bdlt::DatetimeInterval representations for a time interval. This conversion can be accomplished conveniently using bdlt::IntervalConversionUtil.
Suppose we wish to pass the system time – as returned by bsls::SystemTime::nowRealtimeClock – to a function that displays a time that is represented as a bdlt::DatetimeInterval since the UNIX epoch.
First, we include the declaration of the function that displays a bdlt::DatetimeInterval:
Then, we obtain the current system time from bsls::SystemTime, and store it in a bsls::TimeInterval:
Now, we convert the bsls::TimeInterval into a bdlt::DatetimeInterval using convertToDatetimeInterval:
Finally, we display the time by passing the converted value to displayTime: