BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bsls_timeinterval.h
Go to the documentation of this file.
1/// @file bsls_timeinterval.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bsls_timeinterval.h -*-C++-*-
8#ifndef INCLUDED_BSLS_TIMEINTERVAL
9#define INCLUDED_BSLS_TIMEINTERVAL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bsls_timeinterval bsls_timeinterval
15/// @brief Provide a representation of a time interval.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bsls
19/// @{
20/// @addtogroup bsls_timeinterval
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bsls_timeinterval-purpose"> Purpose</a>
25/// * <a href="#bsls_timeinterval-classes"> Classes </a>
26/// * <a href="#bsls_timeinterval-description"> Description </a>
27/// * <a href="#bsls_timeinterval-representation"> Representation </a>
28/// * <a href="#bsls_timeinterval-user-defined-literals"> User-Defined Literals </a>
29/// * <a href="#bsls_timeinterval-usage"> Usage </a>
30/// * <a href="#bsls_timeinterval-example-1-creating-and-modifying-a-bsls-timeinterval"> Example 1: Creating and Modifying a bsls::TimeInterval </a>
31///
32/// # Purpose {#bsls_timeinterval-purpose}
33/// Provide a representation of a time interval.
34///
35/// # Classes {#bsls_timeinterval-classes}
36///
37/// - bsls::TimeInterval: time interval with nanosecond resolution
38///
39/// @see bdlt_time, bdlt_datetimeinterval
40///
41/// # Description {#bsls_timeinterval-description}
42/// This component provides a value-semantic type,
43/// `bsls::TimeInterval`, that is capable of representing a signed time
44/// interval with nanosecond resolution.
45///
46/// ## Representation {#bsls_timeinterval-representation}
47///
48///
49/// A time interval has a value that is independent of its representation.
50/// Conceptually, a time interval may be thought of as a signed,
51/// arbitrary-precision floating-point number denominated in seconds (or in
52/// days, or in fortnights, if one prefers). A `bsls::TimeInterval` represents
53/// this value as two fields: seconds and nanoseconds. In the "canonical
54/// representation" of a time interval, the `seconds` field may have any 64-bit
55/// signed integer value, with the `nanoseconds` field limited to the range
56/// `[ -999,999,999..999,999,999 ]`, and with the additional constraint that the
57/// two fields are either both non-negative or both non-positive. When setting
58/// the value of a time interval via its two-field representation, any integer
59/// value may be used in either field, with the constraint that the resulting
60/// number of seconds be representable as a 64-bit signed integer. Similarly,
61/// the two field values may be accessed in the canonical representation using
62/// the `seconds` and `nanoseconds` methods.
63///
64/// Binary arithmetic and relational operators taking two `bsls::TimeInterval`
65/// objects, or a `bsls::TimeInterval` object and a `double`, are provided. A
66/// `double` operand, representing a real number of seconds, is first converted
67/// to a `bsls::TimeInterval` object before performing the operation. Under
68/// such circumstances, the fractional part of the `double`, if any, is rounded
69/// to the nearest whole number of nanoseconds.
70///
71/// ## User-Defined Literals {#bsls_timeinterval-user-defined-literals}
72///
73///
74/// The user-defined literal `operator""_h`, `operator""_min`,
75/// `operator""_s`, `operator""_ms`, `operator""_us` and `operator""_ns` are
76/// declared for the `TimeInterval`. These suffixes can be applied to integer
77/// literals and allow to create an object, representing the specified number of
78/// hours, minutes, seconds, milliseconds, microseconds or nanoseconds
79/// respectively:
80/// @code
81/// using namespace bsls::TimeIntervalLiterals;
82///
83/// bsls::TimeInterval i0 = 10_h;
84/// assert(36000 == i0.seconds() );
85/// assert(0 == i0.nanoseconds());
86///
87/// bsls::TimeInterval i1 = 10001_ms;
88/// assert(10 == i1.seconds() );
89/// assert(1000000 == i1.nanoseconds());
90///
91/// bsls::TimeInterval i2 = 100_ns;
92/// assert(0 == i2.seconds() );
93/// assert(100 == i2.nanoseconds());
94/// @endcode
95/// The operators providing literals are available in the
96/// `BloombergLP::bsls::literals::TimeIntervalLiterals` namespace (where
97/// `literals` and `TimeIntervalLiterals` are both inline namespaces). Because
98/// of inline namespaces, there are several viable options for a using
99/// declaration, but *we* *recommend*
100/// `using namespace bsls::TimeIntervalLiterals`, which minimizes the scope of
101/// the using declaration.
102///
103/// Note that user defined literals can be used only if the compiler supports
104/// the C++11 standard.
105///
106/// ## Usage {#bsls_timeinterval-usage}
107///
108///
109/// This section illustrates intended use of this component.
110///
111/// ### Example 1: Creating and Modifying a bsls::TimeInterval {#bsls_timeinterval-example-1-creating-and-modifying-a-bsls-timeinterval}
112///
113///
114/// The following example demonstrates how to create and manipulate a
115/// `bsls::TimeInterval` object.
116///
117/// First, we default construct a `TimeInterval` object, `interval`:
118/// @code
119/// bsls::TimeInterval interval;
120///
121/// assert(0 == interval.seconds());
122/// assert(0 == interval.nanoseconds());
123/// @endcode
124/// Next, we set the value of `interval` to 1 second and 10 nanoseconds (a time
125/// interval of 1000000010 nanoseconds):
126/// @code
127/// interval.setInterval(1, 10);
128///
129/// assert( 1 == interval.seconds());
130/// assert(10 == interval.nanoseconds());
131/// @endcode
132/// Then, we add 3 seconds to `interval`:
133/// @code
134/// interval.addInterval(3, 0);
135///
136/// assert( 4 == interval.seconds());
137/// assert(10 == interval.nanoseconds());
138/// @endcode
139/// Next, we create a copy of `interval`, `intervalPrime`:
140/// @code
141/// bsls::TimeInterval intervalPrime(interval);
142///
143/// assert(intervalPrime == interval);
144/// @endcode
145/// Finally, we assign 3.14 seconds to `intervalPrime`, and then add 2.73
146/// seconds more:
147/// @code
148/// intervalPrime = 3.14;
149/// intervalPrime += 2.73;
150///
151/// assert( 5 == intervalPrime.seconds());
152/// assert(870000000 == intervalPrime.nanoseconds());
153/// @endcode
154/// @}
155/** @} */
156/** @} */
157
158/** @addtogroup bsl
159 * @{
160 */
161/** @addtogroup bsls
162 * @{
163 */
164/** @addtogroup bsls_timeinterval
165 * @{
166 */
167
168#include <bsls_assert.h>
170#include <bsls_keyword.h>
171#include <bsls_libraryfeatures.h>
172#include <bsls_preconditions.h>
173#include <bsls_types.h>
174
175#if BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
176#include <chrono>
177#include <type_traits>
178#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
179
180#include <iosfwd>
181#include <limits.h> // 'LLONG_MIN', 'LLONG_MAX'
182
183#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
184#include <bsls_nativestd.h>
185#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
186
187// BDE_VERIFY pragma: push
188// BDE_VERIFY pragma: -FABC01 // 'add*' operations are ordered by time unit
189
190#if BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
191#define BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
192#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
193
194
195namespace bsls {
196
197#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
198
199 // =======================================
200 // template struct TimeInterval_IsDuration
201 // =======================================
202
203/// Template metafunction to determine if the specified `TYPE` is a
204/// `std::chrono::duration`.
205template <class TYPE>
206struct TimeInterval_IsDuration : std::false_type {
207};
208
209/// Template metafunction specialization for `std::chrono::duration` types.
210template <class REP, class PER>
211struct TimeInterval_IsDuration<std::chrono::duration<REP, PER> >
212 : std::true_type {
213};
214
215 // =============================
216 // struct TimeInterval_RepTraits
217 // =============================
218
219/// Trait metafunction that determines whether the specified `REP` type is
220/// considered a floating point type.
221///
222/// See @ref bsls_timeinterval
223template <class REP>
224struct TimeInterval_RepTraits {
225
226 static const bool k_IS_FLOAT =
227 std::is_floating_point<REP>::value
228 || std::chrono::treat_as_floating_point<REP>::value;
229 // This compile time constant is 'true' if the 'REP' (template type
230 // argument) is indicated to be a floating point type by the underlying
231 // library. Otherwise, if the underlying library does not consider 'REP'
232 // floating point anywhere (see note), 'k_IS_FLOAT' is 'false'. Note that
233 // to cover all scenarios we need to examine *two* traits. The first one
234 // that tells if the representation type is a floating point (arithmetic)
235 // type or not (from '<type_traits>'), and another that tells that
236 // representation type is considered a floating point type from the
237 // 'std::chrono' perspective. Formally the second one just duplicates the
238 // first one, but *in theory* either can be specialized to be true,
239 // independently. Also note that conversions from 'std::chrono::duration'
240 // with a floating point representation to 'bsls::TimeInterval' are *not*
241 // supported for now.
242};
243
244 // ==================================
245 // struct TimeInterval_DurationTraits
246 // ==================================
247
248/// Trait metafunction that determines whether the
249/// `std::chrono::duration<REP, PERIOD>` object can be converted to
250/// `bsls::TimeInterval` either implicitly or explicitly.
251///
252/// See @ref bsls_timeinterval
253template <class REP, class PERIOD>
254struct TimeInterval_DurationTraits {
255
256 /// This compile time constant is `true` if the `REP` (template type
257 /// argument) is indicated to be a floating point type by the underlying
258 /// library. Otherwise, if the underlying library does not consider
259 /// `REP` floating point anywhere (see `TimeInterval_RepTraits`),
260 /// `k_IS_FLOAT` is `false`.
261 static const bool k_IS_FLOAT = TimeInterval_RepTraits<REP>::k_IS_FLOAT;
262
263 /// This compile time constant is `true` if any possible value of an
264 /// 'std::chrono::duration<REP, PERIOD> object will be represented by
265 /// integer nanoseconds (fractions of nanoseconds are not required).
266 /// Otherwise this value is `false`.
267 static const bool k_IS_IMPLICIT = (std::nano::den % PERIOD::den == 0);
268
269 /// This compile time constant is `true` if
270 /// `std::chrono::duration<REP, PERIOD>` objects will be implicitly
271 /// converted to `TimeInterval`, and `false` otherwise. This value is
272 /// intended to be used with `enable_if` to enable implicitly converting function overloads.
273 ///
274 /// \note Note that this boolean value is mutually
275 /// exclusive with `k_EXPLICIT_CONVERION_ENABLED` as in they will never
276 /// be both `true` for the same `REP" and `PERIOD', but they may be both
277 /// `false` for floats.
278 static const bool k_IMPLICIT_CONVERSION_ENABLED =
279 !k_IS_FLOAT && k_IS_IMPLICIT;
280
281 /// This compile time constant is `true` if
282 /// `std::chrono::duration<REP, PERIOD>` objects can be explicitly
283 /// converted to `TimeInterval`, and `false` otherwise. This value is
284 /// intended to be used with `enable_if` to enable explicitly converting function overloads.
285 ///
286 /// \note Note that this boolean value is mutually
287 /// exclusive with `k_IMPLICIT_CONVERION_ENABLED` as in they will never
288 /// be both `true` for the same `REP" and `PERIOD', but they may be both
289 /// `false` for floats.
290 static const bool k_EXPLICIT_CONVERSION_ENABLED =
291 !k_IS_FLOAT && !k_IS_IMPLICIT;
292};
293
294#endif
295 // ==================
296 // class TimeInterval
297 // ==================
298
299/// Each instance of this value-semantic type represents a time interval
300/// with nanosecond resolution. In the "canonical representation" of a time
301/// interval, the `seconds` field may have any 64-bit signed integer value,
302/// with the `nanoseconds` field limited to the range
303/// `[ -999,999,999..999,999,999 ]`, and with the additional constraint that
304/// the two fields are either both non-negative or both non-positive.
305///
306/// See @ref bsls_timeinterval
308
309 // PRIVATE TYPES
310 enum {
311 k_MILLISECS_PER_SEC = 1000, // one thousand
312
313 k_MICROSECS_PER_SEC = 1000000, // one million
314
315 k_NANOSECS_PER_MICROSEC = 1000, // one thousand
316
317 k_NANOSECS_PER_MILLISEC = 1000000, // one million
318
319 k_NANOSECS_PER_SEC = 1000000000, // one billion
320
321 k_SECONDS_PER_MINUTE = 60,
322
323 k_SECONDS_PER_HOUR = 60 * k_SECONDS_PER_MINUTE,
324
325 k_SECONDS_PER_DAY = 24 * k_SECONDS_PER_HOUR
326 };
327
328 // DATA
329 bsls::Types::Int64 d_seconds; // field for seconds
330 int d_nanoseconds; // field for nanoseconds
331
332 // PRIVATE CLASS METHODS
333
334 /// Return `true` if the sum of the specified `lhs` and `rhs` can be
335 /// represented using a 64-bit signed integer, and `false` otherwise.
337 static bool isSumValidInt64(bsls::Types::Int64 lhs,
339
340 public:
341 // CLASS METHODS
342
343 /// Return `true` if a `TimeInterval` object can be constructed from the
344 /// specified `seconds` and `nanoseconds`, and `false` otherwise. A
345 /// time interval can be constructed from `seconds` and `nanoseconds` if
346 /// their sum results in a time interval whose total number of seconds
347 /// can be represented with a 64-bit signed integer.
350 int nanoseconds);
351
352#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
353 /// Return `true` if a `TimeInterval` object can be constructed from the
354 /// specified `duration`, and `false` otherwise. A time interval can be
355 /// constructed from `duration` if duration's value converted to seconds
356 /// can be represented with a 64-bit signed integer.
357 template <class REP, class PERIOD>
358 static bool isValid(const std::chrono::duration<REP, PERIOD>& duration);
359#endif
360
361 // Aspects
362
363 /// Return the maximum valid BDEX format version, as indicated by the
364 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
365 ///
366 /// \note Note that it is highly recommended that `versionSelector`
367 /// be formatted as "YYYYMMDD", a date representation. Also note that
368 /// `versionSelector` should be a *compile*-time-chosen value that
369 /// selects a format version supported by both externalizer and
370 /// unexternalizer. See the `bslx` package-level documentation for more
371 /// information on BDEX streaming of value-semantic types and
372 /// containers.
373 static int maxSupportedBdexVersion(int versionSelector);
374
375 // CREATORS
376
377 /// Create a time interval having the value of 0 seconds and 0
378 /// nanoseconds.
380 TimeInterval();
381
382 /// Create a time interval having the value given by the sum of the
383 /// specified integral number of `seconds` and `nanoseconds`.
384 ///
385 /// \pre The behavior is undefined unless the total number of seconds in the
386 /// resulting time interval can be represented with a 64-bit signed integer (see `isValid`).
387 ///
388 /// \note Note that there is no restriction on the
389 /// sign or magnitude of either argument except that they must not
390 /// violate the method's preconditions.
393
394 /// Create a time interval having the value represented by the specified
395 /// real number of `seconds`. The fractional part of `seconds`, if any,
396 /// is rounded to the nearest whole number of nanoseconds.
397 ///
398 /// \pre The behavior is undefined unless the total number of seconds in the
399 /// resulting time interval can be represented with a 64-bit signed
400 /// integer.
401 explicit TimeInterval(double seconds);
402
403#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
404 /// Create a time interval having the value represented by the specified
405 /// `duration`. Only integer representations of `duration` are
406 /// supported (i.e. `REP_TYPE` is integer). If the `duration` can be
407 /// represented *exactly* by an integer nanoseconds this constructor
408 /// will be implicit. Otherwise, the constructor will be explicit.
409 ///
410 /// \pre The behavior is undefined unless the `duration` can be converted to a
411 /// valid `TimeInterval` object, whose `seconds` field may have any
412 /// 64-bit signed integer value and `nanoseconds` field limited to the range `[ -999,999,999..999,999,999 ]`.
413 ///
414 /// \note Note that the current
415 /// implementation of the lossy conversions (e.g., fractions of a
416 /// nanosecond) truncates the values towards zero, however this behavior
417 /// may change without notice in the future, so *do not* rely on this.
418 template <class REP_TYPE, class PERIOD_TYPE>
420 const std::chrono::duration<REP_TYPE, PERIOD_TYPE>& duration,
421 typename std::enable_if<TimeInterval_DurationTraits<
422 REP_TYPE,
423 PERIOD_TYPE>::k_IMPLICIT_CONVERSION_ENABLED,
424 int>::type * = 0);
425 template <class REP_TYPE, class PERIOD_TYPE>
427 const std::chrono::duration<REP_TYPE, PERIOD_TYPE>& duration,
428 typename std::enable_if<TimeInterval_DurationTraits<
429 REP_TYPE,
430 PERIOD_TYPE>::k_EXPLICIT_CONVERSION_ENABLED,
431 int>::type * = 0);
432#endif
433
434 TimeInterval(const TimeInterval& original) = default;
435 // Create a time interval having the value of the specified 'original'
436 // time interval. Note that this trivial copy constructor is
437 // generated by the compiler.
438
439 ~TimeInterval() = default;
440 // Destroy this time interval object. Note that this trivial
441 // destructor is generated by the compiler.
442
443 // MANIPULATORS
444
445 // Operator Overloads
446
447 TimeInterval& operator=(const TimeInterval& rhs) = default;
448 // Assign to this time interval the value of the specified 'rhs' time
449 // interval, and return a reference providing modifiable access to this
450 // object. Note that this trivial assignment operation is generated by
451 // the compiler.
452
453 /// Assign to this time interval the value of the specified `rhs` real
454 /// number of seconds, and return a reference providing modifiable
455 /// access to this object. The fractional part of `rhs`, if any, is
456 /// rounded to the nearest whole number of nanoseconds.
457 ///
458 /// \pre The behavior is undefined unless `rhs` can be converted to a valid
459 /// `TimeInterval` object.
460 TimeInterval& operator=(double rhs);
461
462 /// Add to this time interval the value of the specified `rhs` time
463 /// interval, and return a reference providing modifiable access to this object.
464 ///
465 /// \pre The behavior is undefined unless the total number of
466 /// seconds in the resulting time interval can be represented with a
467 /// 64-bit signed integer.
469
470 /// Add to this time interval the value of the specified `rhs` real
471 /// number of seconds, and return a reference providing modifiable
472 /// access to this object. The fractional part of `rhs`, if any, is
473 /// rounded to the nearest whole number of nanoseconds before being added to this object.
474 ///
475 /// \pre The behavior is undefined unless `rhs` can
476 /// be converted to a valid `TimeInterval` object, and the total number
477 /// of seconds in the resulting time interval can be represented with a
478 /// 64-bit signed integer.
479 TimeInterval& operator+=(double rhs);
480
481 /// Subtract from this time interval the value of the specified `rhs`
482 /// time interval, and return a reference providing modifiable access to this object.
483 ///
484 /// \pre The behavior is undefined unless
485 /// `LLONG_MIN != rhs.seconds()`, and the total number of seconds in the
486 /// resulting time interval can be represented with a 64-bit signed
487 /// integer.
489
490 /// Subtract from this time interval the value of the specified `rhs`
491 /// real number of seconds, and return a reference providing modifiable
492 /// access to this object. The fractional part of `rhs`, if any, is
493 /// rounded to the nearest whole number of nanoseconds before being subtracted from this object.
494 ///
495 /// \pre The behavior is undefined unless
496 /// `rhs` can be converted to a valid `TimeInterval` object whose
497 /// `seconds` field is greater than `LLONG_MIN`, and the total number of
498 /// seconds in the resulting time interval can be represented with a
499 /// 64-bit signed integer.
500 TimeInterval& operator-=(double rhs);
501
502 // Add Operations
503
504 /// Add to this time interval the number of seconds represented by the
505 /// specified integral number of `days`, and return a reference
506 /// providing modifiable access to this object.
507 ///
508 /// \pre The behavior is undefined unless the number of seconds in `days`, and the total
509 /// number of seconds in the resulting time interval, can both be represented with 64-bit signed integers.
510 ///
511 /// \note Note that `days` may be
512 /// negative.
515
516 /// Add to this time interval the number of seconds represented by the
517 /// specified integral number of `hours`, and return a reference
518 /// providing modifiable access to this object.
519 ///
520 /// \pre The behavior is undefined unless the number of seconds in `hours`, and the total
521 /// number of seconds in the resulting time interval, can both be represented with 64-bit signed integers.
522 ///
523 /// \note Note that `hours` may be
524 /// negative.
527
528 /// Add to this time interval the number of seconds represented by the
529 /// specified integral number of `minutes`, and return a reference
530 /// providing modifiable access to this object.
531 ///
532 /// \pre The behavior is undefined unless the number of seconds in `minutes`, and the total
533 /// number of seconds in the resulting time interval, can both be represented with 64-bit signed integers.
534 ///
535 /// \note Note that `minutes` may be
536 /// negative.
539
540 /// Add to this time interval the specified integral number of
541 /// `seconds`, and return a reference providing modifiable access to this object.
542 ///
543 /// \pre The behavior is undefined unless the total number of
544 /// seconds in the resulting time interval can be represented with a 64-bit signed integer.
545 ///
546 /// \note Note that `seconds` may be negative.
549
550 /// Add to this time interval the specified integral number of
551 /// `milliseconds`, and return a reference providing modifiable access to this object.
552 ///
553 /// \pre The behavior is undefined unless the total number
554 /// of seconds in the resulting time interval can be represented with a 64-bit signed integer.
555 ///
556 /// \note Note that `milliseconds` may be negative.
558
559 /// Add to this time interval the specified integral number of
560 /// `microseconds`, and return a reference providing modifiable access to this object.
561 ///
562 /// \pre The behavior is undefined unless the total number
563 /// of seconds in the resulting time interval can be represented with a 64-bit signed integer.
564 ///
565 /// \note Note that `microseconds` may be negative.
567
568 /// Add to this time interval the specified integral number of
569 /// `nanoseconds`, and return a reference providing modifiable access to this object.
570 ///
571 /// \pre The behavior is undefined unless the total number of
572 /// seconds in the resulting time interval can be represented with a 64-bit signed integer.
573 ///
574 /// \note Note that `nanoseconds` may be negative.
576
577 // Set Operations
578
579 /// Set the overall value of this object to indicate the specified integral number of `days`.
580 ///
581 /// \pre The behavior is undefined unless the
582 /// number of seconds in `days` can be represented with a 64-bit signed integer.
583 ///
584 /// \note Note that `days` may be negative.
587
588 /// Set the overall value of this object to indicate the specified integral number of `hours`.
589 ///
590 /// \pre The behavior is undefined unless the
591 /// number of seconds in `hours` can be represented with a 64-bit signed integer.
592 ///
593 /// \note Note that `hours` may be negative.
596
597 /// Set the overall value of this object to indicate the specified integral number of `minutes`.
598 ///
599 /// \pre The behavior is undefined unless the
600 /// number of seconds in `minutes` can be represented with a 64-bit signed integer.
601 ///
602 /// \note Note that `minutes` may be negative.
605
606 /// Set the overall value of this object to indicate the specified integral number of `seconds`.
607 ///
608 /// \note Note that `seconds` may be negative.
611
612 /// Set the overall value of this object to indicate the specified integral number of `milliseconds`.
613 ///
614 /// \note Note that `milliseconds` may be
615 /// negative.
617 void setTotalMilliseconds(bsls::Types::Int64 milliseconds);
618
619 /// Set the overall value of this object to indicate the specified integral number of `microseconds`.
620 ///
621 /// \note Note that `microseconds` may be
622 /// negative.
624 void setTotalMicroseconds(bsls::Types::Int64 microseconds);
625
626 /// Set the overall value of this object to indicate the specified integral number of `nanoseconds`.
627 ///
628 /// \note Note that `nanoseconds` may be
629 /// negative.
632
633 // Time-Interval-Based Manipulators
634
635 /// Add to this time interval the specified integral number of
636 /// `seconds`, and the optionally specified integral number of
637 /// `nanoseconds`. If unspecified, `nanoseconds` is 0. Return a
638 /// reference providing modifiable access to this object.
639 ///
640 /// \pre The behavior is undefined unless `seconds() + seconds`, and the total number of
641 /// seconds in the resulting time interval, can both be represented with
642 /// 64-bit signed integers.
644
645#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
646 /// Add to this time interval the specified `duration`. Return a
647 /// reference providing modifiable access to this object.
648 ///
649 /// \pre The behavior is undefined unless the `duration` can be converted to a valid
650 /// `TimeInterval` object, whose `seconds` field may have any
651 /// 64-bit signed integer value and `nanoseconds` field limited to the
652 /// range `[ -999,999,999..999,999,999 ]`. Also the behavior is
653 /// undefined unless the total number of seconds in the resulting time
654 /// interval can be represented with 64-bit signed integer.
655 ///
656 /// \note Note that this operation is allowed only if representation type of the
657 /// `duration` is not a floating point type and the `duration` itself
658 /// can be *exactly* represented by an integer nanoseconds.
659 template <class REP_TYPE, class PERIOD_TYPE>
661 addDuration(const std::chrono::duration<REP_TYPE, PERIOD_TYPE>& duration,
662 typename std::enable_if<
663 TimeInterval_DurationTraits<REP_TYPE, PERIOD_TYPE>::
664 k_IMPLICIT_CONVERSION_ENABLED,
665 int>::type * = 0);
666#endif
667
668 /// Set this time interval to have the value given by the sum of the
669 /// specified integral number of `seconds`, and the optionally specified
670 /// integral number of `nanoseconds`. If unspecified, `nanoseconds` is 0.
671 ///
672 /// \pre The behavior is undefined unless the total number of seconds in
673 /// the resulting time interval can be represented with a 64-bit signed integer (see `isValid`).
674 ///
675 /// \note Note that there is no restriction on the
676 /// sign or magnitude of either argument except that they must not
677 /// violate the method's preconditions.
680
681 /// Set this time interval to have the value given by the sum of the
682 /// specified integral number of `seconds`, and the optionally specified
683 /// integral number of `nanoseconds`, where `seconds` and `nanoseconds`
684 /// form a canonical representation of a time interval (see
685 /// {Representation}). If unspecified, `nanoseconds` is 0.
686 ///
687 /// \pre The behavior is undefined unless
688 /// `-999,999,999 <= nanoseconds <= +999,999,999` and `seconds` and
689 /// `nanoseconds` are either both non-negative or both non-positive.
690 ///
691 /// \note Note that this function provides a subset of the defined behavior of
692 /// `setInterval` chosen to minimize runtime performance cost.
695
696 // Aspects
697
698 /// Assign to this object the value read from the specified input
699 /// `stream` using the specified `version` format, and return a
700 /// reference to `stream`. If `stream` is initially invalid, this
701 /// operation has no effect. If `version` is not supported, this object
702 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
703 /// If `version` is supported but `stream` becomes invalid during this
704 /// operation, this object has an undefined, but valid, state.
705 ///
706 /// \note Note that no version is read from `stream`. See the `bslx` package-level
707 /// documentation for more information on BDEX streaming of
708 /// value-semantic types and containers.
709 template <class STREAM>
710 STREAM& bdexStreamIn(STREAM& stream, int version);
711
712 // ACCESSORS
713#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
714 /// Return `true` if the value of this time interval is within the valid
715 /// range of the parameterized `DURATION_TYPE`, and `false` otherwise.
716 ///
717 /// \note Note that this function does not participate in overload resolution
718 /// unless `DURATION_TYPE` is an instantiation of
719 /// `std::chrono::duration`.
720 template <class DURATION_TYPE>
721 bool isInDurationRange(
722 typename std::enable_if<TimeInterval_IsDuration<DURATION_TYPE>::value,
723 int>::type * = 0) const;
724#endif
725
726 /// Return the nanoseconds field in the canonical representation of the
727 /// value of this time interval.
729 int nanoseconds() const;
730
731 /// Return the seconds field in the canonical representation of the
732 /// value of this time interval.
735
736 /// Return the value of this time interval as an integral number of days, rounded towards zero.
737 ///
738 /// \note Note that the return value may be
739 /// negative.
742
743 /// Return the value of this time interval as an integral number of hours, rounded towards zero.
744 ///
745 /// \note Note that the return value may be
746 /// negative.
749
750 /// Return the value of this time interval as an integral number of minutes, rounded towards zero.
751 ///
752 /// \note Note that the return value may be
753 /// negative.
756
757 /// Return the value of this time interval as an integral number of seconds, rounded towards zero.
758 ///
759 /// \note Note that the return value may be
760 /// negative. Also note that this method returns the same value as
761 /// `seconds`.
764
765 /// Return the value of this time interval as an integral number of
766 /// milliseconds, rounded towards zero.
767 ///
768 /// \pre The behavior is undefined unless the number of milliseconds can be represented with a 64-bit signed integer.
769 ///
770 /// \note Note that the return value may be negative.
773
774 /// Return the value of this time interval as an integral number of
775 /// microseconds, rounded towards zero.
776 ///
777 /// \pre The behavior is undefined unless the number of microseconds can be represented with a 64-bit signed integer.
778 ///
779 /// \note Note that the return value may be negative.
782
783 /// Return the value of this time interval as an integral number of nanoseconds.
784 ///
785 /// \pre The behavior is undefined unless the number of
786 /// nanoseconds can be represented using a 64-bit signed integer.
787 ///
788 /// \note Note that the return value may be negative.
791
792#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
793 /// Return the value of this time interval as a `std::chrono::duration`
794 /// object. This function participates in overloading if
795 /// `DURATION_TYPE` is actually an `std::chrono::duration` instance, and
796 /// if it has *not* a floating point representation.
797 ///
798 /// \pre The behavior is undefined unless the total number of nanoseconds can be represented using a `DURATION_TYPE`.
799 ///
800 /// \note Note that the return value may be
801 /// negative.
802 template <class DURATION_TYPE>
804 typename std::enable_if<
805 TimeInterval_IsDuration<DURATION_TYPE>::value &&
806 !TimeInterval_RepTraits<typename DURATION_TYPE::rep>::k_IS_FLOAT,
807 DURATION_TYPE>::type
808 asDuration() const;
809#endif
810
811 /// Return the value of this time interval as a real number of seconds.
812 ///
813 /// \note Note that the return value may be negative and may have a fractional
814 /// part (representing the nanosecond field of this object). Also note
815 /// that the conversion from the internal representation to a `double`
816 /// may *lose* precision.
817 double totalSecondsAsDouble() const;
818
819 // Aspects
820
821 /// Write the value of this object, using the specified `version`
822 /// format, to the specified output `stream`, and return a reference to
823 /// `stream`. If `stream` is initially invalid, this operation has no
824 /// effect. If `version` is not supported, `stream` is invalidated, but otherwise unmodified.
825 ///
826 /// \note Note that `version` is not written to
827 /// `stream`. See the `bslx` package-level documentation for more
828 /// information on BDEX streaming of value-semantic types and
829 /// containers.
830 template <class STREAM>
831 STREAM& bdexStreamOut(STREAM& stream, int version) const;
832
833 /// Write the value of this object to the specified output `stream` in a
834 /// human-readable format, and return a reference providing modifiable
835 /// access to `stream`. Optionally specify an initial indentation
836 /// `level`, whose absolute value is incremented recursively for nested
837 /// objects. If `level` is specified, optionally specify
838 /// `spacesPerLevel`, whose absolute value indicates the number of
839 /// spaces per indentation level for this and all of its nested objects.
840 /// If `level` is negative, suppress indentation of the first line. If
841 /// `spacesPerLevel` is negative, format the entire output on one line,
842 /// suppressing all but the initial indentation (as governed by
843 /// `level`). If `stream` is not valid on entry, this operation has no effect.
844 ///
845 /// \note Note that the format is not fully specified, and can change
846 /// without notice.
847 std::ostream& print(std::ostream& stream,
848 int level = 0,
849 int spacesPerLevel = 4) const;
850
851#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
852 // DEPRECATED
853
854 /// Return the most current BDEX streaming version number supported by
855 /// this class.
856 ///
857 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
858 static int maxSupportedBdexVersion();
859
860#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
861#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
862
863 /// Return the most current BDEX streaming version number supported by
864 /// this class.
865 ///
866 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
867 static int maxSupportedVersion();
868
869 /// Format this time to the specified output `stream`, and return a
870 /// reference to the modifiable `stream`.
871 ///
872 /// @deprecated Use @ref print instead.
873 template <class STREAM>
874 STREAM& streamOut(STREAM& stream) const;
875
876#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
877
878};
879
880// FREE OPERATORS
881
882/// Return a `TimeInterval` value that is the sum of the specified `lhs` and `rhs` time intervals.
883///
884/// \pre The behavior is undefined unless (1) operands of
885/// type `double` can be converted to valid `TimeInterval` objects, and (2)
886/// the resulting time interval can be represented with a 64-bit signed
887/// integer.
889TimeInterval operator+(const TimeInterval& lhs, double rhs);
890TimeInterval operator+(double lhs, const TimeInterval& rhs);
891
892/// Return a `TimeInterval` value that is the difference between the
893/// specified `lhs` and `rhs` time intervals.
894///
895/// \pre The behavior is undefined unless (1) operands of type `double` can be converted to valid
896/// `TimeInterval` objects, (2) the value on the right-hand side
897/// (potentially after conversion to a `TimeInterval`) has a number of
898/// seconds that is not `LLONG_MIN`, and (3) the resulting time interval can
899/// be represented with a 64-bit signed integer.
901TimeInterval operator-(const TimeInterval& lhs, double rhs);
902TimeInterval operator-(double lhs, const TimeInterval& rhs);
903
904/// Return a `TimeInterval` value that is the negative of the specified `rhs` time interval.
905///
906/// \pre The behavior is undefined unless
907/// `LLONG_MIN != rhs.seconds()`.
909
910/// Return `true` if the specified `lhs` and `rhs` time intervals have the
911/// same value, and `false` otherwise. Two time intervals have the same
912/// value if their respective second and nanosecond fields have the same value.
913///
914/// \pre The behavior is undefined unless operands of type `double` can
915/// be converted to valid `TimeInterval` objects.
916bool operator==(const TimeInterval& lhs, const TimeInterval& rhs);
917bool operator==(const TimeInterval& lhs, double rhs);
918bool operator==(double lhs, const TimeInterval& rhs);
919
920/// Return `true` if the specified `lhs` and `rhs` time intervals do not
921/// have the same value, and `false` otherwise. Two time intervals do not
922/// have the same value if their respective second or nanosecond fields differ in value.
923///
924/// \pre The behavior is undefined unless operands of type
925/// `double` can be converted to valid `TimeInterval` objects.
926bool operator!=(const TimeInterval& lhs, const TimeInterval& rhs);
927bool operator!=(const TimeInterval& lhs, double rhs);
928bool operator!=(double lhs, const TimeInterval& rhs);
929
930/// Return `true` if the nominal relation between the specified `lhs` and
931/// `rhs` time interval values holds, and `false` otherwise.
932///
933/// \pre The behavior is undefined unless operands of type `double` can be converted to valid
934/// `TimeInterval` objects.
935bool operator< (const TimeInterval& lhs, const TimeInterval& rhs);
936bool operator< (const TimeInterval& lhs, double rhs);
937bool operator< (double lhs, const TimeInterval& rhs);
938bool operator<=(const TimeInterval& lhs, const TimeInterval& rhs);
939bool operator<=(const TimeInterval& lhs, double rhs);
940bool operator<=(double lhs, const TimeInterval& rhs);
941bool operator> (const TimeInterval& lhs, const TimeInterval& rhs);
942bool operator> (const TimeInterval& lhs, double rhs);
943bool operator> (double lhs, const TimeInterval& rhs);
944bool operator>=(const TimeInterval& lhs, const TimeInterval& rhs);
945bool operator>=(const TimeInterval& lhs, double rhs);
946bool operator>=(double lhs, const TimeInterval& rhs);
947
948/// Write the value of the specified `timeInterval` to the specified output
949/// `stream` in a single-line format, and return a reference providing
950/// modifiable access to `stream`. If `stream` is not valid on entry, this operation has no effect.
951///
952/// \note Note that this human-readable format is not
953/// fully specified and can change without notice. Also note that this
954/// method has the same behavior as `object.print(stream, 0, -1)`.
955std::ostream& operator<<(std::ostream& stream,
956 const TimeInterval& timeInterval);
957
958#if defined(BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE) && \
959 defined(BSLS_COMPILERFEATURES_SUPPORT_USER_DEFINED_LITERALS)
960inline namespace literals {
961inline namespace TimeIntervalLiterals {
962
963/// This user defined literal operator converts the specified `hours` value
964/// to the respective `TimeInterval` value.
965///
966/// \pre The behavior is undefined unless the specified number of hours can be converted to valid
967/// `TimeInterval` object. (See the
968/// "User-Defined Literals" section in the component-level documentation.)
970TimeInterval operator ""_h( unsigned long long int hours);
971
972/// This user defined literal operator converts the specified `minutes`
973/// value to the respective `TimeInterval` value.
974///
975/// \pre The behavior is undefined unless the specified number of minutes can be converted to valid
976/// `TimeInterval` object. (See the
977/// "User-Defined Literals" section in the component-level documentation.)
979TimeInterval operator ""_min(unsigned long long int minutes);
980
981/// This user defined literal operator converts the specified `seconds`
982/// value to the respective `TimeInterval` value.
983///
984/// \pre The behavior is undefined unless the specified number of seconds can be converted to valid
985/// `TimeInterval` object. (See the
986/// "User-Defined Literals" section in the component-level documentation.)
988TimeInterval operator ""_s( unsigned long long int seconds);
989
990/// This user defined literal operator converts the specified `milliseconds`
991/// value to the respective `TimeInterval` value. (See the
992/// "User-Defined Literals" section in the component-level documentation.)
994TimeInterval operator ""_ms( unsigned long long int milliseconds);
995
996/// This user defined literal operator converts the specified `microseconds`
997/// value to the respective `TimeInterval` value. (See the
998/// "User-Defined Literals" section in the component-level documentation.)
1000TimeInterval operator ""_us( unsigned long long int microseconds);
1001
1002/// This user defined literal operator converts the specified `nanoseconds`
1003/// value to the respective `TimeInterval` value. (See the
1004/// "User-Defined Literals" section in the component-level documentation.)
1006TimeInterval operator ""_ns( unsigned long long int nanoseconds);
1007
1008} // close TimeIntervalLiterals namespace
1009} // close literals namespace
1010#endif // BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE &&
1011 // BSLS_COMPILERFEATURES_SUPPORT_USER_DEFINED_LITERALS
1012
1013// ============================================================================
1014// INLINE DEFINITIONS
1015// ============================================================================
1016
1017 // ------------------
1018 // class TimeInterval
1019 // ------------------
1020
1021// PRIVATE CLASS METHODS
1023bool TimeInterval::isSumValidInt64(bsls::Types::Int64 lhs,
1025{
1026 // {DRQS 164912552} Sun CC miscomplies this ternary operator when the
1027 // function is invoked from the 'TimeInterval' constructor.
1028 // return lhs > 0 ? LLONG_MAX - lhs >= rhs : LLONG_MIN - lhs <= rhs;
1029 return (lhs > 0 && LLONG_MAX - lhs >= rhs) ||
1030 (lhs <= 0 && LLONG_MIN - lhs <= rhs);
1031}
1032
1033// CLASS METHODS
1034inline
1035int TimeInterval::maxSupportedBdexVersion(int /* versionSelector */)
1036{
1037 return 1;
1038}
1039
1042 int nanoseconds)
1043{
1044 return isSumValidInt64(seconds, nanoseconds / k_NANOSECS_PER_SEC);
1045}
1046
1047#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1048
1049template <class REP, class PERIOD>
1050bool TimeInterval::isValid(const std::chrono::duration<REP, PERIOD>& duration)
1051{
1052 std::chrono::duration<long double> minValue =
1053 std::chrono::duration<long double>(LLONG_MIN);
1054 --minValue;
1055 std::chrono::duration<long double> maxValue =
1056 std::chrono::duration<long double>(LLONG_MAX);
1057 ++maxValue;
1058 const std::chrono::duration<long double> safeDuration =
1059 std::chrono::duration_cast<std::chrono::duration<long double> >(
1060 duration);
1061
1062 return (safeDuration >= minValue && safeDuration <= maxValue);
1063}
1064#endif // BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1065
1066// CREATORS
1069: d_seconds(0)
1070, d_nanoseconds(0)
1071{
1072}
1073
1076 int nanoseconds)
1077: d_seconds(0)
1078, d_nanoseconds(0)
1079{
1080 // A seemingly redundant initializer list is needed since members must be
1081 // initialized by mem-initializer in 'constexpr' constructor.
1082
1084}
1085
1086#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1087template <class REP_TYPE, class PERIOD_TYPE>
1088inline
1091 const std::chrono::duration<REP_TYPE, PERIOD_TYPE>& duration,
1092 typename std::enable_if<TimeInterval_DurationTraits<
1093 REP_TYPE,
1094 PERIOD_TYPE>::k_IMPLICIT_CONVERSION_ENABLED,
1095 int>::type *)
1096{
1097 BSLS_ASSERT((isValid<REP_TYPE, PERIOD_TYPE>(duration)));
1098 using SecondsRatio = std::ratio<1>;
1099 using TimeIntervalSeconds =
1100 std::chrono::duration<bsls::Types::Int64, SecondsRatio>;
1101 using TimeIntervalNanoseconds = std::chrono::duration<int, std::nano>;
1102
1103 const bsls::Types::Int64 k_SECONDS =
1104 std::chrono::duration_cast<TimeIntervalSeconds>(duration).count();
1105 const int k_NANOSECONDS =
1106 std::chrono::duration_cast<TimeIntervalNanoseconds>(
1107 duration - TimeIntervalSeconds(k_SECONDS)).count();
1108 setInterval(k_SECONDS, k_NANOSECONDS);
1109}
1110
1111template <class REP_TYPE, class PERIOD_TYPE>
1112inline
1115 const std::chrono::duration<REP_TYPE, PERIOD_TYPE>& duration,
1116 typename std::enable_if<TimeInterval_DurationTraits<
1117 REP_TYPE,
1118 PERIOD_TYPE>::k_EXPLICIT_CONVERSION_ENABLED,
1119 int>::type *)
1120{
1121 BSLS_ASSERT((isValid<REP_TYPE, PERIOD_TYPE>(duration)));
1122 const bsls::Types::Int64 k_SECONDS =
1123 std::chrono::duration_cast<std::chrono::seconds>(duration).count();
1124 const int k_NANOSECONDS = static_cast<int>(
1125 std::chrono::duration_cast<std::chrono::nanoseconds>(
1126 duration - std::chrono::seconds(k_SECONDS)).count());
1127 setInterval(k_SECONDS, k_NANOSECONDS);
1128}
1129#endif
1130
1131// MANIPULATORS
1132inline
1134{
1135 *this = TimeInterval(rhs);
1136 return *this;
1137}
1138
1139inline
1141{
1142 return addInterval(rhs.d_seconds, rhs.d_nanoseconds);
1143}
1144
1145inline
1147{
1148 *this += TimeInterval(rhs);
1149 return *this;
1150}
1151
1152inline
1154{
1155 BSLS_ASSERT_SAFE(LLONG_MIN < rhs.seconds());
1156
1157 return addInterval(-rhs.d_seconds, -rhs.d_nanoseconds);
1158}
1159
1160inline
1162{
1163 *this -= TimeInterval(rhs);
1164 return *this;
1165}
1166
1167 // Add Operations
1168
1171{
1172 BSLS_ASSERT_SAFE(LLONG_MAX / k_SECONDS_PER_DAY >= days &&
1173 LLONG_MIN / k_SECONDS_PER_DAY <= days);
1174
1175 return addSeconds(days * k_SECONDS_PER_DAY);
1176}
1177
1180{
1181 BSLS_ASSERT_SAFE(LLONG_MAX / k_SECONDS_PER_HOUR >= hours &&
1182 LLONG_MIN / k_SECONDS_PER_HOUR <= hours);
1183
1184 return addSeconds(hours * k_SECONDS_PER_HOUR);
1185}
1186
1189{
1190 BSLS_ASSERT_SAFE(LLONG_MAX / k_SECONDS_PER_MINUTE >= minutes &&
1191 LLONG_MIN / k_SECONDS_PER_MINUTE <= minutes);
1192
1193 return addSeconds(minutes * k_SECONDS_PER_MINUTE);
1194}
1195
1198{
1199 BSLS_ASSERT_SAFE(isSumValidInt64(seconds, d_seconds));
1200
1201 d_seconds += seconds;
1202 if (d_seconds > 0 && d_nanoseconds < 0) {
1203 --d_seconds;
1204 d_nanoseconds += k_NANOSECS_PER_SEC;
1205 }
1206 else if (d_seconds < 0 && d_nanoseconds > 0) {
1207 ++d_seconds;
1208 d_nanoseconds -= k_NANOSECS_PER_SEC;
1209 }
1210
1211 return *this;
1212}
1213
1214inline
1216{
1217 return addInterval( milliseconds / k_MILLISECS_PER_SEC,
1218 static_cast<int>((milliseconds % k_MILLISECS_PER_SEC) *
1219 k_NANOSECS_PER_MILLISEC));
1220}
1221
1222inline
1224{
1225 return addInterval( microseconds / k_MICROSECS_PER_SEC,
1226 static_cast<int>((microseconds % k_MICROSECS_PER_SEC) *
1227 k_NANOSECS_PER_MICROSEC));
1228}
1229
1230inline
1232{
1233 return addInterval( nanoseconds / k_NANOSECS_PER_SEC,
1234 static_cast<int>(nanoseconds % k_NANOSECS_PER_SEC));
1235}
1236
1237 // Set Operations
1238
1241{
1242 BSLS_ASSERT_SAFE(LLONG_MAX / k_SECONDS_PER_DAY >= days &&
1243 LLONG_MIN / k_SECONDS_PER_DAY <= days);
1244
1245 return setTotalSeconds(days * k_SECONDS_PER_DAY);
1246}
1247
1250{
1251 BSLS_ASSERT_SAFE(LLONG_MAX / k_SECONDS_PER_HOUR >= hours &&
1252 LLONG_MIN / k_SECONDS_PER_HOUR <= hours);
1253
1254 return setTotalSeconds(hours * k_SECONDS_PER_HOUR);
1255}
1256
1259{
1260 BSLS_ASSERT_SAFE(LLONG_MAX / k_SECONDS_PER_MINUTE >= minutes &&
1261 LLONG_MIN / k_SECONDS_PER_MINUTE <= minutes);
1262
1263 return setTotalSeconds(minutes * k_SECONDS_PER_MINUTE);
1264}
1265
1268{
1269 d_seconds = seconds;
1270 d_nanoseconds = 0;
1271}
1272
1275{
1276 setInterval( milliseconds / k_MILLISECS_PER_SEC,
1277 static_cast<int>((milliseconds % k_MILLISECS_PER_SEC) *
1278 k_NANOSECS_PER_MILLISEC));
1279}
1280
1283{
1284 setInterval( microseconds / k_MICROSECS_PER_SEC,
1285 static_cast<int>((microseconds % k_MICROSECS_PER_SEC) *
1286 k_NANOSECS_PER_MICROSEC));
1287
1288}
1289
1292{
1293 setInterval( nanoseconds / k_NANOSECS_PER_SEC,
1294 static_cast<int>(nanoseconds % k_NANOSECS_PER_SEC));
1295}
1296
1297#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1298template <class REP_TYPE, class PERIOD_TYPE>
1299inline
1301TimeInterval::addDuration(
1302 const std::chrono::duration<REP_TYPE, PERIOD_TYPE>& duration,
1303 typename std::enable_if<TimeInterval_DurationTraits<
1304 REP_TYPE,
1305 PERIOD_TYPE>::k_IMPLICIT_CONVERSION_ENABLED,
1306 int>::type *)
1307{
1308 BSLS_ASSERT((isValid<REP_TYPE, PERIOD_TYPE>(duration)));
1309
1310 const bsls::Types::Int64 k_SECONDS =
1311 std::chrono::duration_cast<std::chrono::seconds>(duration).count();
1312 const int k_NANOSECONDS = static_cast<int>(
1313 std::chrono::duration_cast<std::chrono::nanoseconds>(
1314 duration - std::chrono::seconds(k_SECONDS)).count());
1315 return addInterval(k_SECONDS, k_NANOSECONDS);
1316}
1317#endif
1318
1321 int nanoseconds)
1322{
1326
1327 d_seconds = seconds;
1328 if (nanoseconds >= k_NANOSECS_PER_SEC
1329 || nanoseconds <= -k_NANOSECS_PER_SEC) {
1330 d_seconds += nanoseconds / k_NANOSECS_PER_SEC;
1331 d_nanoseconds = static_cast<int>(nanoseconds % k_NANOSECS_PER_SEC);
1332 }
1333 else {
1334 d_nanoseconds = static_cast<int>(nanoseconds);
1335 }
1336
1337 if (d_seconds > 0 && d_nanoseconds < 0) {
1338 --d_seconds;
1339 d_nanoseconds += k_NANOSECS_PER_SEC;
1340 }
1341 else if (d_seconds < 0 && d_nanoseconds > 0) {
1342 ++d_seconds;
1343 d_nanoseconds -= k_NANOSECS_PER_SEC;
1344 }
1345
1346}
1347
1350 int nanoseconds)
1351{
1352 BSLS_ASSERT_SAFE(-k_NANOSECS_PER_SEC < nanoseconds &&
1353 k_NANOSECS_PER_SEC > nanoseconds);
1354 BSLS_ASSERT_SAFE((seconds >= 0 && nanoseconds >= 0) ||
1355 (seconds <= 0 && nanoseconds <= 0));
1356
1357 d_seconds = seconds;
1358 d_nanoseconds = nanoseconds;
1359}
1360
1361 // Aspects
1362
1363template <class STREAM>
1364STREAM& TimeInterval::bdexStreamIn(STREAM& stream, int version)
1365{
1366 if (stream) {
1367 switch (version) { // switch on the schema version
1368 case 1: {
1370 int nanoseconds = 0;
1371 stream.getInt64(seconds);
1372 stream.getInt32(nanoseconds);
1373
1374 if (stream && ( (seconds >= 0 && nanoseconds >= 0)
1375 || (seconds <= 0 && nanoseconds <= 0))
1376 && nanoseconds > -k_NANOSECS_PER_SEC
1377 && nanoseconds < k_NANOSECS_PER_SEC) {
1378 d_seconds = seconds;
1379 d_nanoseconds = nanoseconds;
1380 }
1381 else {
1382 stream.invalidate();
1383 }
1384 } break;
1385 default: {
1386 stream.invalidate(); // unrecognized version number
1387 }
1388 }
1389 }
1390 return stream;
1391}
1392
1393// ACCESSORS
1394#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1395template <class DURATION_TYPE>
1396bool TimeInterval::isInDurationRange(
1397 typename std::enable_if<TimeInterval_IsDuration<DURATION_TYPE>::value,
1398 int>::type *) const
1399{
1400 using SecondsRatio = std::ratio<1>;
1401 using TimeIntervalSeconds =
1402 std::chrono::duration<bsls::Types::Int64, SecondsRatio>;
1403 using TimeIntervalNanoseconds = std::chrono::duration<int, std::nano>;
1404 using Period = typename DURATION_TYPE::period;
1405 using LongDoubleTo = std::chrono::duration<long double, Period>;
1406
1407 const LongDoubleTo MIN_VALUE =
1408 std::chrono::duration_cast<LongDoubleTo>(DURATION_TYPE::min());
1409
1410 const LongDoubleTo MAX_VALUE =
1411 std::chrono::duration_cast<LongDoubleTo>(DURATION_TYPE::max());
1412
1413 const LongDoubleTo value = std::chrono::duration_cast<LongDoubleTo>(
1414 TimeIntervalSeconds(seconds()))
1415 + std::chrono::duration_cast<LongDoubleTo>(
1416 TimeIntervalNanoseconds(nanoseconds()));
1417
1418 return (MIN_VALUE <= value && value <= MAX_VALUE);
1419}
1420#endif // BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1421
1424{
1425 return d_nanoseconds;
1426}
1427
1430{
1431 return d_seconds;
1432}
1433
1436{
1437 return d_seconds / k_SECONDS_PER_DAY;
1438}
1439
1442{
1443 return d_seconds / k_SECONDS_PER_HOUR;
1444}
1445
1448{
1449 return d_seconds / k_SECONDS_PER_MINUTE;
1450}
1451
1454{
1455 return d_seconds;
1456}
1457
1460{
1461 BSLS_ASSERT_SAFE(LLONG_MAX / k_MILLISECS_PER_SEC >= d_seconds &&
1462 LLONG_MIN / k_MILLISECS_PER_SEC <= d_seconds);
1463 BSLS_ASSERT_SAFE(isSumValidInt64(d_seconds * k_MILLISECS_PER_SEC,
1464 d_nanoseconds / k_NANOSECS_PER_MILLISEC));
1465
1466
1467 return d_seconds * k_MILLISECS_PER_SEC
1468 + d_nanoseconds / k_NANOSECS_PER_MILLISEC;
1469}
1470
1473{
1474 BSLS_ASSERT_SAFE(LLONG_MAX / k_MICROSECS_PER_SEC >= d_seconds &&
1475 LLONG_MIN / k_MICROSECS_PER_SEC <= d_seconds);
1476 BSLS_ASSERT_SAFE(isSumValidInt64(d_seconds * k_MICROSECS_PER_SEC,
1477 d_nanoseconds / k_NANOSECS_PER_MICROSEC));
1478
1479 return d_seconds * k_MICROSECS_PER_SEC
1480 + d_nanoseconds / k_NANOSECS_PER_MICROSEC;
1481}
1482
1485{
1486 BSLS_ASSERT_SAFE(LLONG_MAX / k_NANOSECS_PER_SEC >= d_seconds &&
1487 LLONG_MIN / k_NANOSECS_PER_SEC <= d_seconds);
1488 BSLS_ASSERT_SAFE(isSumValidInt64(d_seconds * k_NANOSECS_PER_SEC,
1489 d_nanoseconds));
1490
1491 return d_seconds * k_NANOSECS_PER_SEC + d_nanoseconds;
1492}
1493
1494#ifdef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1495template <class DURATION_TYPE>
1496inline
1498typename std::enable_if<
1499 TimeInterval_IsDuration<DURATION_TYPE>::value &&
1500 !TimeInterval_RepTraits<typename DURATION_TYPE::rep>::k_IS_FLOAT,
1501 DURATION_TYPE>::type
1502TimeInterval::asDuration() const
1503{
1504 using SecondsRatio = std::ratio<1>;
1505 using TimeIntervalSeconds =
1506 std::chrono::duration<bsls::Types::Int64, SecondsRatio>;
1507 using TimeIntervalNanoseconds = std::chrono::duration<int, std::nano>;
1508
1509 BSLS_ASSERT(isInDurationRange<DURATION_TYPE>());
1510
1511 return (std::chrono::duration_cast<DURATION_TYPE>(TimeIntervalSeconds(
1512 d_seconds))
1513 + std::chrono::duration_cast<DURATION_TYPE>(TimeIntervalNanoseconds(
1514 d_nanoseconds)));
1515}
1516#endif
1517
1518inline
1520{
1521 return static_cast<double>(d_seconds) + d_nanoseconds /
1522 static_cast<double>(k_NANOSECS_PER_SEC);
1523}
1524
1525 // Aspects
1526
1527template <class STREAM>
1528STREAM& TimeInterval::bdexStreamOut(STREAM& stream, int version) const
1529{
1530 if (stream) {
1531 switch (version) { // switch on the schema version
1532 case 1: {
1533 stream.putInt64(d_seconds);
1534 stream.putInt32(d_nanoseconds);
1535 } break;
1536 default: {
1537 stream.invalidate(); // unrecognized version number
1538 }
1539 }
1540 }
1541 return stream;
1542}
1543
1544
1545#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
1546
1547// DEPRECATED METHODS
1548inline
1553
1554#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
1555#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
1556inline
1561
1562template <class STREAM>
1563inline
1564STREAM& TimeInterval::streamOut(STREAM& stream) const
1565{
1566 return print(stream, 0, -1);
1567}
1568
1569#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
1570
1571} // close package namespace
1572
1573// FREE OPERATORS
1574inline
1575bsls::TimeInterval bsls::operator+(const TimeInterval& lhs,
1576 const TimeInterval& rhs)
1577{
1578 TimeInterval result(lhs);
1579 return result.addInterval(rhs.seconds(), rhs.nanoseconds());
1580}
1581
1582inline
1583bsls::TimeInterval bsls::operator+(const TimeInterval& lhs, double rhs)
1584{
1585 return lhs + TimeInterval(rhs);
1586}
1587
1588inline
1589bsls::TimeInterval bsls::operator+(double lhs, const TimeInterval& rhs)
1590{
1591 return TimeInterval(lhs) + rhs;
1592}
1593
1594inline
1595bsls::TimeInterval bsls::operator-(const TimeInterval& lhs,
1596 const TimeInterval& rhs)
1597
1598{
1599 BSLS_ASSERT_SAFE(LLONG_MIN != rhs.seconds());
1600
1601 TimeInterval result(lhs);
1602 result.addInterval(-rhs.seconds(), -rhs.nanoseconds());
1603 return result;
1604}
1605
1606inline
1607bsls::TimeInterval bsls::operator-(const TimeInterval& lhs, double rhs)
1608{
1609 return lhs - TimeInterval(rhs);
1610}
1611
1612inline
1613bsls::TimeInterval bsls::operator-(double lhs, const TimeInterval& rhs)
1614{
1615 return TimeInterval(lhs) - rhs;
1616}
1617
1618inline
1619bsls::TimeInterval bsls::operator-(const TimeInterval& rhs)
1620{
1621 BSLS_ASSERT_SAFE(LLONG_MIN != rhs.seconds());
1622
1623 return TimeInterval(-rhs.seconds(), -rhs.nanoseconds());
1624}
1625
1626inline
1627bool bsls::operator==(const TimeInterval& lhs, const TimeInterval& rhs)
1628{
1629 return lhs.seconds() == rhs.seconds()
1630 && lhs.nanoseconds() == rhs.nanoseconds();
1631}
1632
1633inline
1634bool bsls::operator==(const TimeInterval& lhs, double rhs)
1635{
1636 return lhs == TimeInterval(rhs);
1637}
1638
1639inline
1640bool bsls::operator==(double lhs, const TimeInterval& rhs)
1641{
1642 return TimeInterval(lhs) == rhs;
1643}
1644
1645inline
1646bool bsls::operator!=(const TimeInterval& lhs, const TimeInterval& rhs)
1647{
1648 return lhs.seconds() != rhs.seconds()
1649 || lhs.nanoseconds() != rhs.nanoseconds();
1650}
1651
1652inline
1653bool bsls::operator!=(const TimeInterval& lhs, double rhs)
1654{
1655 return lhs != TimeInterval(rhs);
1656}
1657
1658inline
1659bool bsls::operator!=(double lhs, const TimeInterval& rhs)
1660{
1661 return TimeInterval(lhs) != rhs;
1662}
1663
1664inline
1665bool bsls::operator< (const TimeInterval& lhs, const TimeInterval& rhs)
1666{
1667 return lhs.seconds() < rhs.seconds()
1668 || (lhs.seconds() == rhs.seconds()
1669 && lhs.nanoseconds() < rhs.nanoseconds());
1670}
1671
1672inline
1673bool bsls::operator< (const TimeInterval& lhs, double rhs)
1674{
1675 return lhs < TimeInterval(rhs);
1676}
1677
1678inline
1679bool bsls::operator< (double lhs, const TimeInterval& rhs)
1680{
1681 return TimeInterval(lhs) < rhs;
1682}
1683
1684inline
1685bool bsls::operator<=(const TimeInterval& lhs, const TimeInterval& rhs)
1686{
1687 return lhs.seconds() < rhs.seconds()
1688 || (lhs.seconds() == rhs.seconds()
1689 && lhs.nanoseconds() <= rhs.nanoseconds());
1690}
1691
1692inline
1693bool bsls::operator<=(const TimeInterval& lhs, double rhs)
1694{
1695 return lhs <= TimeInterval(rhs);
1696}
1697
1698inline
1699bool bsls::operator<=(double lhs, const TimeInterval& rhs)
1700{
1701 return TimeInterval(lhs) <= rhs;
1702}
1703
1704inline
1705bool bsls::operator> (const TimeInterval& lhs, const TimeInterval& rhs)
1706{
1707 return lhs.seconds() > rhs.seconds()
1708 || (lhs.seconds() == rhs.seconds()
1709 && lhs.nanoseconds() > rhs.nanoseconds());
1710}
1711
1712inline
1713bool bsls::operator> (const TimeInterval& lhs, double rhs)
1714{
1715 return lhs > TimeInterval(rhs);
1716}
1717
1718inline
1719bool bsls::operator> (double lhs, const TimeInterval& rhs)
1720{
1721 return TimeInterval(lhs) > rhs;
1722}
1723
1724inline
1725bool bsls::operator>=(const TimeInterval& lhs, const TimeInterval& rhs)
1726{
1727 return lhs.seconds() > rhs.seconds()
1728 || (lhs.seconds() == rhs.seconds()
1729 && lhs.nanoseconds() >= rhs.nanoseconds());
1730}
1731
1732inline
1733bool bsls::operator>=(const TimeInterval& lhs, double rhs)
1734{
1735 return lhs >= TimeInterval(rhs);
1736}
1737
1738inline
1739bool bsls::operator>=(double lhs, const TimeInterval& rhs)
1740{
1741 return TimeInterval(lhs) >= rhs;
1742}
1743
1744#if defined(BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE) && \
1745 defined(BSLS_COMPILERFEATURES_SUPPORT_USER_DEFINED_LITERALS)
1746
1748bsls::TimeInterval bsls::TimeIntervalLiterals::operator""_h(
1749 unsigned long long int hours)
1750{
1751 BSLS_ASSERT((LLONG_MAX/3600) >= hours);
1752 return TimeInterval(static_cast<bsls::Types::Int64>(hours*3600), 0);
1753}
1754
1756bsls::TimeInterval bsls::TimeIntervalLiterals::operator""_min(
1757 unsigned long long int minutes)
1758{
1759 BSLS_ASSERT((LLONG_MAX/60) >= minutes);
1760 return TimeInterval(static_cast<bsls::Types::Int64>(minutes*60), 0);
1761}
1762
1764bsls::TimeInterval bsls::TimeIntervalLiterals::operator""_s(
1765 unsigned long long int seconds)
1766{
1767 BSLS_ASSERT(LLONG_MAX > seconds);
1768 return TimeInterval(static_cast<bsls::Types::Int64>(seconds), 0);
1769}
1770
1772bsls::TimeInterval bsls::TimeIntervalLiterals::operator""_ms(
1773 unsigned long long int milliseconds)
1774{
1775 const bsls::Types::Int64 k_MILLISECS_PER_SEC = 1000;
1776 const bsls::Types::Int64 k_NANOSECS_PER_MILLISEC = 1000000;
1777
1778 return TimeInterval(milliseconds / k_MILLISECS_PER_SEC,
1779 static_cast<int>((milliseconds % k_MILLISECS_PER_SEC) *
1780 k_NANOSECS_PER_MILLISEC));
1781}
1782
1784bsls::TimeInterval bsls::TimeIntervalLiterals::operator""_us(
1785 unsigned long long int microseconds)
1786{
1787 const bsls::Types::Int64 k_MICROSECS_PER_SEC = 1000000;
1788 const bsls::Types::Int64 k_NANOSECS_PER_MICROSEC = 1000;
1789
1790 return TimeInterval(microseconds / k_MICROSECS_PER_SEC,
1791 static_cast<int>((microseconds % k_MICROSECS_PER_SEC) *
1792 k_NANOSECS_PER_MICROSEC));
1793}
1794
1796bsls::TimeInterval bsls::TimeIntervalLiterals::operator""_ns(
1797 unsigned long long int nanoseconds)
1798{
1799 const bsls::Types::Int64 k_NANOSECS_PER_SEC = 1000000000;
1800
1801 return TimeInterval(nanoseconds / k_NANOSECS_PER_SEC,
1802 static_cast<int>(nanoseconds % k_NANOSECS_PER_SEC));
1803}
1804
1805#endif // BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE &&
1806 // BSLS_COMPILERFEATURES_SUPPORT_USER_DEFINED_LITERALS
1807
1808// BDE_VERIFY pragma: pop
1809
1810// IMPLEMENTATION NOTE: A 'is_trivially_copyable' trait declaration has been
1811// moved to 'bslmf_istriviallycopyable.h' to work around issues on the Sun CC
1812// 5.13 compiler. We had previously forward declared
1813// 'bsl::is_trivially_copyable' and specialized it for 'TimeInterval' here (see
1814// the 2.24 release tags).
1815//..
1816// namespace bsl {
1817// template <>
1818// struct is_trivially_copyable<BloombergLP::bsls::TimeInterval> :
1819// bsl::true_type {
1820// // This template specialization for 'is_trivially_copyable' indicates
1821// // that 'Date' is a trivially copyable type.
1822// };
1823// }
1824//..
1825
1826
1827
1828#undef BSLS_TIMEINTERVAL_PROVIDES_CHRONO_CONVERSIONS
1829
1830#endif
1831
1832// ----------------------------------------------------------------------------
1833// Copyright 2020 Bloomberg Finance L.P.
1834//
1835// Licensed under the Apache License, Version 2.0 (the "License");
1836// you may not use this file except in compliance with the License.
1837// You may obtain a copy of the License at
1838//
1839// http://www.apache.org/licenses/LICENSE-2.0
1840//
1841// Unless required by applicable law or agreed to in writing, software
1842// distributed under the License is distributed on an "AS IS" BASIS,
1843// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1844// See the License for the specific language governing permissions and
1845// limitations under the License.
1846// ----------------------------- END-OF-FILE ----------------------------------
1847
1848/** @} */
1849/** @} */
1850/** @} */
Definition bsls_timeinterval.h:307
BSLS_KEYWORD_CONSTEXPR bsls::Types::Int64 totalMinutes() const
Definition bsls_timeinterval.h:1447
BSLS_KEYWORD_CONSTEXPR TimeInterval()
Definition bsls_timeinterval.h:1068
BSLS_KEYWORD_CONSTEXPR_CPP14 void setTotalHours(bsls::Types::Int64 hours)
Definition bsls_timeinterval.h:1249
TimeInterval & addMicroseconds(bsls::Types::Int64 microseconds)
Definition bsls_timeinterval.h:1223
BSLS_KEYWORD_CONSTEXPR_CPP14 void setTotalDays(bsls::Types::Int64 days)
Definition bsls_timeinterval.h:1240
BSLS_KEYWORD_CONSTEXPR int nanoseconds() const
Definition bsls_timeinterval.h:1423
~TimeInterval()=default
TimeInterval & operator-=(const TimeInterval &rhs)
Definition bsls_timeinterval.h:1153
TimeInterval & addNanoseconds(bsls::Types::Int64 nanoseconds)
Definition bsls_timeinterval.h:1231
TimeInterval & addInterval(bsls::Types::Int64 seconds, int nanoseconds=0)
BSLS_KEYWORD_CONSTEXPR_CPP14 void setTotalNanoseconds(bsls::Types::Int64 nanoseconds)
Definition bsls_timeinterval.h:1291
BSLS_KEYWORD_CONSTEXPR_CPP14 void setTotalSeconds(bsls::Types::Int64 seconds)
Definition bsls_timeinterval.h:1267
BSLS_KEYWORD_CONSTEXPR bsls::Types::Int64 totalSeconds() const
Definition bsls_timeinterval.h:1453
TimeInterval & operator=(const TimeInterval &rhs)=default
TimeInterval & addMilliseconds(bsls::Types::Int64 milliseconds)
Definition bsls_timeinterval.h:1215
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bsls_timeinterval.h:1364
BSLS_KEYWORD_CONSTEXPR_CPP14 void setTotalMinutes(bsls::Types::Int64 minutes)
Definition bsls_timeinterval.h:1258
BSLS_KEYWORD_CONSTEXPR_CPP14 TimeInterval & addHours(bsls::Types::Int64 hours)
Definition bsls_timeinterval.h:1179
BSLS_KEYWORD_CONSTEXPR_CPP14 void setTotalMilliseconds(bsls::Types::Int64 milliseconds)
Definition bsls_timeinterval.h:1274
TimeInterval & operator+=(const TimeInterval &rhs)
Definition bsls_timeinterval.h:1140
BSLS_KEYWORD_CONSTEXPR_CPP14 bsls::Types::Int64 totalMicroseconds() const
Definition bsls_timeinterval.h:1472
static BSLS_KEYWORD_CONSTEXPR bool isValid(bsls::Types::Int64 seconds, int nanoseconds)
Definition bsls_timeinterval.h:1041
double totalSecondsAsDouble() const
Definition bsls_timeinterval.h:1519
STREAM & streamOut(STREAM &stream) const
Definition bsls_timeinterval.h:1564
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bsls_timeinterval.h:1528
std::ostream & print(std::ostream &stream, int level=0, int spacesPerLevel=4) const
BSLS_KEYWORD_CONSTEXPR_CPP14 void setIntervalRaw(bsls::Types::Int64 seconds, int nanoseconds=0)
Definition bsls_timeinterval.h:1349
TimeInterval(double seconds)
static int maxSupportedBdexVersion()
Definition bsls_timeinterval.h:1549
BSLS_KEYWORD_CONSTEXPR_CPP14 bsls::Types::Int64 totalNanoseconds() const
Definition bsls_timeinterval.h:1484
BSLS_KEYWORD_CONSTEXPR bsls::Types::Int64 totalDays() const
Definition bsls_timeinterval.h:1435
BSLS_KEYWORD_CONSTEXPR bsls::Types::Int64 seconds() const
Definition bsls_timeinterval.h:1429
BSLS_KEYWORD_CONSTEXPR bsls::Types::Int64 totalHours() const
Definition bsls_timeinterval.h:1441
TimeInterval(const TimeInterval &original)=default
BSLS_KEYWORD_CONSTEXPR_CPP14 TimeInterval & addSeconds(bsls::Types::Int64 seconds)
Definition bsls_timeinterval.h:1197
BSLS_KEYWORD_CONSTEXPR_CPP14 TimeInterval & addMinutes(bsls::Types::Int64 minutes)
Definition bsls_timeinterval.h:1188
static int maxSupportedVersion()
Definition bsls_timeinterval.h:1557
BSLS_KEYWORD_CONSTEXPR_CPP14 bsls::Types::Int64 totalMilliseconds() const
Definition bsls_timeinterval.h:1459
BSLS_KEYWORD_CONSTEXPR_CPP14 TimeInterval & addDays(bsls::Types::Int64 days)
Definition bsls_timeinterval.h:1170
BSLS_KEYWORD_CONSTEXPR_CPP14 void setTotalMicroseconds(bsls::Types::Int64 microseconds)
Definition bsls_timeinterval.h:1282
BSLS_KEYWORD_CONSTEXPR_CPP14 void setInterval(bsls::Types::Int64 seconds, int nanoseconds=0)
Definition bsls_timeinterval.h:1320
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR_CPP14
Definition bsls_keyword.h:631
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
#define BSLS_PRECONDITIONS_END()
Definition bsls_preconditions.h:131
#define BSLS_PRECONDITIONS_BEGIN()
Definition bsls_preconditions.h:130
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
Definition bdlt_iso8601util.h:707
TimeInterval operator+(const TimeInterval &lhs, const TimeInterval &rhs)
bool operator>=(const TimeInterval &lhs, const TimeInterval &rhs)
TimeInterval operator-(const TimeInterval &lhs, const TimeInterval &rhs)
bool operator==(const TimeInterval &lhs, const TimeInterval &rhs)
bool operator>(const TimeInterval &lhs, const TimeInterval &rhs)
bool operator!=(const TimeInterval &lhs, const TimeInterval &rhs)
bool operator<=(const TimeInterval &lhs, const TimeInterval &rhs)
std::ostream & operator<<(std::ostream &stream, const TimeInterval &timeInterval)
bool operator<(const TimeInterval &lhs, const TimeInterval &rhs)
Definition bdldfp_decimal.h:5549
long long Int64
Definition bsls_types.h:134