BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt_datetimeintervalutil.h
Go to the documentation of this file.
1/// @file bdlt_datetimeintervalutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_datetimeintervalutil.h -*-C++-*-
8#ifndef INCLUDED_BDLT_DATETIMEINTERVALUTIL
9#define INCLUDED_BDLT_DATETIMEINTERVALUTIL
10
11// BDE_VERIFY pragma: -FABC01 we order functions by increasing resolution
12// BDE_VERIFY pragma: -SEG03
13
14#include <bsls_ident.h>
15BSLS_IDENT("$Id: $")
16
17/// @defgroup bdlt_datetimeintervalutil bdlt_datetimeintervalutil
18/// @brief Provide non-primitive operations on `bdlt::DatetimeInterval`.
19/// @addtogroup bdl
20/// @{
21/// @addtogroup bdlt
22/// @{
23/// @addtogroup bdlt_datetimeintervalutil
24/// @{
25///
26/// <h1> Outline </h1>
27/// * <a href="#bdlt_datetimeintervalutil-purpose"> Purpose</a>
28/// * <a href="#bdlt_datetimeintervalutil-classes"> Classes </a>
29/// * <a href="#bdlt_datetimeintervalutil-description"> Description </a>
30/// * <a href="#bdlt_datetimeintervalutil-usage"> Usage </a>
31/// * <a href="#bdlt_datetimeintervalutil-example-1-simple-usage-of-the-various-make-functions"> Example 1: Simple Usage of the Various make Functions </a>
32/// * <a href="#bdlt_datetimeintervalutil-example-2-how-to-improve-readability-using-the-make-functions"> Example 2: How to Improve Readability Using the make Functions </a>
33///
34/// # Purpose {#bdlt_datetimeintervalutil-purpose}
35/// Provide non-primitive operations on `bdlt::DatetimeInterval`.
36///
37/// # Classes {#bdlt_datetimeintervalutil-classes}
38///
39/// - bdlt::DatetimeIntervalUtil: Utilities for `bdlt::DatetimeInterval`
40///
41/// @see bdlt_datetimeinterval
42///
43/// # Description {#bdlt_datetimeintervalutil-description}
44/// This component provides non-primitive operations on
45/// `bdlt::DatetimeInterval` objects. In particular,
46/// `bdlt::DatetimeIntervalUtil` supplies factory methods for
47/// `bdlt::DatetimeInterval` objects.
48///
49/// This utility component provides the following (static) methods:
50/// @code
51/// bdlt::DatetimeInterval makeDays(int days);
52/// bdlt::DatetimeInterval makeHours(bsls::Types::Int64 hours);
53/// bdlt::DatetimeInterval makeMinutes(bsls::Types::Int64 minutes);
54/// bdlt::DatetimeInterval makeSeconds(bsls::Types::Int64 seconds);
55/// bdlt::DatetimeInterval makeMilliseconds(bsls::Types::Int64 milliseconds);
56/// bdlt::DatetimeInterval makeMicroseconds(bsls::Types::Int64 microseconds);
57/// @endcode
58///
59/// ## Usage {#bdlt_datetimeintervalutil-usage}
60///
61///
62/// This section illustrates intended use of this component.
63///
64/// ### Example 1: Simple Usage of the Various make Functions {#bdlt_datetimeintervalutil-example-1-simple-usage-of-the-various-make-functions}
65///
66///
67/// This example shows how we can create a `bdlt::DatetimeInterval` objects
68/// having values of 1 day, 2 hours, 3 minutes, 4 seconds, 5 millisecond, and 6
69/// microseconds by using the `bdlt::DatetimeInterval` constructor and, more
70/// readably, by using the `make*` functions.
71///
72/// First, start with a default (0) `bdlt::DatetimeInterval`:
73/// @code
74/// bdlt::DatetimeInterval m;
75/// bdlt::DatetimeInterval d;
76/// @endcode
77/// Next, add 1 day to it, and assert that both objects are equal:
78/// @code
79/// m += bdlt::DatetimeIntervalUtil::makeDays(1);
80/// d += bdlt::DatetimeInterval(1, 0, 0, 0, 0, 0);
81/// assert(m == d);
82/// @endcode
83/// Then, add 2 hours to it, and assert that both objects are equal:
84/// @code
85/// m += bdlt::DatetimeIntervalUtil::makeHours(2);
86/// d += bdlt::DatetimeInterval(0, 2, 0, 0, 0, 0);
87/// assert(m == d);
88/// @endcode
89/// Next, add 3 minutes to it, and assert that both objects are equal:
90/// @code
91/// m += bdlt::DatetimeIntervalUtil::makeMinutes(3);
92/// d += bdlt::DatetimeInterval(0, 0, 3, 0, 0, 0);
93/// assert(m == d);
94/// @endcode
95/// Then, add 4 seconds to it, and assert that both objects are equal:
96/// @code
97/// m += bdlt::DatetimeIntervalUtil::makeSeconds(4);
98/// d += bdlt::DatetimeInterval(0, 0, 0, 4, 0, 0);
99/// assert(m == d);
100/// @endcode
101/// Next, add 5 milliseconds to it, and assert that both objects are equal:
102/// @code
103/// m += bdlt::DatetimeIntervalUtil::makeMilliseconds(5);
104/// d += bdlt::DatetimeInterval(0, 0, 0, 0, 5, 0);
105/// assert(m == d);
106/// @endcode
107/// Then, add 6 microseconds to it, and assert that both objects are equal:
108/// @code
109/// m += bdlt::DatetimeIntervalUtil::makeMicroseconds(6);
110/// d += bdlt::DatetimeInterval(0, 0, 0, 0, 0, 6);
111/// assert(m == d);
112/// @endcode
113/// Finally, we create an create a `DatetimeInterval` with the final value and
114/// compare to the objects built in steps:
115/// @code
116/// bdlt::DatetimeInterval f(1, 2, 3, 4, 5, 6);
117/// assert(f == m);
118/// assert(f == d);
119/// @endcode
120///
121/// ### Example 2: How to Improve Readability Using the make Functions {#bdlt_datetimeintervalutil-example-2-how-to-improve-readability-using-the-make-functions}
122///
123///
124/// This example shows how we can create a `bdlt::Datetime` objects having a
125/// value of now + 2 hours and 30 minutes by using the `bdlt::DatetimeInterval`
126/// constructor and, more readably, by using the `make*` functions.
127///
128/// First, create a `bdlt::Datetime` object having the current time:
129/// @code
130/// bdlt::Datetime now = bdlt::CurrentTime::now();
131/// @endcode
132/// Now, create the `bdlt::DatetimeInterval` objects and assign the desired
133/// values to them using the `makeHours` and `makeMinutes` functions, and using
134/// the `bdlt::DatetimeInterval` constructor:
135/// @code
136/// bdlt::Datetime nextEventTime = now
137/// + bdlt::DatetimeIntervalUtil::makeHours(2)
138/// + bdlt::DatetimeIntervalUtil::makeMinutes(30);
139/// bdlt::Datetime altEventTime = now
140/// + bdlt::DatetimeInterval(0, 2, 30, 0, 0, 0);
141/// @endcode
142/// Finally, assert that both results are equal:
143/// @code
144/// assert(nextEventTime == altEventTime);
145/// @endcode
146/// @}
147/** @} */
148/** @} */
149
150/** @addtogroup bdl
151 * @{
152 */
153/** @addtogroup bdlt
154 * @{
155 */
156/** @addtogroup bdlt_datetimeintervalutil
157 * @{
158 */
159
160#include <bdlscm_version.h>
162#include <bsls_types.h>
163
164
165namespace bdlt {
166
167 // ===========================
168 // struct DatetimeIntervalUtil
169 // ===========================
170
171/// This utility `struct` provides a namespace for a suite of functions
172/// operating on objects of type `DatetimeInterval`.
174
175 public:
176 // CLASS METHODS
177
178 /// Return a `DatetimeInterval` object representing an duration of the
179 /// specified `days` (exactly).
180 static DatetimeInterval makeDays(int days);
181
182 /// Return a `DatetimeInterval` object representing an duration of the
183 /// specified `hours` (exactly).
185
186 /// Return a `DatetimeInterval` object representing an duration of the
187 /// specified `minutes` (exactly).
189
190 /// Return a `DatetimeInterval` object representing an duration of the
191 /// specified `seconds` (exactly).
193
194 /// Return a `DatetimeInterval` object representing an duration of the
195 /// specified `milliseconds` (exactly).
197
198 /// Return a `DatetimeInterval` object representing an duration of the
199 /// specified `microseconds` (exactly).
201};
202
203// ============================================================================
204// INLINE DEFINITIONS
205// ============================================================================
206
207 // ---------------------------
208 // struct DatetimeIntervalUtil
209 // ---------------------------
210
211inline
216
217inline
222
223inline
228
229inline
234
235inline
237 bsls::Types::Int64 milliseconds)
238{
239 return DatetimeInterval(0, 0, 0, 0, milliseconds);
240}
241
242inline
244 bsls::Types::Int64 microseconds)
245{
246 return DatetimeInterval(0, 0, 0, 0, 0, microseconds);
247}
248
249} // close package namespace
250
251
252#endif
253
254// ----------------------------------------------------------------------------
255// Copyright 2017 Bloomberg Finance L.P.
256//
257// Licensed under the Apache License, Version 2.0 (the "License");
258// you may not use this file except in compliance with the License.
259// You may obtain a copy of the License at
260//
261// http://www.apache.org/licenses/LICENSE-2.0
262//
263// Unless required by applicable law or agreed to in writing, software
264// distributed under the License is distributed on an "AS IS" BASIS,
265// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
266// See the License for the specific language governing permissions and
267// limitations under the License.
268// ----------------------------- END-OF-FILE ----------------------------------
269
270/** @} */
271/** @} */
272/** @} */
Definition bdlt_datetimeinterval.h:201
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicisma30360.h:112
Definition bdlt_datetimeintervalutil.h:173
static DatetimeInterval makeMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeintervalutil.h:243
static DatetimeInterval makeSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetimeintervalutil.h:230
static DatetimeInterval makeMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeintervalutil.h:236
static DatetimeInterval makeDays(int days)
Definition bdlt_datetimeintervalutil.h:212
static DatetimeInterval makeHours(bsls::Types::Int64 hours)
Definition bdlt_datetimeintervalutil.h:218
static DatetimeInterval makeMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetimeintervalutil.h:224
long long Int64
Definition bsls_types.h:132