Provide non-primitive operations on bdlt::DatetimeInterval
.
More...
Namespaces |
namespace | bdlt |
Detailed Description
- Outline
-
-
- Purpose:
- Provide non-primitive operations on
bdlt::DatetimeInterval
.
-
- Classes:
-
- See also:
- Component bdlt_datetimeinterval
-
- Description:
- This component provides non-primitive operations on
bdlt::DatetimeInterval
objects. In particular, bdlt::DatetimeIntervalUtil
supplies factory methods for bdlt::DatetimeInterval
objects.
- This utility component provides the following (static) methods:
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Simple Usage of the Various make* Functions:
- This example shows how we can create a
bdlt::DatetimeInterval
objects having values of 1 day, 2 hours, 3 minutes, 4 seconds, 5 millisecond, and 6 microseconds by using the bdlt::DatetimeInterval
constructor and, more readably, by using the make*
functions.
- First, start with a default (0)
bdlt::DatetimeInterval
: bdlt::DatetimeInterval m;
bdlt::DatetimeInterval d;
Next, add 1 day to it, and assert that both objects are equal: Then, add 2 hours to it, and assert that both objects are equal: Next, add 3 minutes to it, and assert that both objects are equal: Then, add 4 seconds to it, and assert that both objects are equal: Next, add 5 milliseconds to it, and assert that both objects are equal: Then, add 6 microseconds to it, and assert that both objects are equal: Finally, we create an create a DatetimeInterval
with the final value and compare to the objects built in steps: bdlt::DatetimeInterval f(1, 2, 3, 4, 5, 6);
assert(f == m);
assert(f == d);
-
- Example 2: How to Improve Readability Using the make* Functions:
- This example shows how we can create a
bdlt::Datetime
objects having a value of now + 2 hours and 30 minutes by using the bdlt::DatetimeInterval
constructor and, more readably, by using the make*
functions.
- First, create a
bdlt::Datetime
object having the current time: Now, create the bdlt::DatetimeInterval
objects and assign the desired values to them using the makeHours
and makeMinutes
functions, and using the bdlt::DatetimeInterval
constructor: Finally, assert that both results are equal: assert(nextEventTime == altEventTime);