Provide utilities to retrieve the current time.
More...
Namespaces |
namespace | bdlt |
Detailed Description
- Outline
-
-
- Purpose:
- Provide utilities to retrieve the current time.
-
- Classes:
-
- See also:
- Component bsls_timeinterval, bdlt_systemtimeutil
-
- Description:
- This component,
bdlt::CurrentTime
, provides static methods for retrieving the current time in Coordinated Universal Time (UTC) and in the local time zone of the executing process. It also provides a facility for customizing the means by which the time is retrieved.
-
- Thread Safety:
- The functions provided by
bdlt::CurrentTime
are thread-safe (meaning they may be called concurrently from multiple threads), including those that set and retrieve the callback function. In addition, user-supplied callback functions must be thread-safe.
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Repeatable Tests Involving Current Time:
- Suppose we are writing an application which involves dealing with the current time (for example, a clock displaying it). In order to test the application, we would like to be able to control the time it sees. We can use
bdlt::CurrentTime
for this purpose.
- First, we create a sample application. For this example, we simply have it retrieve the current time in several formats: Then, we create a method to test whether the application is producing the expected results: Next, we create a class allowing us to set the current time which will be seen by the application: Finally, we write a method that tests that our application is functioning correctly: