BDE 4.14.0 Production release
|
Provide common non-primitive operations on bdlt::Time
.
bdlt::Time
This component provides non-primitive operations on bdlt::Time
objects. In particular, the bdlt::TimeUtil
namespace defined in this component provides conversions among bdlt::Time
values and their corresponding non-negative integral values (e.g., convertFromHHMM
, convertToHHMMSSmmm
), and methods to validate such integral values (e.g., isValidHHMMSS
) before passing them to the corresponding "convertFrom" method.
Seconds-from-midnight is a date-time representation used in some financial applications. Seconds-from-midnight is a lossy representation (using heuristics to determine the date), and conversions for that representation are provided in a higher-level package that is not part of the BDE open-source libraries (see bsitzo_secondsfrommidnightutil ).
Following are examples illustrating basic use of this component.
First, we demonstrate how to use bdlt::TimeUtil
to convert from an integer representation of time in "HHMMSSmmm" format to a bdlt::Time
. Our first time will be around 3:45 pm.
The code above produces the following on stdout
:
Then, we demonstrate a different time, 3:32:24.832 am. Note that we do not lead the integer value with 0
:
The code above produces the following on stdout
:
Now, we demonstrate how bdlt::TimeUtil
provides methods that can be used to validate integral time values before passing them to the various "convert" methods. For example:
Finally, we demonstrate catching an invalid time value, 12:61:02.789 pm:
The following snippet of code demonstrates how to use bdlt::TimeUtil
to convert from a bdlt::Time
to an integer representation of time in "HHMM", "HHMMSS", and "HHMMSSmmm" formats:
The code above produces the following on stdout
:
Note that the millisecond and/or second fields of bdlt::Time
are ignored depending on the conversion method that is called.