BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlt_datetimeinterval.h
Go to the documentation of this file.
1/// @file bdlt_datetimeinterval.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_datetimeinterval.h -*-C++-*-
8#ifndef INCLUDED_BDLT_DATETIMEINTERVAL
9#define INCLUDED_BDLT_DATETIMEINTERVAL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlt_datetimeinterval bdlt_datetimeinterval
15/// @brief Provide a representation of an interval of time.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlt
19/// @{
20/// @addtogroup bdlt_datetimeinterval
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlt_datetimeinterval-purpose"> Purpose</a>
25/// * <a href="#bdlt_datetimeinterval-classes"> Classes </a>
26/// * <a href="#bdlt_datetimeinterval-description"> Description </a>
27/// * <a href="#bdlt_datetimeinterval-the-representation-of-a-time-interval"> The Representation of a Time Interval </a>
28/// * <a href="#bdlt_datetimeinterval-usage"> Usage </a>
29/// * <a href="#bdlt_datetimeinterval-example-1-basic-bdlt-datetimeinterval-usage"> Example 1: Basic bdlt::DatetimeInterval Usage </a>
30///
31/// # Purpose {#bdlt_datetimeinterval-purpose}
32/// Provide a representation of an interval of time.
33///
34/// # Classes {#bdlt_datetimeinterval-classes}
35///
36/// - bdlt::DatetimeInterval: time interval with microsecond resolution
37///
38/// @see
39///
40/// # Description {#bdlt_datetimeinterval-description}
41/// This component implements a time interval class,
42/// `bdlt::DatetimeInterval`, capable of representing the (signed) difference
43/// between two arbitrary points in time. The time interval represented by a
44/// `bdlt::DatetimeInterval` object has microsecond resolution.
45///
46/// ## The Representation of a Time Interval {#bdlt_datetimeinterval-the-representation-of-a-time-interval}
47///
48///
49/// A time interval has a value that is independent of its representation.
50/// Conceptually, the interval between two points in time could be described
51/// using a (signed) real number of seconds (or minutes, or hours, etc.). A
52/// `bdlt::DatetimeInterval` represents this value as six fields: days, hours,
53/// minutes, seconds, milliseconds, and microseconds. In the "canonical
54/// representation" of a time interval, the days field may have any 32-bit
55/// signed integer value, with the hours, minutes, seconds, milliseconds, and
56/// microseconds fields limited to the respective ranges `[-23 .. 23]`,
57/// `[-59 .. 59]`, `[-59 .. 59]`, `[-999 .. 999]`, and `[-999 .. 999]`, with the
58/// additional constraint that the six fields are either all non-negative or all
59/// non-positive. When setting the value of a time interval via its six-field
60/// representation, any integer value may be used in any field, with the
61/// constraint that the resulting number of days be representable as a 32-bit
62/// signed integer. Similarly, the field values may be accessed in the
63/// canonical representation using the `days`, `hours`, `minutes`, `seconds`,
64/// `milliseconds`, and `microseconds` methods.
65///
66/// The primary accessors for this type are `days` and
67/// `fractionalDayInMicroseconds`. In combination, these two methods provide
68/// complete and succinct access to the value of a `DatetimeInterval`.
69/// Furthermore, the total value of the interval may be accessed in the
70/// respective field units via the `totalDays`, `totalHours`, `totalMinutes`,
71/// `totalSeconds`, `totalMilliseconds`, and `totalMicroseconds` methods. Note
72/// that, with the exception of `totalMicroseconds` (which returns an exact
73/// result), the other "total" accessors round toward 0. Also note that the
74/// `totalMicroseconds` accessor can fail for extreme `DatetimeInterval` values.
75///
76/// The following summarizes the canonical representation of the value of a
77/// `bdlt::DatetimeInterval`:
78/// @code
79/// Field Name Max. Valid Range Auxiliary Conditions Limiting Validity
80/// ---------- ------------------ --------------------------------------
81/// days any 32-bit integer all fields non-pos. or all non-neg.
82/// hours [ -23 .. 23] all fields non-pos. or all non-neg.
83/// minutes [ -59 .. 59] all fields non-pos. or all non-neg.
84/// seconds [ -59 .. 59] all fields non-pos. or all non-neg.
85/// milliseconds [-999 .. 999] all fields non-pos. or all non-neg.
86/// microseconds [-999 .. 999] all fields non-pos. or all non-neg.
87/// @endcode
88///
89/// ## Usage {#bdlt_datetimeinterval-usage}
90///
91///
92/// This section illustrates intended use of this component.
93///
94/// ### Example 1: Basic bdlt::DatetimeInterval Usage {#bdlt_datetimeinterval-example-1-basic-bdlt-datetimeinterval-usage}
95///
96///
97/// This example demonstrates how to create and use a `bdlt::DatetimeInterval`
98/// object.
99///
100/// First, create an object `i1` having the default value:
101/// @code
102/// bdlt::DatetimeInterval i1; assert( 0 == i1.days());
103/// assert( 0 == i1.hours());
104/// assert( 0 == i1.minutes());
105/// assert( 0 == i1.seconds());
106/// assert( 0 == i1.milliseconds());
107/// assert( 0 == i1.microseconds());
108/// @endcode
109/// Then, set the value of `i1` to -5 days, and then add 16 hours to that value:
110/// @code
111/// i1.setTotalDays(-5);
112/// i1.addHours(16); assert( -4 == i1.days());
113/// assert( -8 == i1.hours());
114/// assert( 0 == i1.minutes());
115/// assert( 0 == i1.seconds());
116/// assert( 0 == i1.milliseconds());
117/// assert( 0 == i1.microseconds());
118/// @endcode
119/// Next, create `i2` as a copy of `i1`:
120/// @code
121/// bdlt::DatetimeInterval i2(i1); assert( -4 == i2.days());
122/// assert( -8 == i2.hours());
123/// assert( 0 == i2.minutes());
124/// assert( 0 == i2.seconds());
125/// assert( 0 == i2.milliseconds());
126/// assert( 0 == i2.microseconds());
127/// @endcode
128/// Then, add 2 days and 4 seconds to the value of `i2` (in two steps), and
129/// confirm that `i2` has a value that is greater than that of `i1`:
130/// @code
131/// i2.addDays(2);
132/// i2.addSeconds(4); assert( -2 == i2.days());
133/// assert( -7 == i2.hours());
134/// assert(-59 == i2.minutes());
135/// assert(-56 == i2.seconds());
136/// assert( 0 == i2.milliseconds());
137/// assert( 0 == i2.microseconds());
138/// assert(i2 > i1);
139/// @endcode
140/// Next, add 2 days and 4 seconds to the value of `i1` in one step by using the
141/// `addInterval` method, and confirm that `i1` now has the same value as `i2`:
142/// @code
143/// i1.addInterval(2, 0, 0, 4); assert(i2 == i1);
144/// @endcode
145/// Finally, write the value of `i2` to `stdout`:
146/// @code
147/// bsl::cout << i2 << bsl::endl;
148/// @endcode
149/// The output operator produces the following format on `stdout`:
150/// @code
151/// -2_07:59:56.000000
152/// @endcode
153/// @}
154/** @} */
155/** @} */
156
157/** @addtogroup bdl
158 * @{
159 */
160/** @addtogroup bdlt
161 * @{
162 */
163/** @addtogroup bdlt_datetimeinterval
164 * @{
165 */
166
167#include <bdlscm_version.h>
168
169#include <bdlt_timeunitratio.h>
170
171#include <bslh_hash.h>
172
175
176#include <bsls_assert.h>
177#include <bsls_atomic.h>
178#include <bsls_log.h>
179#include <bsls_performancehint.h>
180#include <bsls_platform.h>
181#include <bsls_review.h>
182#include <bsls_timeinterval.h>
183#include <bsls_types.h>
184
185#include <bsl_cstdint.h>
186#include <bsl_limits.h>
187#include <bsl_iosfwd.h>
188
189
190namespace bdlt {
191
192 // ======================
193 // class DatetimeInterval
194 // ======================
195
196/// Each object of this class represents a (signed) time interval with
197/// microsecond resolution. See {The Representation of a Time Interval} for
198/// details.
199///
200/// See @ref bdlt_datetimeinterval
202
203 // PRIVATE TYPES
204 typedef bsls::Types::Int64 Int64;
205
206 enum {
207 k_DEFAULT_FRACTIONAL_SECOND_PRECISION = 6
208 };
209
210 // DATA
211 int32_t d_days; // field for days
212 bsls::Types::Int64 d_microseconds; // field for fractional day
213
214 // FRIENDS
216
217 friend bool operator==(const DatetimeInterval&, const DatetimeInterval&);
218 friend bool operator!=(const DatetimeInterval&, const DatetimeInterval&);
219 friend bool operator< (const DatetimeInterval&, const DatetimeInterval&);
220 friend bool operator<=(const DatetimeInterval&, const DatetimeInterval&);
221 friend bool operator> (const DatetimeInterval&, const DatetimeInterval&);
222 friend bool operator>=(const DatetimeInterval&, const DatetimeInterval&);
223
224 template <class HASHALG>
225 friend void hashAppend(HASHALG&, const DatetimeInterval&);
226
227 // PRIVATE MANIPULATORS
228
229 /// Set this datetime interval to have the value given by the sum of the
230 /// specified `days` and `microseconds`.
231 ///
232 /// \pre The behavior is undefined unless the total number of days, after converting to the canonical representation, can be represented as an `int`.
233 ///
234 /// \note Note that it is
235 /// impossible for an `Int64` to represent more than a day in
236 /// microseconds. Also note that the arguments may be supplied using a
237 /// mixture of positive, negative, and 0 values.
239
240 /// Set this datetime interval to have the value given by the sum of the
241 /// specified `days` and `microseconds`. Return 0 if the total number
242 /// of days, after converting to the canonical representation, can be
243 /// represented as an `int` and a non-zero value (with no effect) otherwise.
244 ///
245 /// \note Note that it is impossible for an `Int64` to represent
246 /// more than a day in microseconds. Also note that the arguments may
247 /// be supplied using a mixture of positive, negative, and 0 values.
248 int assignIfValid(bsls::Types::Int64 days,
250
251 public:
252 // PUBLIC CLASS DATA
253
254 /// The maximum interval that is representable by a `DatetimeInterval`,
255 /// in milliseconds.
256 static const bsls::Types::Int64 k_MILLISECONDS_MAX = 185542587187199999LL;
257
258 /// The minimum interval that is representable by a `DatetimeInterval`,
259 /// in milliseconds.
262
263 // CLASS METHODS
264
265 /// Return `true` if a time interval object having the value given by
266 /// the specified `days`, and the optionally specified `hours`,
267 /// `minutes`, `seconds`, `milliseconds`, and `microseconds` can be
268 /// represented as a `DatetimeInterval` and `false` otherwise.
269 /// Unspecified arguments default to 0. The resulting time interval
270 /// value is valid if the days field does not overflow a 32-bit integer.
271 ///
272 /// \note Note that the arguments may be supplied using a mixture of positive,
273 /// negative, and 0 values.
274 static
275 bool isValid(int days,
281
282 // Aspects
283
284 /// Return the maximum valid BDEX format version, as indicated by the
285 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
286 ///
287 /// \note Note that it is highly recommended that `versionSelector`
288 /// be formatted as "YYYYMMDD", a date representation. Also note that
289 /// `versionSelector` should be a *compile*-time-chosen value that
290 /// selects a format version supported by both externalizer and
291 /// unexternalizer. See the `bslx` package-level documentation for more
292 /// information on BDEX streaming of value-semantic types and
293 /// containers.
294 static int maxSupportedBdexVersion(int versionSelector);
295
296 // CREATORS
297
298 /// Create a time interval object having the value 0.
300
301 /// Create a time interval object having the value given by the
302 /// specified `days`, and the optionally specified `hours`, `minutes`,
303 /// `seconds`, `milliseconds`, and `microseconds`. Unspecified arguments default to 0.
304 ///
305 /// \pre The behavior is undefined unless the
306 /// resulting time interval value is valid (i.e., the days field must not overflow a 32-bit integer).
307 ///
308 /// \note Note that the arguments may be
309 /// supplied using a mixture of positive, negative, and 0 values.
310 explicit
317
318 /// Create a time interval object having the value of the specified
319 /// `original` time interval.
320 DatetimeInterval(const DatetimeInterval& original);
321
322 ~DatetimeInterval() = default;
323 // Destroy this time interval object. Note that this method's
324 // definition is generated by the compiler.
325
326 // MANIPULATORS
327
328 /// Assign to this object the value of the specified `rhs` time
329 /// interval, and return a reference providing modifiable access to this
330 /// object.
332
333 /// Add to this time interval the value of the specified `rhs` time
334 /// interval, and return a reference providing modifiable access to this object.
335 ///
336 /// \pre The behavior is undefined unless the resulting time
337 /// interval value is valid (i.e., the days field must not overflow a
338 /// 32-bit integer).
340
341 /// Subtract from this time interval the value of the specified `rhs`
342 /// time interval, and return a reference providing modifiable access to this object.
343 ///
344 /// \pre The behavior is undefined unless the resulting time
345 /// interval value is valid (i.e., the days field must not overflow a
346 /// 32-bit integer).
348
349 /// Set the time interval represented by this object to the value given
350 /// by the specified `days`, and the optionally specified `hours`,
351 /// `minutes`, `seconds`, `milliseconds`, and `microseconds`.
352 /// Unspecified arguments default to 0.
353 ///
354 /// \pre The behavior is undefined unless the resulting time interval value is valid (i.e., the days field must not overflow a 32-bit integer).
355 ///
356 /// \note Note that the arguments
357 /// may be supplied using a mixture of positive, negative, and 0 values.
364
365 /// Set the time interval represented by this object to the value given
366 /// by the specified `days`, and the optionally specified `hours`,
367 /// `minutes`, `seconds`, `milliseconds`, and `microseconds`.
368 /// Unspecified arguments default to 0. Return 0 if the resulting time
369 /// interval value is valid (i.e., the `days` field must not overflow an
370 /// `int`) and a non-zero value (with no effect) otherwise.
371 ///
372 /// \note Note that the arguments may be supplied using a mixture of positive, negative,
373 /// and 0 values.
380
381 /// Set the overall value of this object to indicate the specified
382 /// number of `days`.
383 void setTotalDays(int days);
384
385 /// Set the overall value of this object to indicate the specified number of `hours`.
386 ///
387 /// \pre The behavior is undefined unless the resulting
388 /// time interval value is valid (i.e., the days field must not overflow
389 /// a 32-bit integer).
391
392 /// Set the overall value of this object to indicate the specified
393 /// number of `hours`. Return 0 if the resulting time interval value is
394 /// valid (i.e., the `days` field must not overflow an `int`) and a
395 /// non-zero value (with no effect) otherwise.
397
398 /// Set the overall value of this object to indicate the specified number of `minutes`.
399 ///
400 /// \pre The behavior is undefined unless the resulting
401 /// time interval value is valid (i.e., the days field must not overflow
402 /// a 32-bit integer).
404
405 /// Set the overall value of this object to indicate the specified
406 /// number of `minutes`. Return 0 if the resulting time interval value
407 /// is valid (i.e., the `days` field must not overflow an `int`) and a
408 /// non-zero value (with no effect) otherwise.
410
411 /// Set the overall value of this object to indicate the specified number of `seconds`.
412 ///
413 /// \pre The behavior is undefined unless the resulting
414 /// time interval value is valid (i.e., the days field must not overflow
415 /// a 32-bit integer).
417
418 /// Set the overall value of this object to indicate the specified
419 /// number of `seconds`. Return 0 if the resulting time interval value
420 /// is valid (i.e., the `days` field must not overflow an `int`) and a
421 /// non-zero value (with no effect) otherwise.
423
424 /// Set the overall value of this object to indicate the specified
425 /// number of `seconds`. The fractional part of `seconds`, if any, is
426 /// rounded to the nearest whole number of microseconds.
427 ///
428 /// \pre The behavior is undefined unless the resulting time interval value is valid
429 /// (i.e., the days field must not overflow a 32-bit integer).
431
432 /// Set the overall value of this object to indicate the specified
433 /// number of `seconds`. The fractional part of `seconds`, if any, is
434 /// rounded to the nearest whole number of microseconds. Return 0 if
435 /// the resulting time interval value is valid (i.e., the `days` field
436 /// must not overflow an `int`) and a non-zero value (with no effect)
437 /// otherwise.
439
440 /// Set the overall value of this object to indicate the specified number of `milliseconds`.
441 ///
442 /// \pre The behavior is undefined unless the
443 /// resulting time interval value is valid (i.e., the days field must
444 /// not overflow a 32-bit integer).
446
447 /// Set the overall value of this object to indicate the specified
448 /// number of `milliseconds`. Return 0 if the resulting time interval
449 /// value is valid (i.e., the days field must not overflow an `int`) and
450 /// a non-zero value (with no effect) otherwise.
452
453 /// Set the overall value of this object to indicate the specified number of `microseconds`.
454 ///
455 /// \note Note that there is no
456 /// `setTotalMicrosecondsIfValid` because no value of `microseconds` can
457 /// cause the number of days to overflow.
459
460 /// Add to this time interval the specified number of `days`, and the
461 /// optionally specified number of `hours`, `minutes`, `seconds`,
462 /// `milliseconds`, and `microseconds`, and return a reference providing
463 /// modifiable access to this object. Unspecified arguments default to 0.
464 ///
465 /// \pre The behavior is undefined unless the resulting time interval
466 /// value is valid (i.e., the days field must not overflow a 32-bit integer).
467 ///
468 /// \note Note that the arguments may be supplied using a mixture
469 /// of positive, negative, and 0 values.
476
477 /// Add to this time interval the specified number of `days`, and the
478 /// optionally specified number of `hours`, `minutes`, `seconds`,
479 /// `milliseconds`, and `microseconds`. Return 0 if the resulting time
480 /// interval value is valid (i.e., the days field must not overflow an
481 /// `int`) and a non-zero value (with no effect) otherwise.
482 ///
483 /// \note Note that the arguments may be supplied using a mixture of positive, negative,
484 /// and 0 values.
491
492 /// Add to this time interval the specified number of `days`, and return
493 /// a reference providing modifiable access to this object.
494 ///
495 /// \pre The behavior is undefined unless the resulting time interval value is
496 /// valid (i.e., the days field must not overflow a 32-bit integer).
498
499 /// Add to this time interval the specified number of `days`. Return 0
500 /// if the resulting time interval value is valid (i.e., the days field
501 /// must not overflow an `int`) and a non-zero value (with no effect)
502 /// otherwise.
503 int addDaysIfValid(int days);
504
505 /// Add to this time interval the specified number of `hours`, and
506 /// return a reference providing modifiable access to this object.
507 ///
508 /// \pre The behavior is undefined unless the resulting time interval value is
509 /// valid (i.e., the days field must not overflow a 32-bit integer).
511
512 /// Add to this time interval the specified number of `hours`. Return 0
513 /// if the resulting time interval value is valid (i.e., the days field
514 /// must not overflow an `int`) and a non-zero value (with no effect)
515 /// otherwise.
517
518 /// Add to this time interval the specified number of `minutes`, and
519 /// return a reference providing modifiable access to this object.
520 ///
521 /// \pre The behavior is undefined unless the resulting time interval value is
522 /// valid (i.e., the days field must not overflow a 32-bit integer).
524
525 /// Add to this time interval the specified number of `minutes`. Return
526 /// 0 if the resulting time interval value is valid (i.e., the days
527 /// field must not overflow an `int`) and a non-zero value (with no
528 /// effect) otherwise.
530
531 /// Add to this time interval the specified number of `seconds`, and
532 /// return a reference providing modifiable access to this object.
533 ///
534 /// \pre The behavior is undefined unless the resulting time interval value is
535 /// valid (i.e., the days field must not overflow a 32-bit integer).
537
538 /// Add to this time interval the specified number of `seconds`. Return
539 /// 0 if the resulting time interval value is valid (i.e., the days
540 /// field must not overflow an `int`) and a non-zero value (with no
541 /// effect) otherwise.
543
544 /// Add to this time interval the specified number of `milliseconds`,
545 /// and return a reference providing modifiable access to this object.
546 ///
547 /// \pre The behavior is undefined unless the resulting time interval value
548 /// is valid (i.e., the days field must not overflow a 32-bit integer).
550
551 /// Add to this time interval the specified number of `milliseconds`.
552 /// Return 0 if the resulting time interval value is valid (i.e., the
553 /// days field must not overflow an `int`) and a non-zero value (with no
554 /// effect) otherwise.
556
557 /// Add to this time interval the specified number of `microseconds`,
558 /// and return a reference providing modifiable access to this object.
559 ///
560 /// \pre The behavior is undefined unless the resulting time interval value
561 /// is valid (i.e., the days field must not overflow a 32-bit integer).
563
564 /// Add to this time interval the specified number of `microseconds`.
565 /// Return 0 if the resulting time interval value is valid (i.e., the
566 /// days field must not overflow an `int`) and a non-zero value (with no
567 /// effect) otherwise.
569
570 // Aspects
571
572 /// Assign to this object the value read from the specified input
573 /// `stream` using the specified `version` format, and return a
574 /// reference to `stream`. If `stream` is initially invalid, this
575 /// operation has no effect. If `version` is not supported, this object
576 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
577 /// If `version` is supported but `stream` becomes invalid during this
578 /// operation, this object has an undefined, but valid, state.
579 ///
580 /// \note Note that no version is read from `stream`. See the `bslx` package-level
581 /// documentation for more information on BDEX streaming of
582 /// value-semantic types and containers.
583 template <class STREAM>
584 STREAM& bdexStreamIn(STREAM& stream, int version);
585
586 // ACCESSORS
587
588 /// Return the days field in the canonical representation of the value of this time interval.
589 ///
590 /// \note Note that the return value may be negative.
591 /// Also note that the return value is the same as that returned by
592 /// `totalDays`.
593 int days() const;
594
595 /// Return the value of this time interval as an integral number of
596 /// microseconds modulo the number of microseconds in a day.
597 ///
598 /// \note Note that the return value may be negative.
600
601 /// Return the hours field in the canonical representation of the value of this time interval.
602 ///
603 /// \note Note that the return value may be negative.
604 int hours() const;
605
606 /// Return the minutes field in the canonical representation of the value of this time interval.
607 ///
608 /// \note Note that the return value may be
609 /// negative.
610 int minutes() const;
611
612 /// Return the seconds field in the canonical representation of the value of this time interval.
613 ///
614 /// \note Note that the return value may be
615 /// negative.
616 int seconds() const;
617
618 /// Return the milliseconds field in the canonical representation of the value of this time interval.
619 ///
620 /// \note Note that the return value may be
621 /// negative.
622 int milliseconds() const;
623
624 /// Return the microseconds field in the canonical representation of the value of this time interval.
625 ///
626 /// \note Note that the return value may be
627 /// negative.
628 int microseconds() const;
629
630 /// Efficiently write to the specified `result` buffer no more than the
631 /// specified `numBytes` of a representation of the value of this
632 /// object. Optionally specify `fractionalSecondPrecision` digits to
633 /// indicate how many fractional second digits to output. If
634 /// `fractionalSecondPrecision` is not specified then 6 fractional
635 /// second digits will be output (3 digits for milliseconds and 3 digits
636 /// for microseconds). Return the number of characters (not including
637 /// the null character) that would have been written if the limit due to
638 /// `numBytes` were not imposed. `result` is null-terminated unless `numBytes` is 0.
639 ///
640 /// \pre The behavior is undefined unless `0 <= numBytes`,
641 /// `0 <= fractionalSecondPrecision <= 6`, and `result` refers to at least `numBytes` contiguous bytes.
642 ///
643 /// \note Note that the return value is
644 /// greater than or equal to `numBytes` if the output representation was
645 /// truncated to avoid `result` overrun.
646 int printToBuffer(char *result,
647 int numBytes,
648 int fractionalSecondPrecision = 6) const;
649
650 /// Return the value of this time interval in integral days, rounded toward 0.
651 ///
652 /// \note Note that the return value may be negative. Also note
653 /// that the return value is the same as that returned by `days`.
654 int totalDays() const;
655
656 /// Return the value of this time interval in integral hours, rounded toward 0.
657 ///
658 /// \note Note that the return value may be negative.
660
661 /// Return the value of this time interval in integral minutes, rounded toward 0.
662 ///
663 /// \note Note that the return value may be negative.
665
666 /// Return the value of this time interval in integral seconds, rounded toward 0.
667 ///
668 /// \note Note that the return value may be negative.
670
671 /// Return the value of this time interval in seconds as a `double`, potentially with a fractional part.
672 ///
673 /// \note Note that the return value may
674 /// be negative. Also note that the conversion from the internal
675 /// representation to `double` may *lose* precision.
676 double totalSecondsAsDouble() const;
677
678 /// Return the value of this time interval in integral milliseconds, rounded towards zero.
679 ///
680 /// \note Note that the return value may be negative.
682
683 /// Return the value of this time interval as an integral number of microseconds.
684 ///
685 /// \pre The behavior is undefined unless the number of
686 /// microseconds can be represented with a 64-bit signed integer.
687 ///
688 /// \note Note that the return value may be negative.
690
691 // Aspects
692
693 /// Write the value of this object, using the specified `version`
694 /// format, to the specified output `stream`, and return a reference to
695 /// `stream`. If `stream` is initially invalid, this operation has no
696 /// effect. If `version` is not supported, `stream` is invalidated, but otherwise unmodified.
697 ///
698 /// \note Note that `version` is not written to
699 /// `stream`. See the `bslx` package-level documentation for more
700 /// information on BDEX streaming of value-semantic types and
701 /// containers.
702 template <class STREAM>
703 STREAM& bdexStreamOut(STREAM& stream, int version) const;
704
705 /// Write the value of this object to the specified output `stream` in a
706 /// human-readable format, and return a reference to `stream`.
707 /// Optionally specify an initial indentation `level`, whose absolute
708 /// value is incremented recursively for nested objects. If `level` is
709 /// specified, optionally specify `spacesPerLevel`, whose absolute value
710 /// indicates the number of spaces per indentation level for this and
711 /// all of its nested objects. If `level` is negative, suppress
712 /// indentation of the first line. If `spacesPerLevel` is negative,
713 /// format the entire output on one line, suppressing all but the
714 /// initial indentation (as governed by `level`). If `stream` is not valid on entry, this operation has no effect.
715 ///
716 /// \note Note that the format
717 /// is not fully specified, and can change without notice.
718 bsl::ostream& print(bsl::ostream& stream,
719 int level = 0,
720 int spacesPerLevel = 4) const;
721
722#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
723
724 // DEPRECATED METHODS
725
726 /// Return the most current BDEX streaming version number supported by
727 /// this class.
728 ///
729 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
730 static int maxSupportedBdexVersion();
731
732#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
733#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
734
735 /// Return the most current BDEX streaming version number supported by
736 /// this class.
737 ///
738 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
739 static int maxSupportedVersion();
740
741 /// Format this datetime interval to the specified output `stream`, and
742 /// return a reference to `stream`.
743 ///
744 /// @deprecated use `operator<<` or `print` instead.
745 bsl::ostream& streamOut(bsl::ostream& stream) const;
746
747#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
748
749};
750
751// FREE OPERATORS
752
753/// Return a `DatetimeInterval` object whose value is the sum of the
754/// specified `lhs` and `rhs` time intervals.
755///
756/// \pre The behavior is undefined unless the resulting time interval value is valid (i.e., the days field
757/// must not overflow a 32-bit integer).
759 const DatetimeInterval& rhs);
760
761/// Return a `DatetimeInterval` object whose value is the difference between
762/// the specified `lhs` and `rhs` time intervals.
763///
764/// \pre The behavior is undefined unless the resulting time interval value is valid (i.e., the days field
765/// must not overflow a 32-bit integer).
767 const DatetimeInterval& rhs);
768
769/// Return a `DatetimeInterval` object whose value is the negative of the specified time interval `value`.
770///
771/// \pre The behavior is undefined unless
772/// `INT_MIN < value.days()`.
774
775/// Return `true` if the specified `lhs` and `rhs` time intervals have the
776/// same value, and `false` otherwise. Two time intervals have the same
777/// value if all of the corresponding values of their days, hours, minutes,
778/// seconds, milliseconds, and microseconds fields are the same.
779bool operator==(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
780
781/// Return `true` if the specified `lhs` and `rhs` time intervals do not
782/// have the same value, and `false` otherwise. Two time intervals do not
783/// have the same value if any of the corresponding values of their days,
784/// hours, minutes, seconds, milliseconds, or microseconds fields is not
785/// the same.
786bool operator!=(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
787
788/// Return `true` if the nominal relation between the specified `lhs` and
789/// `rhs` time interval values holds, and `false` otherwise. `lhs` is less
790/// than `rhs` if the following expression evaluates to `true`:
791/// @code
792/// lhs.days() < rhs.days()
793/// || (lhs.days() == rhs.days() && lhs.fractionalDayInMicroseconds()
794/// < rhs.fractionalDayInMicroseconds())
795/// @endcode
796/// The other relationships are defined similarly.
797bool operator< (const DatetimeInterval& lhs, const DatetimeInterval& rhs);
798bool operator<=(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
799bool operator> (const DatetimeInterval& lhs, const DatetimeInterval& rhs);
800bool operator>=(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
801
802/// Write the value of the specified `object` to the specified output
803/// `stream` in a single-line format, and return a reference providing
804/// modifiable access to `stream`. If `stream` is not valid on entry, this operation has no effect.
805///
806/// \note Note that this human-readable format is not
807/// fully specified and can change without notice. Also note that this
808/// method has the same behavior as `object.print(stream, 0, -1)`.
809bsl::ostream& operator<<(bsl::ostream& stream, const DatetimeInterval& object);
810
811// FREE FUNCTIONS
812
813/// Pass the specified `object` to the specified `hashAlg`. This function
814/// integrates with the `bslh` modular hashing system and effectively
815/// provides a `bsl::hash` specialization for `DatetimeInterval`.
816template <class HASHALG>
817void hashAppend(HASHALG& hashAlg, const DatetimeInterval& object);
818
819// ============================================================================
820// INLINE DEFINITIONS
821// ============================================================================
822
823 // ----------------------
824 // class DatetimeInterval
825 // ----------------------
826
827// CLASS METHODS
828
829 // Aspects
830
831inline
833{
834 if (versionSelector >= 20170401) {
835 return 2; // RETURN
836 }
837 return 1;
838}
839
840// CREATORS
841inline
843: d_days(0)
844, d_microseconds(0)
845{
846}
847
848inline
850 bsls::Types::Int64 hours,
851 bsls::Types::Int64 minutes,
852 bsls::Types::Int64 seconds,
853 bsls::Types::Int64 milliseconds,
854 bsls::Types::Int64 microseconds)
855{
857 hours,
858 minutes,
859 seconds,
862}
863
864inline
866: d_days(original.d_days)
867, d_microseconds(original.d_microseconds)
868{
869}
870
871// MANIPULATORS
872inline
874{
875 d_days = rhs.d_days;
876 d_microseconds = rhs.d_microseconds;
877 return *this;
878}
879
880inline
882{
883#ifdef BSLS_ASSERT_IS_USED
884 int rc = addIntervalIfValid(rhs.d_days, 0, 0, 0, 0, rhs.d_microseconds);
885 BSLS_ASSERT(0 == rc && "operator+= over/under flow"); (void) rc;
886#else
887 addInterval(rhs.d_days, 0, 0, 0, 0, rhs.d_microseconds);
888#endif
889
890 return *this;
891}
892
893inline
895{
896 Int64 rhsDays = rhs.d_days;
897 Int64 rhsMicroseconds = rhs.d_microseconds;
898 if (INT_MIN == rhsDays) {
899 ++rhsDays;
900 rhsMicroseconds -= TimeUnitRatio::k_US_PER_D;
901 }
902 rhsDays = -rhsDays;
903 rhsMicroseconds = -rhsMicroseconds;
904 BSLS_ASSERT_SAFE(rhsDays <= INT_MAX && INT_MIN < rhsDays); // always true
905
906#ifdef BSLS_ASSERT_IS_USED
907 int rc = addIntervalIfValid(
908 static_cast<int>(rhsDays), 0, 0, 0, 0, rhsMicroseconds);
909 BSLS_ASSERT(0 == rc && "operator-= over/under flow"); (void) rc;
910#else
911 addInterval(static_cast<int>(rhsDays), 0, 0, 0, 0, rhsMicroseconds);
912#endif
913
914 return *this;
915}
916
917inline
919{
920 d_days = days;
921 d_microseconds = 0;
922}
923
924inline
930
931inline
938
939inline
945
946inline
953
954inline
960
961inline
968
969inline
976
977inline
985
986inline
992
993inline
995{
996 assign(static_cast<bsls::Types::Int64>(d_days)
997 + static_cast<bsls::Types::Int64>(days),
998 d_microseconds);
999 return *this;
1000}
1001
1002inline
1004{
1005 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1006 + static_cast<bsls::Types::Int64>(days),
1007 d_microseconds);
1008}
1009
1010inline
1012{
1013 assign(static_cast<bsls::Types::Int64>(d_days)
1015 d_microseconds +
1017 return *this;
1018}
1019
1020inline
1022{
1023 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1025 d_microseconds + (hours % TimeUnitRatio::k_H_PER_D) *
1027}
1028
1029inline
1031{
1032 assign(static_cast<bsls::Types::Int64>(d_days)
1034 d_microseconds +
1036 return *this;
1037}
1038
1039inline
1041{
1042 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1044 d_microseconds +
1047}
1048
1049inline
1051{
1052 assign(static_cast<bsls::Types::Int64>(d_days)
1054 d_microseconds +
1056 return *this;
1057}
1058
1059inline
1061{
1062 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1064 d_microseconds +
1067}
1068
1069inline
1072{
1073 assign(static_cast<bsls::Types::Int64>(d_days)
1075 d_microseconds + milliseconds % TimeUnitRatio::k_MS_PER_D
1077 return *this;
1078}
1079
1080inline
1082{
1083 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1085 d_microseconds +
1088}
1089
1090inline
1093{
1094 assign(static_cast<bsls::Types::Int64>(d_days)
1096 d_microseconds + microseconds % TimeUnitRatio::k_US_PER_D);
1097 return *this;
1098}
1099
1100inline
1102{
1103 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1105 d_microseconds +
1107}
1108
1109 // Aspects
1110
1111template <class STREAM>
1112STREAM& DatetimeInterval::bdexStreamIn(STREAM& stream, int version)
1113{
1114 if (stream) {
1115 switch (version) { // switch on the schema version
1116 case 2: {
1117 int tmpDays;
1118 stream.getInt32(tmpDays);
1119
1120 bsls::Types::Int64 tmpMicroseconds;
1121 stream.getInt64(tmpMicroseconds);
1122
1123 if ( stream
1124 && ( (0 <= tmpDays && 0 <= tmpMicroseconds)
1125 || (0 >= tmpDays && 0 >= tmpMicroseconds))
1126 && TimeUnitRatio::k_US_PER_D > tmpMicroseconds
1127 && -TimeUnitRatio::k_US_PER_D < tmpMicroseconds) {
1128 assign(tmpDays, tmpMicroseconds);
1129 }
1130 else {
1131 stream.invalidate();
1132 }
1133 } break;
1134 case 1: {
1136 stream.getInt64(tmp);
1137
1138 if ( stream
1139 && k_MILLISECONDS_MIN <= tmp && k_MILLISECONDS_MAX >= tmp) {
1141 }
1142 else {
1143 stream.invalidate();
1144 }
1145 } break;
1146 default: {
1147 stream.invalidate(); // unrecognized version number
1148 }
1149 }
1150 }
1151 return stream;
1152}
1153
1154// ACCESSORS
1155inline
1157{
1158 return d_days;
1159}
1160
1161inline
1163{
1164 return d_microseconds;
1165}
1166
1167inline
1169{
1170 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_H);
1171}
1172
1173inline
1175{
1176 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_M
1178}
1179
1180inline
1182{
1183 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_S
1185}
1186
1187inline
1189{
1190 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_MS
1192}
1193
1194inline
1196{
1197 return static_cast<int>(d_microseconds % TimeUnitRatio::k_US_PER_MS);
1198}
1199
1200inline
1202{
1203 return d_days;
1204}
1205
1206inline
1208{
1209 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_H_PER_D
1210 + d_microseconds / TimeUnitRatio::k_US_PER_H;
1211}
1212
1213inline
1215{
1216 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_M_PER_D
1217 + d_microseconds / TimeUnitRatio::k_US_PER_M;
1218}
1219
1220inline
1222{
1223 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_S_PER_D
1224 + d_microseconds / TimeUnitRatio::k_US_PER_S;
1225}
1226
1227inline
1229{
1230 return d_days * static_cast<double>(TimeUnitRatio::k_S_PER_D) +
1231 static_cast<double>(d_microseconds) /
1232 static_cast<double>(TimeUnitRatio::k_US_PER_S);
1233}
1234
1235inline
1237{
1238 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_MS_PER_D
1239 + d_microseconds / TimeUnitRatio::k_US_PER_MS;
1240}
1241
1242inline
1244{
1245 BSLS_REVIEW( 0 >= d_days
1246 || (bsl::numeric_limits<bsls::Types::Int64>::max() -
1247 d_microseconds) / TimeUnitRatio::k_US_PER_D >= d_days);
1248
1249#if !defined(BSLS_PLATFORM_CMP_SUN) \
1250 || !defined(BDE_BUILD_TARGET_OPT) \
1251 || BSLS_PLATFORM_CMP_VERSION >= 0x5140
1252
1253 // Older versions of the Sun compiler (e.g., 5.12.3 and 5.12.4) fail to
1254 // compile the following 'BSLS_REVIEW' correctly in optimized builds.
1255
1256 BSLS_REVIEW( 0 <= d_days
1257 || (bsl::numeric_limits<bsls::Types::Int64>::min() -
1258 d_microseconds) / TimeUnitRatio::k_US_PER_D <= d_days);
1259
1260#endif
1261
1262 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_US_PER_D
1263 + d_microseconds;
1264}
1265
1266 // Aspects
1267
1268template <class STREAM>
1269STREAM& DatetimeInterval::bdexStreamOut(STREAM& stream, int version) const
1270{
1271 if (stream) {
1272 switch (version) { // switch on the schema version
1273 case 2: {
1274 stream.putInt32(d_days);
1275 stream.putInt64(d_microseconds);
1276 } break;
1277 case 1: {
1278 stream.putInt64(totalMilliseconds());
1279 } break;
1280 default: {
1281 stream.invalidate(); // unrecognized version number
1282 }
1283 }
1284 }
1285 return stream;
1286}
1287
1288#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
1289
1290// DEPRECATED METHODS
1291inline
1296
1297#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
1298#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
1299inline
1304
1305#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
1306
1307} // close package namespace
1308
1309// FREE OPERATORS
1310inline
1311bdlt::DatetimeInterval bdlt::operator+(const DatetimeInterval& lhs,
1312 const DatetimeInterval& rhs)
1313{
1314 DatetimeInterval ret(lhs);
1315
1316#ifdef BSLS_ASSERT_IS_USED
1317 int rc = ret.addIntervalIfValid(0, 0, 0, 0,
1318 rhs.totalMilliseconds(), rhs.microseconds());
1319 BSLS_ASSERT(0 == rc && "operator+ over/under flow"); (void) rc;
1320#else
1321 ret.addInterval(0, 0, 0, 0, rhs.totalMilliseconds(), rhs.microseconds());
1322#endif
1323
1324 return ret;
1325}
1326
1327inline
1328bdlt::DatetimeInterval bdlt::operator-(const DatetimeInterval& lhs,
1329 const DatetimeInterval& rhs)
1330{
1331 DatetimeInterval ret(lhs);
1332
1333#ifdef BSLS_ASSERT_IS_USED
1334 int rc = ret.addIntervalIfValid(0, 0, 0, 0,
1335 -rhs.totalMilliseconds(), -rhs.microseconds());
1336 BSLS_ASSERT(0 == rc && "operator- over/under flow"); (void) rc;
1337#else
1338 ret.addInterval(0, 0, 0, 0, -rhs.totalMilliseconds(), -rhs.microseconds());
1339#endif
1340
1341 return ret;
1342}
1343
1344inline
1345bdlt::DatetimeInterval bdlt::operator-(const DatetimeInterval& value)
1346{
1347 BSLS_REVIEW(value.d_days > bsl::numeric_limits<int32_t>::min());
1348
1349 DatetimeInterval interval;
1350
1351 interval.d_days = -value.d_days;
1352 interval.d_microseconds = -value.d_microseconds;
1353
1354 return interval;
1355}
1356
1357inline
1358bool bdlt::operator==(const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1359{
1360 return lhs.d_days == rhs.d_days
1361 && lhs.d_microseconds == rhs.d_microseconds;
1362}
1363
1364inline
1365bool bdlt::operator!=(const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1366{
1367 return lhs.d_days != rhs.d_days
1368 || lhs.d_microseconds != rhs.d_microseconds;
1369}
1370
1371inline
1372bool bdlt::operator< (const DatetimeInterval& lhs,
1373 const DatetimeInterval& rhs)
1374{
1375 return lhs.d_days < rhs.d_days
1376 || ( lhs.d_days == rhs.d_days
1377 && lhs.d_microseconds < rhs.d_microseconds);
1378}
1379
1380inline
1381bool bdlt::operator<=(const DatetimeInterval& lhs,
1382 const DatetimeInterval& rhs)
1383{
1384 return lhs.d_days < rhs.d_days
1385 || ( lhs.d_days == rhs.d_days
1386 && lhs.d_microseconds <= rhs.d_microseconds);
1387}
1388
1389inline
1390bool bdlt::operator> (const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1391{
1392 return lhs.d_days > rhs.d_days
1393 || ( lhs.d_days == rhs.d_days
1394 && lhs.d_microseconds > rhs.d_microseconds);
1395}
1396
1397inline
1398bool bdlt::operator>=(const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1399{
1400 return lhs.d_days > rhs.d_days
1401 || ( lhs.d_days == rhs.d_days
1402 && lhs.d_microseconds >= rhs.d_microseconds);
1403}
1404
1405inline
1406bsl::ostream& bdlt::operator<<(bsl::ostream& stream,
1407 const DatetimeInterval& object)
1408{
1409 return object.print(stream, 0, -1);
1410}
1411
1412// FREE FUNCTIONS
1413template <class HASHALG>
1414void bdlt::hashAppend(HASHALG& hashAlg, const DatetimeInterval& object)
1415{
1416 using ::BloombergLP::bslh::hashAppend;
1417 hashAppend(hashAlg, object.d_days);
1418 hashAppend(hashAlg, object.d_microseconds);
1419}
1420
1421
1422
1423namespace bsl {
1424
1425// TRAITS
1426
1427/// This template specialization for `is_trivially_copyable` indicates that
1428/// `DatetimeInterval` is a trivially copyable type.
1429template <>
1430struct is_trivially_copyable<BloombergLP::bdlt::DatetimeInterval> :
1432};
1433
1434} // close namespace bsl
1435
1436#endif
1437
1438// ----------------------------------------------------------------------------
1439// Copyright 2017 Bloomberg Finance L.P.
1440//
1441// Licensed under the Apache License, Version 2.0 (the "License");
1442// you may not use this file except in compliance with the License.
1443// You may obtain a copy of the License at
1444//
1445// http://www.apache.org/licenses/LICENSE-2.0
1446//
1447// Unless required by applicable law or agreed to in writing, software
1448// distributed under the License is distributed on an "AS IS" BASIS,
1449// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1450// See the License for the specific language governing permissions and
1451// limitations under the License.
1452// ----------------------------- END-OF-FILE ----------------------------------
1453
1454/** @} */
1455/** @} */
1456/** @} */
Definition bdlt_datetimeinterval.h:201
int days() const
Definition bdlt_datetimeinterval.h:1156
friend DatetimeInterval operator-(const DatetimeInterval &)
int setIntervalIfValid(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
friend bool operator>(const DatetimeInterval &, const DatetimeInterval &)
int setTotalSecondsFromDoubleIfValid(double seconds)
int addSecondsIfValid(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:1060
int addIntervalIfValid(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
bsls::Types::Int64 totalMinutes() const
Definition bdlt_datetimeinterval.h:1214
int totalDays() const
Definition bdlt_datetimeinterval.h:1201
DatetimeInterval & addMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:1092
int milliseconds() const
Definition bdlt_datetimeinterval.h:1188
static const bsls::Types::Int64 k_MILLISECONDS_MIN
Definition bdlt_datetimeinterval.h:260
int seconds() const
Definition bdlt_datetimeinterval.h:1181
int addMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:1040
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_datetimeinterval.h:1112
void setTotalDays(int days)
Definition bdlt_datetimeinterval.h:918
int setTotalHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:932
DatetimeInterval & operator-=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:894
void setTotalMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:987
DatetimeInterval & operator=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:873
bsls::Types::Int64 totalSeconds() const
Definition bdlt_datetimeinterval.h:1221
int setTotalMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:978
void setTotalMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:940
void setTotalMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:970
double totalSecondsAsDouble() const
Definition bdlt_datetimeinterval.h:1228
DatetimeInterval & addHours(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:1011
int setTotalSecondsIfValid(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:962
int addMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:1081
void setTotalHours(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:925
static bool isValid(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
friend bool operator!=(const DatetimeInterval &, const DatetimeInterval &)
int minutes() const
Definition bdlt_datetimeinterval.h:1174
bsls::Types::Int64 fractionalDayInMicroseconds() const
Definition bdlt_datetimeinterval.h:1162
static int maxSupportedVersion()
Definition bdlt_datetimeinterval.h:1300
DatetimeInterval & addDays(int days)
Definition bdlt_datetimeinterval.h:994
int addMicrosecondsIfValid(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:1101
DatetimeInterval & addInterval(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
int hours() const
Definition bdlt_datetimeinterval.h:1168
int microseconds() const
Definition bdlt_datetimeinterval.h:1195
bsls::Types::Int64 totalMilliseconds() const
Definition bdlt_datetimeinterval.h:1236
bsl::ostream & streamOut(bsl::ostream &stream) const
int addHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:1021
void setInterval(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
DatetimeInterval()
Create a time interval object having the value 0.
Definition bdlt_datetimeinterval.h:842
friend bool operator==(const DatetimeInterval &, const DatetimeInterval &)
int printToBuffer(char *result, int numBytes, int fractionalSecondPrecision=6) const
DatetimeInterval & operator+=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:881
void setTotalSecondsFromDouble(double seconds)
DatetimeInterval & addMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:1030
bsls::Types::Int64 totalMicroseconds() const
Definition bdlt_datetimeinterval.h:1243
int setTotalMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:947
int addDaysIfValid(int days)
Definition bdlt_datetimeinterval.h:1003
DatetimeInterval & addMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:1071
friend bool operator<=(const DatetimeInterval &, const DatetimeInterval &)
DatetimeInterval & addSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:1050
static int maxSupportedBdexVersion()
Definition bdlt_datetimeinterval.h:1292
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_datetimeinterval.h:1269
friend bool operator>=(const DatetimeInterval &, const DatetimeInterval &)
friend void hashAppend(HASHALG &, const DatetimeInterval &)
void setTotalSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:955
friend bool operator<(const DatetimeInterval &, const DatetimeInterval &)
static const bsls::Types::Int64 k_MILLISECONDS_MAX
Definition bdlt_datetimeinterval.h:256
bsls::Types::Int64 totalHours() const
Definition bdlt_datetimeinterval.h:1207
#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_REVIEW(X)
Definition bsls_review.h:1019
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const BigEndianInt16 &object)
Definition bbldc_basicisma30360.h:112
bool operator>(const Date &lhs, const Date &rhs)
bool operator<(const Date &lhs, const Date &rhs)
bool operator==(const Calendar &lhs, const Calendar &rhs)
Date operator-(const Date &date, int numDays)
bool operator>=(const Date &lhs, const Date &rhs)
Date operator+(const Date &date, int numDays)
bsl::ostream & operator<<(bsl::ostream &stream, const Calendar &calendar)
bool operator<=(const Date &lhs, const Date &rhs)
void hashAppend(HASHALG &hashAlg, const Calendar &object)
bool operator!=(const Calendar &lhs, const Calendar &rhs)
Definition bdlat_valuetypefunctions.h:939
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
static const bsls::Types::Int64 k_M_PER_D
Definition bdlt_timeunitratio.h:292
static const bsls::Types::Int64 k_S_PER_M
Definition bdlt_timeunitratio.h:287
static const bsls::Types::Int64 k_MS_PER_S
Definition bdlt_timeunitratio.h:282
static const bsls::Types::Int64 k_US_PER_H
Definition bdlt_timeunitratio.h:279
static const bsls::Types::Int64 k_M_PER_H
Definition bdlt_timeunitratio.h:291
static const bsls::Types::Int64 k_US_PER_MS
Definition bdlt_timeunitratio.h:275
static const bsls::Types::Int64 k_US_PER_D
Definition bdlt_timeunitratio.h:280
static const bsls::Types::Int64 k_H_PER_D
Definition bdlt_timeunitratio.h:294
static const bsls::Types::Int64 k_US_PER_S
Definition bdlt_timeunitratio.h:277
static const bsls::Types::Int64 k_US_PER_M
Definition bdlt_timeunitratio.h:278
static const bsls::Types::Int64 k_S_PER_D
Definition bdlt_timeunitratio.h:289
static const bsls::Types::Int64 k_MILLISECONDS_PER_DAY
Definition bdlt_timeunitratio.h:251
static const bsls::Types::Int64 k_MS_PER_D
Definition bdlt_timeunitratio.h:285
long long Int64
Definition bsls_types.h:134