Provide functions to convert between time-interval representations.
More...
Namespaces |
namespace | bdlt |
Detailed Description
- Outline
-
-
- Purpose:
- Provide functions to convert between time-interval representations.
-
- Classes:
-
- See also:
- Component bdlt_datetimeinterval, Component bsls_timeinterval
-
- Description:
- 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
).
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Interfacing With an API That Uses bsls::TimeInterval:
- 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
: void displayTime(const bdlt::DatetimeInterval& timeSinceEpoch);
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
: displayTime(timeSinceEpoch);