BDE 4.14.0 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`. The behavior is undefined
231 /// unless the total number of days, after converting to the canonical
232 /// representation, can be represented as an `int`. Note that it is
233 /// impossible for an `Int64` to represent more than a day in
234 /// microseconds. Also note that the arguments may be supplied using a
235 /// mixture of positive, negative, and 0 values.
237
238 /// Set this datetime interval to have the value given by the sum of the
239 /// specified `days` and `microseconds`. Return 0 if the total number
240 /// of days, after converting to the canonical representation, can be
241 /// represented as an `int` and a non-zero value (with no effect)
242 /// otherwise. Note that it is impossible for an `Int64` to represent
243 /// more than a day in microseconds. Also note that the arguments may
244 /// be supplied using a mixture of positive, negative, and 0 values.
245 int assignIfValid(bsls::Types::Int64 days,
247
248 public:
249 // PUBLIC CLASS DATA
250
251 /// The maximum interval that is representable by a `DatetimeInterval`,
252 /// in milliseconds.
253 static const bsls::Types::Int64 k_MILLISECONDS_MAX = 185542587187199999LL;
254
255 /// The minimum interval that is representable by a `DatetimeInterval`,
256 /// in milliseconds.
259
260 // CLASS METHODS
261
262 /// Return `true` if a time interval object having the value given by
263 /// the specified `days`, and the optionally specified `hours`,
264 /// `minutes`, `seconds`, `milliseconds`, and `microseconds` can be
265 /// represented as a `DatetimeInterval` and `false` otherwise.
266 /// Unspecified arguments default to 0. The resulting time interval
267 /// value is valid if the days field does not overflow a 32-bit integer.
268 /// Note that the arguments may be supplied using a mixture of positive,
269 /// negative, and 0 values.
270 static
271 bool isValid(int days,
277
278 // Aspects
279
280 /// Return the maximum valid BDEX format version, as indicated by the
281 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
282 /// method. Note that it is highly recommended that `versionSelector`
283 /// be formatted as "YYYYMMDD", a date representation. Also note that
284 /// `versionSelector` should be a *compile*-time-chosen value that
285 /// selects a format version supported by both externalizer and
286 /// unexternalizer. See the `bslx` package-level documentation for more
287 /// information on BDEX streaming of value-semantic types and
288 /// containers.
289 static int maxSupportedBdexVersion(int versionSelector);
290
291 // CREATORS
292
293 /// Create a time interval object having the value 0.
295
296 /// Create a time interval object having the value given by the
297 /// specified `days`, and the optionally specified `hours`, `minutes`,
298 /// `seconds`, `milliseconds`, and `microseconds`. Unspecified
299 /// arguments default to 0. The behavior is undefined unless the
300 /// resulting time interval value is valid (i.e., the days field must
301 /// not overflow a 32-bit integer). Note that the arguments may be
302 /// supplied using a mixture of positive, negative, and 0 values.
303 explicit
310
311 /// Create a time interval object having the value of the specified
312 /// `original` time interval.
313 DatetimeInterval(const DatetimeInterval& original);
314
315 ~DatetimeInterval() = default;
316 // Destroy this time interval object. Note that this method's
317 // definition is generated by the compiler.
318
319 // MANIPULATORS
320
321 /// Assign to this object the value of the specified `rhs` time
322 /// interval, and return a reference providing modifiable access to this
323 /// object.
325
326 /// Add to this time interval the value of the specified `rhs` time
327 /// interval, and return a reference providing modifiable access to this
328 /// object. The behavior is undefined unless the resulting time
329 /// interval value is valid (i.e., the days field must not overflow a
330 /// 32-bit integer).
332
333 /// Subtract from this time interval the value of the specified `rhs`
334 /// time interval, and return a reference providing modifiable access to
335 /// this object. The behavior is undefined unless the resulting time
336 /// interval value is valid (i.e., the days field must not overflow a
337 /// 32-bit integer).
339
340 /// Set the time interval represented by this object to the value given
341 /// by the specified `days`, and the optionally specified `hours`,
342 /// `minutes`, `seconds`, `milliseconds`, and `microseconds`.
343 /// Unspecified arguments default to 0. The behavior is undefined
344 /// unless the resulting time interval value is valid (i.e., the days
345 /// field must not overflow a 32-bit integer). Note that the arguments
346 /// may be supplied using a mixture of positive, negative, and 0 values.
353
354 /// Set the time interval represented by this object to the value given
355 /// by the specified `days`, and the optionally specified `hours`,
356 /// `minutes`, `seconds`, `milliseconds`, and `microseconds`.
357 /// Unspecified arguments default to 0. Return 0 if the resulting time
358 /// interval value is valid (i.e., the `days` field must not overflow an
359 /// `int`) and a non-zero value (with no effect) otherwise. Note that
360 /// the arguments may be supplied using a mixture of positive, negative,
361 /// and 0 values.
368
369 /// Set the overall value of this object to indicate the specified
370 /// number of `days`.
371 void setTotalDays(int days);
372
373 /// Set the overall value of this object to indicate the specified
374 /// number of `hours`. The behavior is undefined unless the resulting
375 /// time interval value is valid (i.e., the days field must not overflow
376 /// a 32-bit integer).
378
379 /// Set the overall value of this object to indicate the specified
380 /// number of `hours`. Return 0 if the resulting time interval value is
381 /// valid (i.e., the `days` field must not overflow an `int`) and a
382 /// non-zero value (with no effect) otherwise.
384
385 /// Set the overall value of this object to indicate the specified
386 /// number of `minutes`. The behavior is undefined unless the resulting
387 /// time interval value is valid (i.e., the days field must not overflow
388 /// a 32-bit integer).
390
391 /// Set the overall value of this object to indicate the specified
392 /// number of `minutes`. Return 0 if the resulting time interval value
393 /// is valid (i.e., the `days` field must not overflow an `int`) and a
394 /// non-zero value (with no effect) otherwise.
396
397 /// Set the overall value of this object to indicate the specified
398 /// number of `seconds`. The behavior is undefined unless the resulting
399 /// time interval value is valid (i.e., the days field must not overflow
400 /// a 32-bit integer).
402
403 /// Set the overall value of this object to indicate the specified
404 /// number of `seconds`. Return 0 if the resulting time interval value
405 /// is valid (i.e., the `days` field must not overflow an `int`) and a
406 /// non-zero value (with no effect) otherwise.
408
409 /// Set the overall value of this object to indicate the specified
410 /// number of `seconds`. The fractional part of `seconds`, if any, is
411 /// rounded to the nearest whole number of microseconds. The behavior
412 /// is undefined unless the resulting time interval value is valid
413 /// (i.e., the days field must not overflow a 32-bit integer).
415
416 /// Set the overall value of this object to indicate the specified
417 /// number of `seconds`. The fractional part of `seconds`, if any, is
418 /// rounded to the nearest whole number of microseconds. Return 0 if
419 /// the resulting time interval value is valid (i.e., the `days` field
420 /// must not overflow an `int`) and a non-zero value (with no effect)
421 /// otherwise.
423
424 /// Set the overall value of this object to indicate the specified
425 /// number of `milliseconds`. The behavior is undefined unless the
426 /// resulting time interval value is valid (i.e., the days field must
427 /// not overflow a 32-bit integer).
429
430 /// Set the overall value of this object to indicate the specified
431 /// number of `milliseconds`. Return 0 if the resulting time interval
432 /// value is valid (i.e., the days field must not overflow an `int`) and
433 /// a non-zero value (with no effect) otherwise.
435
436 /// Set the overall value of this object to indicate the specified
437 /// number of `microseconds`. Note that there is no
438 /// `setTotalMicrosecondsIfValid` because no value of `microseconds` can
439 /// cause the number of days to overflow.
441
442 /// Add to this time interval the specified number of `days`, and the
443 /// optionally specified number of `hours`, `minutes`, `seconds`,
444 /// `milliseconds`, and `microseconds`, and return a reference providing
445 /// modifiable access to this object. Unspecified arguments default to
446 /// 0. The behavior is undefined unless the resulting time interval
447 /// value is valid (i.e., the days field must not overflow a 32-bit
448 /// integer). Note that the arguments may be supplied using a mixture
449 /// of positive, negative, and 0 values.
456
457 /// Add to this time interval the specified number of `days`, and the
458 /// optionally specified number of `hours`, `minutes`, `seconds`,
459 /// `milliseconds`, and `microseconds`. Return 0 if the resulting time
460 /// interval value is valid (i.e., the days field must not overflow an
461 /// `int`) and a non-zero value (with no effect) otherwise. Note that
462 /// the arguments may be supplied using a mixture of positive, negative,
463 /// and 0 values.
470
471 /// Add to this time interval the specified number of `days`, and return
472 /// a reference providing modifiable access to this object. The
473 /// behavior is undefined unless the resulting time interval value is
474 /// valid (i.e., the days field must not overflow a 32-bit integer).
476
477 /// Add to this time interval the specified number of `days`. Return 0
478 /// if the resulting time interval value is valid (i.e., the days field
479 /// must not overflow an `int`) and a non-zero value (with no effect)
480 /// otherwise.
481 int addDaysIfValid(int days);
482
483 /// Add to this time interval the specified number of `hours`, and
484 /// return a reference providing modifiable access to this object. The
485 /// behavior is undefined unless the resulting time interval value is
486 /// valid (i.e., the days field must not overflow a 32-bit integer).
488
489 /// Add to this time interval the specified number of `hours`. Return 0
490 /// if the resulting time interval value is valid (i.e., the days field
491 /// must not overflow an `int`) and a non-zero value (with no effect)
492 /// otherwise.
494
495 /// Add to this time interval the specified number of `minutes`, and
496 /// return a reference providing modifiable access to this object. The
497 /// behavior is undefined unless the resulting time interval value is
498 /// valid (i.e., the days field must not overflow a 32-bit integer).
500
501 /// Add to this time interval the specified number of `minutes`. Return
502 /// 0 if the resulting time interval value is valid (i.e., the days
503 /// field must not overflow an `int`) and a non-zero value (with no
504 /// effect) otherwise.
506
507 /// Add to this time interval the specified number of `seconds`, and
508 /// return a reference providing modifiable access to this object. The
509 /// behavior is undefined unless the resulting time interval value is
510 /// valid (i.e., the days field must not overflow a 32-bit integer).
512
513 /// Add to this time interval the specified number of `seconds`. Return
514 /// 0 if the resulting time interval value is valid (i.e., the days
515 /// field must not overflow an `int`) and a non-zero value (with no
516 /// effect) otherwise.
518
519 /// Add to this time interval the specified number of `milliseconds`,
520 /// and return a reference providing modifiable access to this object.
521 /// The behavior is undefined unless the resulting time interval value
522 /// is valid (i.e., the days field must not overflow a 32-bit integer).
524
525 /// Add to this time interval the specified number of `milliseconds`.
526 /// Return 0 if the resulting time interval value is valid (i.e., the
527 /// days 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 `microseconds`,
532 /// and return a reference providing modifiable access to this object.
533 /// The behavior is undefined unless the resulting time interval value
534 /// is valid (i.e., the days field must not overflow a 32-bit integer).
536
537 /// Add to this time interval the specified number of `microseconds`.
538 /// Return 0 if the resulting time interval value is valid (i.e., the
539 /// days field must not overflow an `int`) and a non-zero value (with no
540 /// effect) otherwise.
542
543 // Aspects
544
545 /// Assign to this object the value read from the specified input
546 /// `stream` using the specified `version` format, and return a
547 /// reference to `stream`. If `stream` is initially invalid, this
548 /// operation has no effect. If `version` is not supported, this object
549 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
550 /// If `version` is supported but `stream` becomes invalid during this
551 /// operation, this object has an undefined, but valid, state. Note
552 /// that no version is read from `stream`. See the `bslx` package-level
553 /// documentation for more information on BDEX streaming of
554 /// value-semantic types and containers.
555 template <class STREAM>
556 STREAM& bdexStreamIn(STREAM& stream, int version);
557
558 // ACCESSORS
559
560 /// Return the days field in the canonical representation of the value
561 /// of this time interval. Note that the return value may be negative.
562 /// Also note that the return value is the same as that returned by
563 /// `totalDays`.
564 int days() const;
565
566 /// Return the value of this time interval as an integral number of
567 /// microseconds modulo the number of microseconds in a day. Note that
568 /// the return value may be negative.
570
571 /// Return the hours field in the canonical representation of the value
572 /// of this time interval. Note that the return value may be negative.
573 int hours() const;
574
575 /// Return the minutes field in the canonical representation of the
576 /// value of this time interval. Note that the return value may be
577 /// negative.
578 int minutes() const;
579
580 /// Return the seconds field in the canonical representation of the
581 /// value of this time interval. Note that the return value may be
582 /// negative.
583 int seconds() const;
584
585 /// Return the milliseconds field in the canonical representation of the
586 /// value of this time interval. Note that the return value may be
587 /// negative.
588 int milliseconds() const;
589
590 /// Return the microseconds field in the canonical representation of the
591 /// value of this time interval. Note that the return value may be
592 /// negative.
593 int microseconds() const;
594
595 /// Efficiently write to the specified `result` buffer no more than the
596 /// specified `numBytes` of a representation of the value of this
597 /// object. Optionally specify `fractionalSecondPrecision` digits to
598 /// indicate how many fractional second digits to output. If
599 /// `fractionalSecondPrecision` is not specified then 6 fractional
600 /// second digits will be output (3 digits for milliseconds and 3 digits
601 /// for microseconds). Return the number of characters (not including
602 /// the null character) that would have been written if the limit due to
603 /// `numBytes` were not imposed. `result` is null-terminated unless
604 /// `numBytes` is 0. The behavior is undefined unless `0 <= numBytes`,
605 /// `0 <= fractionalSecondPrecision <= 6`, and `result` refers to at
606 /// least `numBytes` contiguous bytes. Note that the return value is
607 /// greater than or equal to `numBytes` if the output representation was
608 /// truncated to avoid `result` overrun.
609 int printToBuffer(char *result,
610 int numBytes,
611 int fractionalSecondPrecision = 6) const;
612
613 /// Return the value of this time interval in integral days, rounded
614 /// toward 0. Note that the return value may be negative. Also note
615 /// that the return value is the same as that returned by `days`.
616 int totalDays() const;
617
618 /// Return the value of this time interval in integral hours, rounded
619 /// toward 0. Note that the return value may be negative.
621
622 /// Return the value of this time interval in integral minutes, rounded
623 /// toward 0. Note that the return value may be negative.
625
626 /// Return the value of this time interval in integral seconds, rounded
627 /// toward 0. Note that the return value may be negative.
629
630 /// Return the value of this time interval in seconds as a `double`,
631 /// potentially with a fractional part. Note that the return value may
632 /// be negative. Also note that the conversion from the internal
633 /// representation to `double` may *lose* precision.
634 double totalSecondsAsDouble() const;
635
636 /// Return the value of this time interval in integral milliseconds,
637 /// rounded towards zero. Note that the return value may be negative.
639
640 /// Return the value of this time interval as an integral number of
641 /// microseconds. The behavior is undefined unless the number of
642 /// microseconds can be represented with a 64-bit signed integer. Note
643 /// that the return value may be negative.
645
646 // Aspects
647
648 /// Write the value of this object, using the specified `version`
649 /// format, to the specified output `stream`, and return a reference to
650 /// `stream`. If `stream` is initially invalid, this operation has no
651 /// effect. If `version` is not supported, `stream` is invalidated, but
652 /// otherwise unmodified. Note that `version` is not written to
653 /// `stream`. See the `bslx` package-level documentation for more
654 /// information on BDEX streaming of value-semantic types and
655 /// containers.
656 template <class STREAM>
657 STREAM& bdexStreamOut(STREAM& stream, int version) const;
658
659 /// Write the value of this object to the specified output `stream` in a
660 /// human-readable format, and return a reference to `stream`.
661 /// Optionally specify an initial indentation `level`, whose absolute
662 /// value is incremented recursively for nested objects. If `level` is
663 /// specified, optionally specify `spacesPerLevel`, whose absolute value
664 /// indicates the number of spaces per indentation level for this and
665 /// all of its nested objects. If `level` is negative, suppress
666 /// indentation of the first line. If `spacesPerLevel` is negative,
667 /// format the entire output on one line, suppressing all but the
668 /// initial indentation (as governed by `level`). If `stream` is not
669 /// valid on entry, this operation has no effect. Note that the format
670 /// is not fully specified, and can change without notice.
671 bsl::ostream& print(bsl::ostream& stream,
672 int level = 0,
673 int spacesPerLevel = 4) const;
674
675#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
676
677 // DEPRECATED METHODS
678
679 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
680 ///
681 /// Return the most current BDEX streaming version number supported by
682 /// this class.
683 static int maxSupportedBdexVersion();
684
685#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
686#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
687
688 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
689 ///
690 /// Return the most current BDEX streaming version number supported by
691 /// this class.
692 static int maxSupportedVersion();
693
694 /// @deprecated use `operator<<` or `print` instead.
695 ///
696 /// Format this datetime interval to the specified output `stream`, and
697 /// return a reference to `stream`.
698 bsl::ostream& streamOut(bsl::ostream& stream) const;
699
700#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
701
702};
703
704// FREE OPERATORS
705
706/// Return a `DatetimeInterval` object whose value is the sum of the
707/// specified `lhs` and `rhs` time intervals. The behavior is undefined
708/// unless the resulting time interval value is valid (i.e., the days field
709/// must not overflow a 32-bit integer).
711 const DatetimeInterval& rhs);
712
713/// Return a `DatetimeInterval` object whose value is the difference between
714/// the specified `lhs` and `rhs` time intervals. The behavior is undefined
715/// unless the resulting time interval value is valid (i.e., the days field
716/// must not overflow a 32-bit integer).
718 const DatetimeInterval& rhs);
719
720/// Return a `DatetimeInterval` object whose value is the negative of the
721/// specified time interval `value`. The behavior is undefined unless
722/// `INT_MIN < value.days()`.
724
725/// Return `true` if the specified `lhs` and `rhs` time intervals have the
726/// same value, and `false` otherwise. Two time intervals have the same
727/// value if all of the corresponding values of their days, hours, minutes,
728/// seconds, milliseconds, and microseconds fields are the same.
729bool operator==(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
730
731/// Return `true` if the specified `lhs` and `rhs` time intervals do not
732/// have the same value, and `false` otherwise. Two time intervals do not
733/// have the same value if any of the corresponding values of their days,
734/// hours, minutes, seconds, milliseconds, or microseconds fields is not
735/// the same.
736bool operator!=(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
737
738/// Return `true` if the nominal relation between the specified `lhs` and
739/// `rhs` time interval values holds, and `false` otherwise. `lhs` is less
740/// than `rhs` if the following expression evaluates to `true`:
741/// @code
742/// lhs.days() < rhs.days()
743/// || (lhs.days() == rhs.days() && lhs.fractionalDayInMicroseconds()
744/// < rhs.fractionalDayInMicroseconds())
745/// @endcode
746/// The other relationships are defined similarly.
747bool operator< (const DatetimeInterval& lhs, const DatetimeInterval& rhs);
748bool operator<=(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
749bool operator> (const DatetimeInterval& lhs, const DatetimeInterval& rhs);
750bool operator>=(const DatetimeInterval& lhs, const DatetimeInterval& rhs);
751
752/// Write the value of the specified `object` to the specified output
753/// `stream` in a single-line format, and return a reference providing
754/// modifiable access to `stream`. If `stream` is not valid on entry, this
755/// operation has no effect. Note that this human-readable format is not
756/// fully specified and can change without notice. Also note that this
757/// method has the same behavior as `object.print(stream, 0, -1)`.
758bsl::ostream& operator<<(bsl::ostream& stream, const DatetimeInterval& object);
759
760// FREE FUNCTIONS
761
762/// Pass the specified `object` to the specified `hashAlg`. This function
763/// integrates with the `bslh` modular hashing system and effectively
764/// provides a `bsl::hash` specialization for `DatetimeInterval`.
765template <class HASHALG>
766void hashAppend(HASHALG& hashAlg, const DatetimeInterval& object);
767
768// ============================================================================
769// INLINE DEFINITIONS
770// ============================================================================
771
772 // ----------------------
773 // class DatetimeInterval
774 // ----------------------
775
776// CLASS METHODS
777
778 // Aspects
779
780inline
782{
783 if (versionSelector >= 20170401) {
784 return 2; // RETURN
785 }
786 return 1;
787}
788
789// CREATORS
790inline
792: d_days(0)
793, d_microseconds(0)
794{
795}
796
797inline
799 bsls::Types::Int64 hours,
800 bsls::Types::Int64 minutes,
801 bsls::Types::Int64 seconds,
802 bsls::Types::Int64 milliseconds,
803 bsls::Types::Int64 microseconds)
804{
806 hours,
807 minutes,
808 seconds,
811}
812
813inline
815: d_days(original.d_days)
816, d_microseconds(original.d_microseconds)
817{
818}
819
820// MANIPULATORS
821inline
823{
824 d_days = rhs.d_days;
825 d_microseconds = rhs.d_microseconds;
826 return *this;
827}
828
829inline
831{
832#ifdef BSLS_ASSERT_IS_USED
833 int rc = addIntervalIfValid(rhs.d_days, 0, 0, 0, 0, rhs.d_microseconds);
834 BSLS_ASSERT(0 == rc && "operator+= over/under flow"); (void) rc;
835#else
836 addInterval(rhs.d_days, 0, 0, 0, 0, rhs.d_microseconds);
837#endif
838
839 return *this;
840}
841
842inline
844{
845 Int64 rhsDays = rhs.d_days;
846 Int64 rhsMicroseconds = rhs.d_microseconds;
847 if (INT_MIN == rhsDays) {
848 ++rhsDays;
849 rhsMicroseconds -= TimeUnitRatio::k_US_PER_D;
850 }
851 rhsDays = -rhsDays;
852 rhsMicroseconds = -rhsMicroseconds;
853 BSLS_ASSERT_SAFE(rhsDays <= INT_MAX && INT_MIN < rhsDays); // always true
854
855#ifdef BSLS_ASSERT_IS_USED
856 int rc = addIntervalIfValid(
857 static_cast<int>(rhsDays), 0, 0, 0, 0, rhsMicroseconds);
858 BSLS_ASSERT(0 == rc && "operator-= over/under flow"); (void) rc;
859#else
860 addInterval(static_cast<int>(rhsDays), 0, 0, 0, 0, rhsMicroseconds);
861#endif
862
863 return *this;
864}
865
866inline
868{
869 d_days = days;
870 d_microseconds = 0;
871}
872
873inline
879
880inline
887
888inline
894
895inline
902
903inline
909
910inline
917
918inline
925
926inline
934
935inline
941
942inline
944{
945 assign(static_cast<bsls::Types::Int64>(d_days)
946 + static_cast<bsls::Types::Int64>(days),
947 d_microseconds);
948 return *this;
949}
950
951inline
953{
954 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
955 + static_cast<bsls::Types::Int64>(days),
956 d_microseconds);
957}
958
959inline
961{
962 assign(static_cast<bsls::Types::Int64>(d_days)
964 d_microseconds +
966 return *this;
967}
968
969inline
971{
972 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
974 d_microseconds + (hours % TimeUnitRatio::k_H_PER_D) *
976}
977
978inline
980{
981 assign(static_cast<bsls::Types::Int64>(d_days)
983 d_microseconds +
985 return *this;
986}
987
988inline
990{
991 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
993 d_microseconds +
996}
997
998inline
1000{
1001 assign(static_cast<bsls::Types::Int64>(d_days)
1003 d_microseconds +
1005 return *this;
1006}
1007
1008inline
1010{
1011 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1013 d_microseconds +
1016}
1017
1018inline
1021{
1022 assign(static_cast<bsls::Types::Int64>(d_days)
1024 d_microseconds + milliseconds % TimeUnitRatio::k_MS_PER_D
1026 return *this;
1027}
1028
1029inline
1031{
1032 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1034 d_microseconds +
1037}
1038
1039inline
1042{
1043 assign(static_cast<bsls::Types::Int64>(d_days)
1045 d_microseconds + microseconds % TimeUnitRatio::k_US_PER_D);
1046 return *this;
1047}
1048
1049inline
1051{
1052 return assignIfValid(static_cast<bsls::Types::Int64>(d_days)
1054 d_microseconds +
1056}
1057
1058 // Aspects
1059
1060template <class STREAM>
1061STREAM& DatetimeInterval::bdexStreamIn(STREAM& stream, int version)
1062{
1063 if (stream) {
1064 switch (version) { // switch on the schema version
1065 case 2: {
1066 int tmpDays;
1067 stream.getInt32(tmpDays);
1068
1069 bsls::Types::Int64 tmpMicroseconds;
1070 stream.getInt64(tmpMicroseconds);
1071
1072 if ( stream
1073 && ( (0 <= tmpDays && 0 <= tmpMicroseconds)
1074 || (0 >= tmpDays && 0 >= tmpMicroseconds))
1075 && TimeUnitRatio::k_US_PER_D > tmpMicroseconds
1076 && -TimeUnitRatio::k_US_PER_D < tmpMicroseconds) {
1077 assign(tmpDays, tmpMicroseconds);
1078 }
1079 else {
1080 stream.invalidate();
1081 }
1082 } break;
1083 case 1: {
1085 stream.getInt64(tmp);
1086
1087 if ( stream
1088 && k_MILLISECONDS_MIN <= tmp && k_MILLISECONDS_MAX >= tmp) {
1090 }
1091 else {
1092 stream.invalidate();
1093 }
1094 } break;
1095 default: {
1096 stream.invalidate(); // unrecognized version number
1097 }
1098 }
1099 }
1100 return stream;
1101}
1102
1103// ACCESSORS
1104inline
1106{
1107 return d_days;
1108}
1109
1110inline
1112{
1113 return d_microseconds;
1114}
1115
1116inline
1118{
1119 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_H);
1120}
1121
1122inline
1124{
1125 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_M
1127}
1128
1129inline
1131{
1132 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_S
1134}
1135
1136inline
1138{
1139 return static_cast<int>(d_microseconds / TimeUnitRatio::k_US_PER_MS
1141}
1142
1143inline
1145{
1146 return static_cast<int>(d_microseconds % TimeUnitRatio::k_US_PER_MS);
1147}
1148
1149inline
1151{
1152 return d_days;
1153}
1154
1155inline
1157{
1158 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_H_PER_D
1159 + d_microseconds / TimeUnitRatio::k_US_PER_H;
1160}
1161
1162inline
1164{
1165 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_M_PER_D
1166 + d_microseconds / TimeUnitRatio::k_US_PER_M;
1167}
1168
1169inline
1171{
1172 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_S_PER_D
1173 + d_microseconds / TimeUnitRatio::k_US_PER_S;
1174}
1175
1176inline
1178{
1179 return d_days * static_cast<double>(TimeUnitRatio::k_S_PER_D) +
1180 static_cast<double>(d_microseconds) /
1181 static_cast<double>(TimeUnitRatio::k_US_PER_S);
1182}
1183
1184inline
1186{
1187 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_MS_PER_D
1188 + d_microseconds / TimeUnitRatio::k_US_PER_MS;
1189}
1190
1191inline
1193{
1194 BSLS_REVIEW( 0 >= d_days
1195 || (bsl::numeric_limits<bsls::Types::Int64>::max() -
1196 d_microseconds) / TimeUnitRatio::k_US_PER_D >= d_days);
1197
1198#if !defined(BSLS_PLATFORM_CMP_SUN) \
1199 || !defined(BDE_BUILD_TARGET_OPT) \
1200 || BSLS_PLATFORM_CMP_VERSION >= 0x5140
1201
1202 // Older versions of the Sun compiler (e.g., 5.12.3 and 5.12.4) fail to
1203 // compile the following 'BSLS_REVIEW' correctly in optimized builds.
1204
1205 BSLS_REVIEW( 0 <= d_days
1206 || (bsl::numeric_limits<bsls::Types::Int64>::min() -
1207 d_microseconds) / TimeUnitRatio::k_US_PER_D <= d_days);
1208
1209#endif
1210
1211 return static_cast<bsls::Types::Int64>(d_days) * TimeUnitRatio::k_US_PER_D
1212 + d_microseconds;
1213}
1214
1215 // Aspects
1216
1217template <class STREAM>
1218STREAM& DatetimeInterval::bdexStreamOut(STREAM& stream, int version) const
1219{
1220 if (stream) {
1221 switch (version) { // switch on the schema version
1222 case 2: {
1223 stream.putInt32(d_days);
1224 stream.putInt64(d_microseconds);
1225 } break;
1226 case 1: {
1227 stream.putInt64(totalMilliseconds());
1228 } break;
1229 default: {
1230 stream.invalidate(); // unrecognized version number
1231 }
1232 }
1233 }
1234 return stream;
1235}
1236
1237#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
1238
1239// DEPRECATED METHODS
1240inline
1245
1246#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
1247#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
1248inline
1253
1254#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
1255
1256} // close package namespace
1257
1258// FREE OPERATORS
1259inline
1260bdlt::DatetimeInterval bdlt::operator+(const DatetimeInterval& lhs,
1261 const DatetimeInterval& rhs)
1262{
1263 DatetimeInterval ret(lhs);
1264
1265#ifdef BSLS_ASSERT_IS_USED
1266 int rc = ret.addIntervalIfValid(0, 0, 0, 0,
1267 rhs.totalMilliseconds(), rhs.microseconds());
1268 BSLS_ASSERT(0 == rc && "operator+ over/under flow"); (void) rc;
1269#else
1270 ret.addInterval(0, 0, 0, 0, rhs.totalMilliseconds(), rhs.microseconds());
1271#endif
1272
1273 return ret;
1274}
1275
1276inline
1277bdlt::DatetimeInterval bdlt::operator-(const DatetimeInterval& lhs,
1278 const DatetimeInterval& rhs)
1279{
1280 DatetimeInterval ret(lhs);
1281
1282#ifdef BSLS_ASSERT_IS_USED
1283 int rc = ret.addIntervalIfValid(0, 0, 0, 0,
1284 -rhs.totalMilliseconds(), -rhs.microseconds());
1285 BSLS_ASSERT(0 == rc && "operator- over/under flow"); (void) rc;
1286#else
1287 ret.addInterval(0, 0, 0, 0, -rhs.totalMilliseconds(), -rhs.microseconds());
1288#endif
1289
1290 return ret;
1291}
1292
1293inline
1294bdlt::DatetimeInterval bdlt::operator-(const DatetimeInterval& value)
1295{
1296 BSLS_REVIEW(value.d_days > bsl::numeric_limits<int32_t>::min());
1297
1298 DatetimeInterval interval;
1299
1300 interval.d_days = -value.d_days;
1301 interval.d_microseconds = -value.d_microseconds;
1302
1303 return interval;
1304}
1305
1306inline
1307bool bdlt::operator==(const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1308{
1309 return lhs.d_days == rhs.d_days
1310 && lhs.d_microseconds == rhs.d_microseconds;
1311}
1312
1313inline
1314bool bdlt::operator!=(const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1315{
1316 return lhs.d_days != rhs.d_days
1317 || lhs.d_microseconds != rhs.d_microseconds;
1318}
1319
1320inline
1321bool bdlt::operator< (const DatetimeInterval& lhs,
1322 const DatetimeInterval& rhs)
1323{
1324 return lhs.d_days < rhs.d_days
1325 || ( lhs.d_days == rhs.d_days
1326 && lhs.d_microseconds < rhs.d_microseconds);
1327}
1328
1329inline
1330bool bdlt::operator<=(const DatetimeInterval& lhs,
1331 const DatetimeInterval& rhs)
1332{
1333 return lhs.d_days < rhs.d_days
1334 || ( lhs.d_days == rhs.d_days
1335 && lhs.d_microseconds <= rhs.d_microseconds);
1336}
1337
1338inline
1339bool bdlt::operator> (const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1340{
1341 return lhs.d_days > rhs.d_days
1342 || ( lhs.d_days == rhs.d_days
1343 && lhs.d_microseconds > rhs.d_microseconds);
1344}
1345
1346inline
1347bool bdlt::operator>=(const DatetimeInterval& lhs, const DatetimeInterval& rhs)
1348{
1349 return lhs.d_days > rhs.d_days
1350 || ( lhs.d_days == rhs.d_days
1351 && lhs.d_microseconds >= rhs.d_microseconds);
1352}
1353
1354inline
1355bsl::ostream& bdlt::operator<<(bsl::ostream& stream,
1356 const DatetimeInterval& object)
1357{
1358 return object.print(stream, 0, -1);
1359}
1360
1361// FREE FUNCTIONS
1362template <class HASHALG>
1363void bdlt::hashAppend(HASHALG& hashAlg, const DatetimeInterval& object)
1364{
1365 using ::BloombergLP::bslh::hashAppend;
1366 hashAppend(hashAlg, object.d_days);
1367 hashAppend(hashAlg, object.d_microseconds);
1368}
1369
1370
1371
1372namespace bsl {
1373
1374// TRAITS
1375
1376/// This template specialization for `is_trivially_copyable` indicates that
1377/// `DatetimeInterval` is a trivially copyable type.
1378template <>
1379struct is_trivially_copyable<BloombergLP::bdlt::DatetimeInterval> :
1381};
1382
1383} // close namespace bsl
1384
1385#endif
1386
1387// ----------------------------------------------------------------------------
1388// Copyright 2017 Bloomberg Finance L.P.
1389//
1390// Licensed under the Apache License, Version 2.0 (the "License");
1391// you may not use this file except in compliance with the License.
1392// You may obtain a copy of the License at
1393//
1394// http://www.apache.org/licenses/LICENSE-2.0
1395//
1396// Unless required by applicable law or agreed to in writing, software
1397// distributed under the License is distributed on an "AS IS" BASIS,
1398// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1399// See the License for the specific language governing permissions and
1400// limitations under the License.
1401// ----------------------------- END-OF-FILE ----------------------------------
1402
1403/** @} */
1404/** @} */
1405/** @} */
Definition bdlt_datetimeinterval.h:201
int days() const
Definition bdlt_datetimeinterval.h:1105
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:1009
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:1163
int totalDays() const
Definition bdlt_datetimeinterval.h:1150
DatetimeInterval & addMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:1041
int milliseconds() const
Definition bdlt_datetimeinterval.h:1137
static const bsls::Types::Int64 k_MILLISECONDS_MIN
Definition bdlt_datetimeinterval.h:257
int seconds() const
Definition bdlt_datetimeinterval.h:1130
int addMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:989
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_datetimeinterval.h:1061
void setTotalDays(int days)
Definition bdlt_datetimeinterval.h:867
int setTotalHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:881
DatetimeInterval & operator-=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:843
void setTotalMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:936
DatetimeInterval & operator=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:822
bsls::Types::Int64 totalSeconds() const
Definition bdlt_datetimeinterval.h:1170
int setTotalMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:927
void setTotalMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:889
void setTotalMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:919
double totalSecondsAsDouble() const
Definition bdlt_datetimeinterval.h:1177
DatetimeInterval & addHours(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:960
int setTotalSecondsIfValid(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:911
int addMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:1030
void setTotalHours(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:874
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:1123
bsls::Types::Int64 fractionalDayInMicroseconds() const
Definition bdlt_datetimeinterval.h:1111
static int maxSupportedVersion()
Definition bdlt_datetimeinterval.h:1249
DatetimeInterval & addDays(int days)
Definition bdlt_datetimeinterval.h:943
int addMicrosecondsIfValid(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:1050
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:1117
int microseconds() const
Definition bdlt_datetimeinterval.h:1144
bsls::Types::Int64 totalMilliseconds() const
Definition bdlt_datetimeinterval.h:1185
bsl::ostream & streamOut(bsl::ostream &stream) const
int addHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:970
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:791
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:830
void setTotalSecondsFromDouble(double seconds)
DatetimeInterval & addMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:979
bsls::Types::Int64 totalMicroseconds() const
Definition bdlt_datetimeinterval.h:1192
int setTotalMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:896
int addDaysIfValid(int days)
Definition bdlt_datetimeinterval.h:952
DatetimeInterval & addMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:1020
friend bool operator<=(const DatetimeInterval &, const DatetimeInterval &)
DatetimeInterval & addSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:999
static int maxSupportedBdexVersion()
Definition bdlt_datetimeinterval.h:1241
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_datetimeinterval.h:1218
friend bool operator>=(const DatetimeInterval &, const DatetimeInterval &)
friend void hashAppend(HASHALG &, const DatetimeInterval &)
void setTotalSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:904
friend bool operator<(const DatetimeInterval &, const DatetimeInterval &)
static const bsls::Types::Int64 k_MILLISECONDS_MAX
Definition bdlt_datetimeinterval.h:253
bsls::Types::Int64 totalHours() const
Definition bdlt_datetimeinterval.h:1156
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_REVIEW(X)
Definition bsls_review.h:949
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
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 bdlb_printmethods.h:283
static const bsls::Types::Int64 k_M_PER_D
Definition bdlt_timeunitratio.h:290
static const bsls::Types::Int64 k_S_PER_M
Definition bdlt_timeunitratio.h:285
static const bsls::Types::Int64 k_MS_PER_S
Definition bdlt_timeunitratio.h:280
static const bsls::Types::Int64 k_US_PER_H
Definition bdlt_timeunitratio.h:277
static const bsls::Types::Int64 k_M_PER_H
Definition bdlt_timeunitratio.h:289
static const bsls::Types::Int64 k_US_PER_MS
Definition bdlt_timeunitratio.h:273
static const bsls::Types::Int64 k_US_PER_D
Definition bdlt_timeunitratio.h:278
static const bsls::Types::Int64 k_H_PER_D
Definition bdlt_timeunitratio.h:292
static const bsls::Types::Int64 k_US_PER_S
Definition bdlt_timeunitratio.h:275
static const bsls::Types::Int64 k_US_PER_M
Definition bdlt_timeunitratio.h:276
static const bsls::Types::Int64 k_S_PER_D
Definition bdlt_timeunitratio.h:287
static const bsls::Types::Int64 k_MILLISECONDS_PER_DAY
Definition bdlt_timeunitratio.h:249
static const bsls::Types::Int64 k_MS_PER_D
Definition bdlt_timeunitratio.h:283
long long Int64
Definition bsls_types.h:132