BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt_datetime.h
Go to the documentation of this file.
1/// @file bdlt_datetime.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_datetime.h -*-C++-*-
8#ifndef INCLUDED_BDLT_DATETIME
9#define INCLUDED_BDLT_DATETIME
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlt_datetime bdlt_datetime
15/// @brief Provide a value-semantic type representing both date and time.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlt
19/// @{
20/// @addtogroup bdlt_datetime
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlt_datetime-purpose"> Purpose</a>
25/// * <a href="#bdlt_datetime-classes"> Classes </a>
26/// * <a href="#bdlt_datetime-description"> Description </a>
27/// * <a href="#bdlt_datetime-valid-bdlt-datetime-values-and-their-representations"> Valid bdlt::Datetime Values and Their Representations </a>
28/// * <a href="#bdlt_datetime-attributes"> Attributes </a>
29/// * <a href="#bdlt_datetime-iso-standard-text-representation"> ISO Standard Text Representation </a>
30/// * <a href="#bdlt_datetime-usage"> Usage </a>
31/// * <a href="#bdlt_datetime-example-1-basic-syntax"> Example 1: Basic Syntax </a>
32/// * <a href="#bdlt_datetime-example-2-creating-a-schedule-of-equal-time-intervals"> Example 2: Creating a Schedule of Equal Time Intervals </a>
33///
34/// # Purpose {#bdlt_datetime-purpose}
35/// Provide a value-semantic type representing both date and time.
36///
37/// # Classes {#bdlt_datetime-classes}
38///
39/// - bdlt::Datetime: date and time value (at least microsecond resolution)
40///
41/// @see bdlt_date, bdlt_time, bdlt_datetimetz
42///
43/// # Description {#bdlt_datetime-description}
44/// This component implements a value-semantic type,
45/// `bdlt::Datetime`, that represents the composition of a date and a time
46/// value. The combined "date+time" value of a `bdlt::Datetime` object is
47/// expressed textually as "yyyy/mm/dd_hh:mm:ss.ssssss", where "yyyy/mm/dd"
48/// represents the "date" part of the value and "hh:mm:ss.ssssss" represents the
49/// "time" part.
50///
51/// In addition to the usual value-semantic complement of methods for getting
52/// and setting value, the `bdlt::Datetime` class provides methods and operators
53/// for making relative adjustments to value (`addDays`, `addTime`, `addHours`,
54/// etc.). In particular, note that adding units of time to a `bdlt::Datetime`
55/// object can affect the values of both the time and date parts of the object.
56/// For example, invoking `addHours(2)` on a `bdlt::Datetime` object whose value
57/// is "1987/10/03_22:30:00.000000" updates the value to
58/// "1987/10/04_00:30:00.000000".
59///
60/// ## Valid bdlt::Datetime Values and Their Representations {#bdlt_datetime-valid-bdlt-datetime-values-and-their-representations}
61///
62///
63/// The "date" part of a `bdlt::Datetime` value has a range of validity
64/// identical to a `bdlt::Date` object -- i.e., valid dates (according to the
65/// Unix [POSIX] calendar) having years in the range `[1 .. 9999]`. The valid
66/// time values are `[00:00:00.000000 .. 23:59:59.999999]`. Furthermore, the
67/// unset time value (i.e., 24:00:00.000000, corresponding to the default
68/// constructed value for `bdlt::Time`) is available for every valid date. Note
69/// that the supported range of time does *not* allow for the injection of leap
70/// seconds. The value "0001/01/01_24:00:00.000000" is the default constructed
71/// value of `bdlt::Datetime`.
72///
73/// Furthermore, consistent with the `bdlt::Time` type, a `bdlt::Datetime`
74/// object whose "time" part has the default constructed value, behaves the
75/// same, with respect to manipulators and (most) free operators, as if the
76/// "time" part had the value 00:00:00.000000. As for `bdlt::Time`, the
77/// behavior of all `bdlt::Datetime` relational comparison operators is
78/// undefined if the "time" part of either operand is 24:00:00.000000.
79/// Consequently, `bdlt::Datetime` objects whose "time" part has the default
80/// constructed value must *not* be used as keys for the standard associative
81/// containers, since `operator<` is not defined for such objects.
82///
83/// ## Attributes {#bdlt_datetime-attributes}
84///
85///
86/// Conceptually, the two primary attributes of `bdlt::Datetime` are the
87/// constituent date and time values. These attributes are given the special
88/// designation "part" in this component (i.e., the "time" part and the "date"
89/// part, respectively) to distinguish them from the many other attributes (see
90/// below) that derive from these two main parts.
91/// @code
92/// Name Related Type Default Range
93/// ---- ------------ --------------- ------------------------------------
94/// date bdlt::Date 0001/01/01 [0001/01/01 .. 9999/12/31]
95/// time bdlt::Time 24:00:00.000000 [00:00:00.000000 .. 23:59:59.999999]
96/// @endcode
97/// A `bdlt::Datetime` object can be used in terms of its "date" and "time"
98/// parts or, if appropriate to an application, the object can be viewed as a
99/// single, integrated type having the combined individual attributes of date
100/// and time. Accessors and manipulators are provided for each of these eight
101/// (derived) attributes:
102/// @code
103/// Name Type Default Range Constraint
104/// ----------- ---- ------- ----------- -----------------------------
105/// year int 1 [1 .. 9999] none
106/// month int 1 [1 .. 12] none
107/// day int 1 [1 .. 31] must exist for year and month
108/// hour int 24 [0 .. 24] none
109/// minute int 0 [0 .. 59] must be 0 if '24 == hour'
110/// second int 0 [0 .. 59] must be 0 if '24 == hour'
111/// millisecond int 0 [0 .. 999] must be 0 if '24 == hour'
112/// microsecond int 0 [0 .. 999] must be 0 if '24 == hour'
113/// @endcode
114/// There are two additional "date" part attributes to `bdlt::Datetime`:
115/// @code
116/// Name Type Default Range Constraint
117/// --------- --------------------- ------- ------------ ----------------------
118/// dayOfYear int 1 [ 1 .. 366] 366 only on leap years
119/// dayOfWeek bdlt::DayOfWeek::Enum SAT [SUN .. SAT] tied to calendar day
120/// @endcode
121/// where `dayOfYear` tracks the value of `year/month/day` (and *vice* *versa*),
122/// and `dayOfWeek` can be accessed but not explicitly set.
123///
124/// ## ISO Standard Text Representation {#bdlt_datetime-iso-standard-text-representation}
125///
126///
127/// A common standard text representation of a date and time value is described
128/// by ISO 8601. BDE provides the @ref bdlt_iso8601util component for conversion
129/// to and from the standard ISO8601 format.
130///
131/// ## Usage {#bdlt_datetime-usage}
132///
133///
134/// This section illustrates intended use of this component.
135///
136/// ### Example 1: Basic Syntax {#bdlt_datetime-example-1-basic-syntax}
137///
138///
139/// Values represented by objects of type `bdlt::Datetime` are used widely in
140/// practice. The values of the individual attributes resulting from a
141/// default-constructed `bdlt::Datetime` object, `dt`, are
142/// "0001/01/01_24:00:00.000000":
143/// @code
144/// bdlt::Datetime dt; assert( 1 == dt.date().year());
145/// assert( 1 == dt.date().month());
146/// assert( 1 == dt.date().day());
147/// assert(24 == dt.hour());
148/// assert( 0 == dt.minute());
149/// assert( 0 == dt.second());
150/// assert( 0 == dt.millisecond());
151/// assert( 0 == dt.microsecond());
152/// @endcode
153/// We can then set `dt` to have a specific value, say, 8:43pm on January 6,
154/// 2013:
155/// @code
156/// dt.setDatetime(2013, 1, 6, 20, 43);
157/// assert(2013 == dt.date().year());
158/// assert( 1 == dt.date().month());
159/// assert( 6 == dt.date().day());
160/// assert( 20 == dt.hour());
161/// assert( 43 == dt.minute());
162/// assert( 0 == dt.second());
163/// assert( 0 == dt.millisecond());
164/// assert( 0 == dt.microsecond());
165/// @endcode
166/// Now suppose we add 6 hours and 9 seconds to this value. There is more than
167/// one way to do it:
168/// @code
169/// bdlt::Datetime dt2(dt);
170/// dt2.addHours(6);
171/// dt2.addSeconds(9);
172/// assert(2013 == dt2.date().year());
173/// assert( 1 == dt2.date().month());
174/// assert( 7 == dt2.date().day());
175/// assert( 2 == dt2.hour());
176/// assert( 43 == dt2.minute());
177/// assert( 9 == dt2.second());
178/// assert( 0 == dt2.millisecond());
179/// assert( 0 == dt2.microsecond());
180///
181/// bdlt::Datetime dt3(dt);
182/// dt3.addTime(6, 0, 9);
183/// assert(dt2 == dt3);
184/// @endcode
185/// Notice that (in both cases) the date changed as a result of adding time;
186/// however, changing just the date never affects the time:
187/// @code
188/// dt3.addDays(10);
189/// assert(2013 == dt3.date().year());
190/// assert( 1 == dt3.date().month());
191/// assert( 17 == dt3.date().day());
192/// assert( 2 == dt3.hour());
193/// assert( 43 == dt3.minute());
194/// assert( 9 == dt3.second());
195/// assert( 0 == dt3.millisecond());
196/// assert( 0 == dt3.microsecond());
197/// @endcode
198/// We can also add more than a day's worth of time:
199/// @code
200/// dt2.addHours(240);
201/// assert(dt3 == dt2);
202/// @endcode
203/// The individual arguments can also be negative:
204/// @code
205/// dt2.addTime(-246, 0, -10, 1000); // -246 h, -10 s, +1000 ms
206/// assert(dt == dt2);
207/// @endcode
208/// Finally, we stream the value of `dt2` to `stdout`:
209/// @code
210/// bsl::cout << dt2 << bsl::endl;
211/// @endcode
212/// The streaming operator produces the following output on `stdout`:
213/// @code
214/// 06JAN2013_20:43:00.000000
215/// @endcode
216///
217/// ### Example 2: Creating a Schedule of Equal Time Intervals {#bdlt_datetime-example-2-creating-a-schedule-of-equal-time-intervals}
218///
219///
220/// Calculations involving date and time values are difficult to get correct
221/// manually; consequently, people tend to schedule events on natural time
222/// boundaries (e.g., on the hour) even if that is sub-optimal. Having a class
223/// such as `bdlt::Datetime` makes doing date and time calculations trivial.
224///
225/// Suppose one wants to divide into an arbitrary interval such as the time
226/// between sunset and sunrise into an arbitrary number (say 7) of equal
227/// intervals (perhaps to use as a duty roster for teams making astronomical
228/// observations).
229///
230/// First, we create objects containing values for the start and end of the time
231/// interval:
232/// @code
233/// bdlt::Datetime sunset(2014, 6, 26, 20, 31, 23); // New York City
234/// bdlt::Datetime sunrise(2014, 6, 27, 5, 26, 51); // New York City
235/// @endcode
236/// Then, we calculate the length of each shift in milliseconds (for good
237/// precision -- we may be synchronizing astronomical instruments). Note that
238/// the difference of `sunrise` and `sunset` creates a temporary
239/// `bdlt::DatetimeInterval` object:
240/// @code
241/// const int numShifts = 7;
242/// const bsls::Types::Int64 shiftLengthInMsec
243/// = (sunrise - sunset).totalMilliseconds()
244/// / numShifts;
245/// @endcode
246/// Now, we calculate (and print to `stdout`) the beginning and end times for
247/// each shift:
248/// @code
249/// for (int i = 0; i <= numShifts; ++i) {
250/// bdlt::Datetime startOfShift(sunset);
251/// startOfShift.addMilliseconds(shiftLengthInMsec * i);
252/// bsl::cout << startOfShift << bsl::endl;
253/// }
254/// @endcode
255/// Finally, we observe:
256/// @code
257/// 26JUN2014_20:31:23.000000
258/// 26JUN2014_21:47:52.714000
259/// 26JUN2014_23:04:22.428000
260/// 27JUN2014_00:20:52.142000
261/// 27JUN2014_01:37:21.856000
262/// 27JUN2014_02:53:51.570000
263/// 27JUN2014_04:10:21.284000
264/// 27JUN2014_05:26:50.998000
265/// @endcode
266/// Notice how our objects (since they manage both "date" and "time of day"
267/// parts of each point in time) seamlessly handle the transition between the
268/// two days.
269/// @}
270/** @} */
271/** @} */
272
273/** @addtogroup bdl
274 * @{
275 */
276/** @addtogroup bdlt
277 * @{
278 */
279/** @addtogroup bdlt_datetime
280 * @{
281 */
282
283#include <bdlscm_version.h>
284
285#include <bdlt_date.h>
286#include <bdlt_datetimeimputil.h>
288#include <bdlt_dayofweek.h>
289#include <bdlt_time.h>
290#include <bdlt_timeunitratio.h>
291
292#include <bdlb_bitutil.h>
293
294#include <bslh_hash.h>
295
298
299#include <bsls_assert.h>
300#include <bsls_atomic.h>
301#include <bsls_log.h>
302#include <bsls_performancehint.h>
303#include <bsls_platform.h>
304#include <bsls_preconditions.h>
305#include <bsls_review.h>
307#include <bsls_timeinterval.h>
308#include <bsls_types.h>
309
310#include <bsl_iosfwd.h>
311#include <bsl_cstring.h> // memset
312#include <bsl_sstream.h>
313
314
315namespace bdlt {
316
317 // ==============
318 // class Datetime
319 // ==============
320
321/// This class implements a simply-constrained value-semantic type
322/// representing the composition of date and time values. Valid date values
323/// for the "date" part of a `Datetime` object are the same as those defined
324/// for `Date` objects; similarly, valid time values for the "time" part of
325/// a `Datetime` object are similar to those defined for `Time` objects (but
326/// with additional precision). Relational operators are disallowed on
327/// `Datetime` objects whose "time" part has the same value as that of a
328/// default constructed `Time` object.
329///
330/// See @ref bdlt_datetime
331class Datetime {
332
333 // PRIVATE TYPES
334 enum {
335 k_NUM_TIME_BITS = 37,
336 k_DEFAULT_FRACTIONAL_SECOND_PRECISION = 6
337 };
338
339 // CLASS DATA
340 static const bsls::Types::Uint64 k_MAX_US_FROM_EPOCH;
341
342 static const bsls::Types::Uint64 k_REP_MASK = 0x8000000000000000ULL;
343 static const bsls::Types::Uint64 k_DATE_MASK = 0xffffffe000000000ULL;
344 static const bsls::Types::Uint64 k_TIME_MASK = 0x0000001fffffffffULL;
345
346 static bsls::AtomicInt64 s_invalidRepresentationCount;
347
348 // DATA
349 bsls::Types::Uint64 d_value; // encoded offset from the epoch
350
351 // FRIENDS
353
354 friend bool operator==(const Datetime&, const Datetime&);
355 friend bool operator!=(const Datetime&, const Datetime&);
356 friend bool operator< (const Datetime&, const Datetime&);
357 friend bool operator<=(const Datetime&, const Datetime&);
358 friend bool operator> (const Datetime&, const Datetime&);
359 friend bool operator>=(const Datetime&, const Datetime&);
360 template <class HASHALG>
361 friend void hashAppend(HASHALG& hashAlg, const Datetime&);
362
363 // PRIVATE MANIPULATOR
364
365 /// Assign to `d_value` the representation of a datetime such that the
366 /// difference between this datetime and the epoch is the specified
367 /// `totalMicroseconds`.
368 void setMicrosecondsFromEpoch(bsls::Types::Uint64 totalMicroseconds);
369
370 // PRIVATE ACCESSORS
371
372 /// Return the difference, measured in microseconds, between this
373 /// datetime value, with 24:00:00.000000 converted to 0:00:00.000000,
374 /// and the epoch.
375 bsls::Types::Uint64 microsecondsFromEpoch() const;
376
377 /// If `d_value` is a valid representation, return `d_value`.
378 /// Otherwise, return the representation of the datetime corresponding
379 /// to the datetime implied by assuming the value in `d_value` is the
380 /// concatenation of a `Date` and a `Time`, and log or assert the
381 /// detection of an invalid date.
382 bsls::Types::Uint64 updatedRepresentation() const;
383
384 /// Return `true` if the representation is valid. Invoke a review
385 /// failure notifying of an invalid use of a `bdlt::Datetime` instance
386 /// and return `false` if the representation is invalid and
387 /// `BSLS_ASSERT_SAFE` is inactive. The behavior is undefined if the
388 /// representation is invalid and `BSLS_ASSERT_SAFE` is active.
389 bool validateAndTraceLogRepresentation() const;
390
391 public:
392 // CLASS METHODS
393
394 /// Return `true` if the specified `year`, `month`, and `day` attribute
395 /// values, and the optionally specified `hour`, `minute`, `second`,
396 /// `millisecond`, and `microsecond` attribute values, represent a valid
397 /// `Datetime` value, and `false` otherwise. Unspecified trailing
398 /// optional parameters default to 0. `year`, `month`, `day`, `hour`,
399 /// `minute`, `second`, `millisecond`, and `microsecond` attribute
400 /// values represent a valid `Datetime` value if
401 /// `true == Date::isValidYearMonthDay(year, month, day)`,
402 /// `0 <= hour < 24`, `0 <= minute < 60`, `0 <= second < 60`,
403 /// `0 <= millisecond < 1000`, and `0 <= microsecond < 1000`.
404 /// Additionally, a valid `year`, `month`, `day` with the time portion
405 /// equal to 24:00:00.000000 also represents a valid `Datetime` value.
406 static bool isValid(int year,
407 int month,
408 int day,
409 int hour = 0,
410 int minute = 0,
411 int second = 0,
412 int millisecond = 0,
413 int microsecond = 0);
414
415 // Aspects
416
417 /// Return the maximum valid BDEX format version, as indicated by the
418 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
419 /// method. Note that it is highly recommended that `versionSelector`
420 /// be formatted as "YYYYMMDD", a date representation. Also note that
421 /// `versionSelector` should be a *compile*-time-chosen value that
422 /// selects a format version supported by both externalizer and
423 /// unexternalizer. See the `bslx` package-level documentation for more
424 /// information on BDEX streaming of value-semantic types and
425 /// containers.
426 static int maxSupportedBdexVersion(int versionSelector);
427
428 // CREATORS
429
430 /// Create a `Datetime` object whose "date" and "time" parts have their
431 /// respective default-constructed values, "0001/01/01" and
432 /// "24:00:00.000000".
433 Datetime();
434
435 /// Create a `Datetime` object whose "date" part has the value of the
436 /// specified `date` and whose "time" part has the value
437 /// "00:00:00.000000".
438 Datetime(const Date& date); // IMPLICIT
439
440 /// Create a `Datetime` object whose "date" and "time" parts have the
441 /// values of the specified `date` and `time`, respectively.
442 Datetime(const Date& date, const Time& time);
443
444 /// Create a `Datetime` object whose "date" part has the value
445 /// represented by the specified `year`, `month`, and `day` attributes,
446 /// and whose "time" part has the value represented by the optionally
447 /// specified `hour`, `minute`, `second`, `millisecond`, and
448 /// `microsecond` attributes. Unspecified trailing optional parameters
449 /// default to 0. The behavior is undefined unless the eight attributes
450 /// (collectively) represent a valid `Datetime` value (see `isValid`).
451 Datetime(int year,
452 int month,
453 int day,
454 int hour = 0,
455 int minute = 0,
456 int second = 0,
457 int millisecond = 0,
458 int microsecond = 0);
459
460 /// Create a `Datetime` object having the value of the specified
461 /// `original` object.
462 Datetime(const Datetime& original);
463
464 ~Datetime() = default;
465 // Destroy this 'Datetime' object.
466
467 // MANIPULATORS
468
469 /// Assign to this object the value of the specified `rhs` object, and
470 /// return a reference providing modifiable access to this object.
471 Datetime& operator=(const Datetime& rhs);
472
473 /// Add to this object the value of the specified `rhs` object, and
474 /// return a reference providing modifiable access to this object. If
475 /// `24 == hour()` on entry, set the `hour` attribute of this object to
476 /// 0 before performing the addition. The behavior is undefined unless
477 /// the resulting value is valid for `Datetime` (see `isValid`).
479
480 /// Subtract from this object the value of the specified `rhs` object,
481 /// and return a reference providing modifiable access to this object.
482 /// If `24 == hour()` on entry, set the `hour` attribute of this object
483 /// to 0 before performing the subtraction. The behavior is undefined
484 /// unless the resulting value is valid for `Datetime` (see `isValid`).
486
487 /// Add to this object the value of the specified `rhs` object, and
488 /// return a reference providing modifiable access to this object. If
489 /// `24 == hour()` on entry, set the `hour` attribute of this object to
490 /// 0 before performing the addition. The behavior is undefined unless
491 /// the resulting value is valid for `Datetime` (see `isValid`).
493
494 /// Subtract from this object the value of the specified `rhs` object,
495 /// and return a reference providing modifiable access to this object.
496 /// If `24 == hour()` on entry, set the `hour` attribute of this object
497 /// to 0 before performing the subtraction. The behavior is undefined
498 /// unless the resulting value is valid for `Datetime` (see `isValid`).
500
501 /// Set the value of this object to a `Datetime` whose "date" part has
502 /// the value represented by the specified `date`, and whose "time" part
503 /// has the value represented by the optionally specified `hour`,
504 /// `minute`, `second`, `millisecond`, and `microsecond` attributes.
505 /// Unspecified trailing optional parameters default to 0. The behavior
506 /// is undefined unless the attributes (collectively) represent a valid
507 /// `Datetime` value (see `isValid`).
508 void setDatetime(const Date& date,
509 int hour = 0,
510 int minute = 0,
511 int second = 0,
512 int millisecond = 0,
513 int microsecond = 0);
514
515 /// Set the value of this object to a `Datetime` whose "date" part has
516 /// the value represented by the specified `date`, and whose "time" part
517 /// has the value represented by the specified `time`.
518 void setDatetime(const Date& date, const Time& time);
519
520 /// Set the value of this object to a `Datetime` whose "date" part has
521 /// the value represented by the specified `year`, `month`, and `day`
522 /// attributes, and whose "time" part has the value represented by the
523 /// optionally specified `hour`, `minute`, `second`, `millisecond`, and
524 /// `microsecond` attributes. Unspecified trailing optional parameters
525 /// default to 0. The behavior is undefined unless the eight attributes
526 /// (collectively) represent a valid `Datetime` value (see `isValid`).
527 void setDatetime(int year,
528 int month,
529 int day,
530 int hour = 0,
531 int minute = 0,
532 int second = 0,
533 int millisecond = 0,
534 int microsecond = 0);
535
536 /// Set the "date" part of this object to have the value represented by
537 /// the specified `year`, `month`, and `day` attributes, and set the
538 /// "time" part to have the value represented by the optionally
539 /// specified `hour`, `minute`, `second`, `millisecond`, and
540 /// `microsecond` attributes, if the eight attribute values
541 /// (collectively) represent a valid `Datetime` value (see `isValid`).
542 /// Unspecified trailing optional parameters default to 0. Return 0 on
543 /// success, and a non-zero value (with no effect) otherwise.
544 int setDatetimeIfValid(int year,
545 int month,
546 int day,
547 int hour = 0,
548 int minute = 0,
549 int second = 0,
550 int millisecond = 0,
551 int microsecond = 0);
552
553 /// Set the value of this object to a `Datetime` whose "date" part has
554 /// the value represented by the specified `date`, and whose "time" part
555 /// has the value represented by the optionally specified `hour`,
556 /// `minute`, `second`, `millisecond`, and `microsecond` attributes, if
557 /// the attribute values (collectively) represent a valid `Datetime`
558 /// value (see `isValid`). Unspecified trailing optional parameters
559 /// default to 0. Return 0 on success, and a non-zero value (with no
560 /// effect) otherwise.
561 int setDatetimeIfValid(const Date& date,
562 int hour = 0,
563 int minute = 0,
564 int second = 0,
565 int millisecond = 0,
566 int microsecond = 0);
567
568 /// Set the "date" part of this object to have the value of the
569 /// specified `date`. Note that this method has no effect on the "time"
570 /// part of this object.
571 void setDate(const Date& date);
572
573 /// Set the "date" part of this object to have the value represented by
574 /// the specified `year` and `dayOfYear` attribute values. The behavior
575 /// is undefined unless `year` and `dayOfYear` represent a valid `Date`
576 /// value (i.e., `true == Date::isValidYearDay(year, dayOfYear)`). Note
577 /// that this method has no effect on the "time" part of this object.
578 void setYearDay(int year, int dayOfYear);
579
580 /// Set this object to have the value represented by the specified
581 /// `year` and `dayOfYear` if they comprise a valid `Date` value (see
582 /// `Date::isValidYearDay`). Return 0 on success, and a non-zero value
583 /// (with no effect) otherwise.
584 int setYearDayIfValid(int year, int dayOfYear);
585
586 /// Set the "date" part of this object to have the value represented by
587 /// the specified `year`, `month`, and `day` attribute values. The
588 /// behavior is undefined unless `year`, `month`, and `day` represent a
589 /// valid `Date` value (i.e.,
590 /// `true == Date::isValidYearMonthDay(year, month, day)`). Note that
591 /// this method has no effect on the "time" part of this object.
592 void setYearMonthDay(int year, int month, int day);
593
594 /// Set this object to have the value represented by the specified
595 /// `year`, `month`, and `day` if they comprise a valid `Date` value
596 /// (see `Date::isValidYearMonthDay`). Return 0 on success, and a
597 /// non-zero value (with no effect) otherwise.
598 int setYearMonthDayIfValid(int year, int month, int day);
599
600 /// Set the "time" part of this object to have the value of the
601 /// specified `time`. Note that this method has no effect on the "date"
602 /// part of this object.
603 void setTime(const Time& time);
604
605 /// Set the "time" part of this object to have the value represented by
606 /// the specified `hour` attribute value and the optionally specified
607 /// `minute`, `second`, `millisecond`, and `microsecond` attribute
608 /// values. Unspecified trailing optional parameters default to 0. The
609 /// behavior is undefined unless `hour`, `minute`, `second`,
610 /// `millisecond`, and `microsecond` represent a valid "time" portion of
611 /// a `Datetime` value. Note that this method has no effect on the
612 /// "date" part of this object.
613 void setTime(int hour,
614 int minute = 0,
615 int second = 0,
616 int millisecond = 0,
617 int microsecond = 0);
618
619 /// Set the "time" part of this object to have the value represented by
620 /// the specified `hour` attribute value and the optionally specified
621 /// `minute`, `second`, `millisecond`, and `microsecond` attribute
622 /// values if they comprise a valid "time" portion of a `DateTime`
623 /// value. Unspecified trailing optional parameters default to 0.
624 /// Return 0 on success, and a non-zero value (with no effect)
625 /// otherwise. Note that this method has no effect on the "date" part
626 /// of this object.
627 int setTimeIfValid(int hour,
628 int minute = 0,
629 int second = 0,
630 int millisecond = 0,
631 int microsecond = 0);
632
633 /// Set the "hour" attribute of this object to the specified `hour`
634 /// value. If `24 == hour`, set the `minute`, `second`, `millisecond`,
635 /// and `microsecond` attributes to 0. The behavior is undefined
636 /// unless `0 <= hour <= 24`. Note that this method has no effect on
637 /// the "date" part of this object.
638 void setHour(int hour);
639
640 /// Set the "hour" attribute of this object to the specified `hour`
641 /// value if `0 <= hour <= 24`. If `24 == hour`, set the `minute`,
642 /// `second`, `millisecond`, and `microsecond` attributes to 0. Return
643 /// 0 on success, and a non-zero value (with no effect) otherwise. Note
644 /// that this method has no effect on the "date" part of this object.
645 int setHourIfValid(int hour);
646
647 /// Set the "minute" attribute of this object to the specified `minute`
648 /// value. If `24 == hour()`, set the `hour` attribute to 0. The
649 /// behavior is undefined unless `0 <= minute <= 59`. Note that this
650 /// method has no effect on the "date" part of this object.
651 void setMinute(int minute);
652
653 /// Set the "minute" attribute of this object to the specified `minute`
654 /// value if `0 <= minute <= 59`. If `24 == hour()`, set the `hour`
655 /// attribute to 0. Return 0 on success, and a non-zero value (with no
656 /// effect) otherwise. Note that this method has no effect on the
657 /// "date" part of this object.
658 int setMinuteIfValid(int minute);
659
660 /// Set the "second" attribute of this object to the specified `second`
661 /// value. If `24 == hour()`, set the `hour` attribute to 0. The
662 /// behavior is undefined unless `0 <= second <= 59`. Note that this
663 /// method has no effect on the "date" part of this object.
664 void setSecond(int second);
665
666 /// Set the "second" attribute of this object to the specified `second`
667 /// value if `0 <= second <= 59`. If `24 == hour()`, set the `hour`
668 /// attribute to 0. Return 0 on success, and a non-zero value (with no
669 /// effect) otherwise. Note that this method has no effect on the
670 /// "date" part of this object.
671 int setSecondIfValid(int second);
672
673 /// Set the "millisecond" attribute of this object to the specified
674 /// `millisecond` value. If `24 == hour()`, set the `hour` attribute to
675 /// 0. The behavior is undefined unless `0 <= millisecond <= 999`.
676 /// Note that this method has no effect on the "date" part of this
677 /// object.
678 void setMillisecond(int millisecond);
679
680 /// Set the "millisecond" attribute of this object to the specified
681 /// `millisecond` value if `0 <= millisecond <= 999`. If
682 /// `24 == hour()`, set the `hour` attribute to 0. Return 0 on success,
683 /// and a non-zero value (with no effect) otherwise. Note that this
684 /// method has no effect on the "date" part of this object.
686
687 /// Set the "microsecond" attribute of this object to the specified
688 /// `microsecond` value. If `24 == hour()`, set the `hour` attribute to
689 /// 0. The behavior is undefined unless `0 <= microsecond <= 999`.
690 /// Note that this method has no effect on the "date" part of this
691 /// object.
692 void setMicrosecond(int microsecond);
693
694 /// Set the "microsecond" attribute of this object to the specified
695 /// `microsecond` value if `0 <= microsecond <= 999`. If
696 /// `24 == hour()`, set the `hour` attribute to 0. Return 0 on success,
697 /// and a non-zero value (with no effect) otherwise. Note that this
698 /// method has no effect on the "date" part of this object.
700
701 /// Add the specified number of `days` to the value of this object.
702 /// Return a reference providing modifiable access to this object. The
703 /// behavior is undefined unless the resulting value is in the valid
704 /// range for a `Datetime` object. Note that this method has no effect
705 /// on the "time" part of this object. Also note that `days` may be
706 /// positive, 0, or negative.
707 Datetime& addDays(int days);
708
709 /// Add the specified number of `days` to the value of this object, if
710 /// the resulting value is in the valid range for a `Datetime` object.
711 /// Return 0 on success, and a non-zero value (with no effect)
712 /// otherwise. Note that this method has no effect on the "time" part
713 /// of this object. Also note that `days` may be positive, 0, or
714 /// negative.
715 int addDaysIfValid(int days);
716
717 /// Add the specified number of `hours`, and the optionally specified
718 /// number of `minutes`, `seconds`, `milliseconds`, and `microseconds`
719 /// to the value of this object, adjusting the "date" part of this
720 /// object accordingly. Unspecified trailing optional parameters
721 /// default to 0. Return a reference providing modifiable access to
722 /// this object. If `24 == hour()` on entry, set the `hour` attribute
723 /// to 0 before performing the addition. The behavior is undefined
724 /// unless the resulting value is in the valid range for a `Datetime`
725 /// object. Note that each argument independently may be positive,
726 /// negative, or 0.
728 bsls::Types::Int64 minutes = 0,
729 bsls::Types::Int64 seconds = 0,
730 bsls::Types::Int64 milliseconds = 0,
731 bsls::Types::Int64 microseconds = 0);
732
733 /// Add the specified number of `hours`, and the optionally specified
734 /// number of `minutes`, `seconds`, `milliseconds`, and `microseconds`
735 /// to the value of this object, adjusting the "date" part of this
736 /// object accordingly, if the resulting value is in the valid range for
737 /// a `Datetime` object. Unspecified trailing optional parameters
738 /// default to 0. If `24 == hour()` on entry, set the `hour` attribute
739 /// to 0 before performing the addition. Return 0 on success, and a
740 /// non-zero value (with no effect) otherwise. Note that each argument
741 /// independently may be positive, negative, or 0.
743 bsls::Types::Int64 minutes = 0,
744 bsls::Types::Int64 seconds = 0,
745 bsls::Types::Int64 milliseconds = 0,
746 bsls::Types::Int64 microseconds = 0);
747
748 /// Add the specified number of `hours` to the value of this object,
749 /// adjusting the "date" part of the object accordingly. Return a
750 /// reference providing modifiable access to this object. If
751 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
752 /// performing the addition. The behavior is undefined unless the
753 /// resulting value is in the valid range for a `Datetime` object. Note
754 /// that `hours` may be positive, negative, or 0.
756
757 /// Add the specified number of `hours` to the value of this object,
758 /// adjusting the "date" part of the object accordingly, if the
759 /// resulting value is in the valid range for a `Datetime` object. If
760 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
761 /// performing the addition. Return 0 on success, and a non-zero value
762 /// (with no effect) otherwise. Note that `hours` may be positive,
763 /// negative, or 0.
765
766 /// Add the specified number of `minutes` to the value of this object,
767 /// adjusting the "date" part of the object accordingly. Return a
768 /// reference providing modifiable access to this object. If
769 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
770 /// performing the addition. The behavior is undefined unless the
771 /// resulting value is in the valid range for a `Datetime` object. Note
772 /// that `minutes` may be positive, negative, or 0.
774
775 /// Add the specified number of `minutes` to the value of this object,
776 /// adjusting the "date" part of the object accordingly, if the
777 /// resulting value is in the valid range for a `Datetime` object. If
778 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
779 /// performing the addition. Return 0 on success, and a non-zero value
780 /// (with no effect) otherwise. Note that `minutes` may be positive,
781 /// negative, or 0.
783
784 /// Add the specified number of `seconds` to the value of this object,
785 /// adjusting the "date" part of the object accordingly. Return a
786 /// reference providing modifiable access to this object. If
787 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
788 /// performing the addition. The behavior is undefined unless the
789 /// resulting value is in the valid range for a `Datetime` object. Note
790 /// that `seconds` may be positive, negative, or 0.
792
793 /// Add the specified number of `seconds` to the value of this object,
794 /// adjusting the "date" part of the object accordingly, if the
795 /// resulting value is in the valid range for a `Datetime` object. If
796 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
797 /// performing the addition. Return 0 on success, and a non-zero value
798 /// (with no effect) otherwise. Note that `seconds` may be positive,
799 /// negative, or 0.
801
802 /// Add the specified number of `milliseconds` to the value of this
803 /// object, adjusting the "date" part of the object accordingly. Return
804 /// a reference providing modifiable access to this object. If
805 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
806 /// performing the addition. The behavior is undefined unless the
807 /// resulting value is in the valid range for a `Datetime` object. Note
808 /// that `milliseconds` may be positive, negative, or 0.
810
811 /// Add the specified number of `milliseconds` to the value of this
812 /// object, adjusting the "date" part of the object accordingly, if the
813 /// resulting value is in the valid range for a `Datetime` object. If
814 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
815 /// performing the addition. Return 0 on success, and a non-zero value
816 /// (with no effect) otherwise. Note that `milliseconds` may be
817 /// positive, negative, or 0.
819
820 /// Add the specified number of `microseconds` to the value of this
821 /// object, adjusting the "date" part of the object accordingly. Return
822 /// a reference providing modifiable access to this object. If
823 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
824 /// performing the addition. The behavior is undefined unless the
825 /// resulting value is in the valid range for a `Datetime` object. Note
826 /// that `microseconds` may be positive, negative, or 0.
828
829 /// Add the specified number of `microseconds` to the value of this
830 /// object, adjusting the "date" part of the object accordingly, if the
831 /// resulting value is in the valid range for a `Datetime` object. If
832 /// `24 == hour()` on entry, set the `hour` attribute to 0 before
833 /// performing the addition. Return 0 on success, and a non-zero value
834 /// (with no effect) otherwise. Note that `microseconds` may be
835 /// positive, negative, or 0.
837
838 // Aspects
839
840 /// Assign to this object the value read from the specified input
841 /// `stream` using the specified `version` format, and return a
842 /// reference to `stream`. If `stream` is initially invalid, this
843 /// operation has no effect. If `version` is not supported, this object
844 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
845 /// If `version` is supported but `stream` becomes invalid during this
846 /// operation, this object has an undefined, but valid, state. Note
847 /// that no version is read from `stream`. See the `bslx` package-level
848 /// documentation for more information on BDEX streaming of
849 /// value-semantic types and containers.
850 template <class STREAM>
851 STREAM& bdexStreamIn(STREAM& stream, int version);
852
853 // ACCESSORS
854
855 /// Return the value of the "date" part of this object.
856 Date date() const;
857
858 /// Return the value of the `day` (of the month) attribute of this
859 /// object.
860 int day() const;
861
862 /// Return the value of the `dayOfWeek` attribute associated with the
863 /// `day` (of the month) attribute of this object.
865
866 /// Return the value of the `dayOfYear` attribute of this object.
867 int dayOfYear() const;
868
869 /// Load, into the specified `hour`, and the optionally specified
870 /// `minute`, `second`, `millisecond`, and `microsecond` the respective
871 /// `hour`, `minute`, `second`, `millisecond`, and `microsecond`
872 /// attribute values from this time object. Unspecified arguments
873 /// default to 0. Supplying 0 for an address argument suppresses the
874 /// loading of the value for the corresponding attribute, but has no
875 /// effect on the loading of other attribute values.
876 void getTime(int *hour,
877 int *minute = 0,
878 int *second = 0,
879 int *millisecond = 0,
880 int *microsecond = 0) const;
881
882 /// Return the value of the `hour` attribute of this object.
883 int hour() const;
884
885 /// Return the value of the `microsecond` attribute of this object.
886 int microsecond() const;
887
888 /// Return the value of the `millisecond` attribute of this object.
889 int millisecond() const;
890
891 /// Return the value of the `minute` attribute of this object.
892 int minute() const;
893
894 /// Return the value of the `month` attribute of this object.
895 int month() const;
896
897 /// Return the value of the `second` attribute of this object.
898 int second() const;
899
900 /// Return the value of the "time" part of this object.
901 Time time() const;
902
903 /// Return the value of the `year` attribute of this object.
904 int year() const;
905
906 /// Efficiently write to the specified `result` buffer no more than the
907 /// specified `numBytes` of a representation of the value of this
908 /// object. Optionally specify `fractionalSecondPrecision` digits to
909 /// indicate how many fractional second digits to output. If
910 /// `fractionalSecondPrecision` is not specified then 6 fractional
911 /// second digits will be output (3 digits for milliseconds and 3 digits
912 /// for microseconds). Return the number of characters (not including
913 /// the null character) that would have been written if the limit due to
914 /// `numBytes` were not imposed. `result` is null-terminated unless
915 /// `numBytes` is 0. The behavior is undefined unless `0 <= numBytes`,
916 /// `0 <= fractionalSecondPrecision <= 6`, and `result` refers to at
917 /// least `numBytes` contiguous bytes. Note that the return value is
918 /// greater than or equal to `numBytes` if the output representation was
919 /// truncated to avoid `result` overrun.
920 int printToBuffer(char *result,
921 int numBytes,
922 int fractionalSecondPrecision = 6) const;
923
924 // Aspects
925
926 /// Write the value of this object, using the specified `version`
927 /// format, to the specified output `stream`, and return a reference to
928 /// `stream`. If `stream` is initially invalid, this operation has no
929 /// effect. If `version` is not supported, `stream` is invalidated, but
930 /// otherwise unmodified. Note that `version` is not written to
931 /// `stream`. See the `bslx` package-level documentation for more
932 /// information on BDEX streaming of value-semantic types and
933 /// containers.
934 template <class STREAM>
935 STREAM& bdexStreamOut(STREAM& stream, int version) const;
936
937 /// Write the value of this object to the specified output `stream` in a
938 /// human-readable format, and return a reference to `stream`.
939 /// Optionally specify an initial indentation `level`, whose absolute
940 /// value is incremented recursively for nested objects. If `level` is
941 /// specified, optionally specify `spacesPerLevel`, whose absolute value
942 /// indicates the number of spaces per indentation level for this and
943 /// all of its nested objects. If `level` is negative, suppress
944 /// indentation of the first line. If `spacesPerLevel` is negative,
945 /// format the entire output on one line, suppressing all but the
946 /// initial indentation (as governed by `level`). If `stream` is not
947 /// valid on entry, this operation has no effect. Note that this
948 /// human-readable format is not fully specified, and can change without
949 /// notice.
950 bsl::ostream& print(bsl::ostream& stream,
951 int level = 0,
952 int spacesPerLevel = 4) const;
953
954#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
955
956 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
957 ///
958 /// Return the most current BDEX streaming version number supported by
959 /// this class.
960 static int maxSupportedBdexVersion();
961
962#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
963#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
964
965 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
966 ///
967 /// Return the most current BDEX streaming version number supported by
968 /// this class.
969 static int maxSupportedVersion();
970
971 /// @deprecated Use @ref print instead.
972 ///
973 /// Format this datetime to the specified output `stream` and return a
974 /// reference to the modifiable `stream`.
975 bsl::ostream& streamOut(bsl::ostream& stream) const;
976
977 /// @deprecated Use @ref setDatetimeIfValid instead.
978 ///
979 /// Set the "date" part of this object's value to the specified `year`,
980 /// `month`, and `day`, and the "time" part to the optionally specified
981 /// `hour`, `minute`, `second`, and `millisecond`, if they represent a
982 /// valid `Datetime` value, with trailing fields that are not specified
983 /// set to 0. Return 0 on success, and a non-zero value (with no
984 /// effect) otherwise.
986 int month,
987 int day,
988 int hour = 0,
989 int minute = 0,
990 int second = 0,
991 int millisecond = 0);
992
993#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
994
995};
996
997// FREE OPERATORS
998
999/// Return a `Datetime` object having a value that is the sum of the
1000/// specified `lhs` (`Datetime`) and the specified `rhs`
1001/// (`bsls::TimeInterval`). If `24 == lhs.hour()`, the result is the same
1002/// as if the `hour` attribute of `lhs` is 0. The behavior is undefined
1003/// unless the resulting value is in the valid range for a `Datetime`
1004/// object.
1006
1007/// Return a `Datetime` object having a value that is the sum of the
1008/// specified `lhs` (`bsls::TimeInterval`) and the specified `rhs`
1009/// (`Datetime`). If `24 == rhs.hour()`, the result is the same as if the
1010/// `hour` attribute of `rhs` is 0. The behavior is undefined unless the
1011/// resulting value is in the valid range for a `Datetime` object.
1013
1014/// Return a `Datetime` object having a value that is the sum of the
1015/// specified `lhs` (`Datetime`) and the specified `rhs`
1016/// (`DatetimeInterval`). If `24 == lhs.hour()`, the result is the same as
1017/// if the `hour` attribute of `lhs` is 0. The behavior is undefined unless
1018/// the resulting value is in the valid range for a `Datetime` object.
1020
1021/// Return a `Datetime` object having a value that is the sum of the
1022/// specified `lhs` (`DatetimeInterval`) and the specified `rhs`
1023/// (`Datetime`). If `24 == rhs.hour()`, the result is the same as if the
1024/// `hour` attribute of `rhs` is 0. The behavior is undefined unless the
1025/// resulting value is in the valid range for a `Datetime` object.
1027
1028/// Return a `Datetime` object having a value that is the difference between
1029/// the specified `lhs` (`Datetime`) and the specified `rhs`
1030/// (`bsls::TimeInterval`). If `24 == lhs.hour()`, the result is the same
1031/// as if the `hour` attribute of `lhs` is 0. The behavior is undefined
1032/// unless the resulting value is in the valid range for a `Datetime`
1033/// object.
1035
1036/// Return a `Datetime` object having a value that is the difference between
1037/// the specified `lhs` (`Datetime`) and the specified `rhs`
1038/// (`DatetimeInterval`). If `24 == lhs.hour()`, the result is the same as
1039/// if the `hour` attribute of `lhs` is 0. The behavior is undefined unless
1040/// the resulting value is in the valid range for a `Datetime` object.
1042
1043/// Return a `DatetimeInterval` object having a value that is the difference
1044/// between the specified `lhs` (`Datetime`) and the specified `rhs`
1045/// (`Datetime`). If the `hour` attribute of either operand is 24, the
1046/// result is the same as if that `hour` attribute is 0. The behavior is
1047/// undefined unless the resulting value is in the valid range for a
1048/// `DatetimeInterval` object.
1050
1051/// Return `true` if the specified `lhs` and `rhs` objects have the same
1052/// value, and `false` otherwise. Two `Datetime` objects have the same
1053/// value if they have the same values for their "date" and "time" parts,
1054/// respectively.
1055bool operator==(const Datetime& lhs, const Datetime& rhs);
1056
1057/// Return `true` if the specified `lhs` and `rhs` `Datetime` objects do not
1058/// have the same value, and `false` otherwise. Two `Datetime` objects do
1059/// not have the same value if they do not have the same values for either
1060/// of their "date" or "time" parts, respectively.
1061bool operator!=(const Datetime& lhs, const Datetime& rhs);
1062
1063/// Return `true` if the value of the specified `lhs` object is less than
1064/// the value of the specified `rhs` object, and `false` otherwise. A
1065/// `Datetime` object `a` is less than a `Datetime` object `b` if
1066/// `a.date() < b.date()`, or if `a.date() == b.date()` and the time portion
1067/// of `a` is less than the time portion of `b`. The behavior is undefined
1068/// unless `24 != lhs.hour() && 24 != rhs.hour()`.
1069bool operator<(const Datetime& lhs, const Datetime& rhs);
1070
1071/// Return `true` if the value of the specified `lhs` object is less than or
1072/// equal to the value of the specified `rhs` object, and `false` otherwise.
1073/// The behavior is undefined unless `24 != lhs.hour() && 24 != rhs.hour()`.
1074bool operator<=(const Datetime& lhs, const Datetime& rhs);
1075
1076/// Return `true` if the value of the specified `lhs` object is greater than
1077/// the value of the specified `rhs` object, and `false` otherwise. A
1078/// `Datetime` object `a` is greater than a `Datetime` object `b` if
1079/// `a.date() > b.date()`, or if `a.date() == b.date()` and the time portion
1080/// of `a` is greater than the time portion of `b`. The behavior is
1081/// undefined unless `24 != lhs.hour() && 24 != rhs.hour()`.
1082bool operator>(const Datetime& lhs, const Datetime& rhs);
1083
1084/// Return `true` if the value of the specified `lhs` object is greater than
1085/// or equal to the value of the specified `rhs` object, and `false`
1086/// otherwise. The behavior is undefined unless
1087/// `24 != lhs.hour() && 24 != rhs.hour()`.
1088bool operator>=(const Datetime& lhs, const Datetime& rhs);
1089
1090/// Write the value of the specified `object` object to the specified output
1091/// `stream` in a single-line format, and return a reference to `stream`.
1092/// If `stream` is not valid on entry, this operation has no effect. Note
1093/// that this human-readable format is not fully specified, can change
1094/// without notice, and is logically equivalent to:
1095/// @code
1096/// print(stream, 0, -1);
1097/// @endcode
1098bsl::ostream& operator<<(bsl::ostream& stream, const Datetime& object);
1099
1100// FREE FUNCTIONS
1101
1102/// Pass the specified `object` to the specified `hashAlg`. This function
1103/// integrates with the `bslh` modular hashing system and effectively
1104/// provides a `bsl::hash` specialization for `Datetime`.
1105template <class HASHALG>
1106void hashAppend(HASHALG& hashAlg, const Datetime& object);
1107
1108// ============================================================================
1109// INLINE DEFINITIONS
1110// ============================================================================
1111
1112 // --------------
1113 // class Datetime
1114 // --------------
1115
1116// PRIVATE MANIPULATOR
1117inline
1118void Datetime::setMicrosecondsFromEpoch(bsls::Types::Uint64 totalMicroseconds)
1119{
1120 d_value = ((totalMicroseconds / TimeUnitRatio::k_US_PER_D)
1121 << k_NUM_TIME_BITS)
1122 + totalMicroseconds % TimeUnitRatio::k_US_PER_D;
1123 d_value |= k_REP_MASK;
1124}
1125
1126// PRIVATE ACCESSORS
1127inline
1128bsls::Types::Uint64 Datetime::microsecondsFromEpoch() const
1129{
1130 if (validateAndTraceLogRepresentation()) {
1131 int h = hour();
1132
1133 bsls::Types::Uint64 value = d_value & (~k_REP_MASK);
1134
1135 if (TimeUnitRatio::k_H_PER_D_32 != h) {
1136 return (value >> k_NUM_TIME_BITS) * TimeUnitRatio::k_US_PER_D
1137 + (value & k_TIME_MASK); // RETURN
1138 }
1139
1140 return (value >> k_NUM_TIME_BITS)
1141 * TimeUnitRatio::k_US_PER_D; // RETURN
1142 }
1143
1144#if BSLS_PLATFORM_IS_LITTLE_ENDIAN
1145 bsls::Types::Uint64 days = (d_value & 0xffffffff) - 1;
1146 bsls::Types::Uint64 milliseconds =
1147 (d_value >> 32) % TimeUnitRatio::k_MS_PER_D_32;
1148#else
1149 bsls::Types::Uint64 days = (d_value >> 32) - 1;
1150 bsls::Types::Uint64 milliseconds =
1151 (d_value & 0xffffffff) % TimeUnitRatio::k_MS_PER_D_32;
1152#endif
1153
1154 return TimeUnitRatio::k_US_PER_D * days
1155 + TimeUnitRatio::k_US_PER_MS * milliseconds;
1156}
1157
1158inline
1159bsls::Types::Uint64 Datetime::updatedRepresentation() const
1160{
1161 if (validateAndTraceLogRepresentation()) {
1162 return d_value; // RETURN
1163 }
1164
1165#if BSLS_PLATFORM_IS_LITTLE_ENDIAN
1166 bsls::Types::Uint64 days = (d_value & 0xffffffff) - 1;
1167 bsls::Types::Uint64 milliseconds = d_value >> 32;
1168#else
1169 bsls::Types::Uint64 days = (d_value >> 32) - 1;
1170 bsls::Types::Uint64 milliseconds = d_value & 0xffffffff;
1171#endif
1172
1173 return (days << k_NUM_TIME_BITS)
1174 | (TimeUnitRatio::k_US_PER_MS * milliseconds)
1175 | k_REP_MASK;
1176}
1177
1178inline
1179bool Datetime::validateAndTraceLogRepresentation() const
1180{
1181 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(k_REP_MASK <= d_value)) {
1182 return true; // RETURN
1183 }
1185 0 && "detected invalid 'bdlt::Datetime'; see TEAM 579660115");
1187 "detected invalid 'bdlt::Datetime'; see TEAM 579660115");
1188
1189 return false;
1190}
1191
1192// CLASS METHODS
1193inline
1194bool Datetime::isValid(int year,
1195 int month,
1196 int day,
1197 int hour,
1198 int minute,
1199 int second,
1200 int millisecond,
1201 int microsecond)
1202{
1207 0 <= millisecond && millisecond
1209 0 <= microsecond && microsecond
1212 0 == minute &&
1213 0 == second &&
1214 0 == millisecond &&
1215 0 == microsecond));
1216}
1217
1218 // Aspects
1219
1220inline
1222{
1223 if (versionSelector >= 20160411) {
1224 return 2; // RETURN
1225 }
1226 return 1;
1227}
1228
1229// CREATORS
1230inline
1232: d_value(TimeUnitRatio::k_US_PER_D)
1233{
1234 d_value |= k_REP_MASK;
1235}
1236
1237inline
1239: d_value(static_cast<bsls::Types::Uint64>(date - Date()) << k_NUM_TIME_BITS)
1240{
1241 d_value |= k_REP_MASK;
1242}
1243
1244inline
1245Datetime::Datetime(const Date& date, const Time& time)
1246{
1248}
1249
1250inline
1252 int month,
1253 int day,
1254 int hour,
1255 int minute,
1256 int second,
1257 int millisecond,
1258 int microsecond)
1259{
1261 month,
1262 day,
1263 hour,
1264 minute,
1265 second,
1267 microsecond);
1268}
1269
1270inline
1272: d_value(original.d_value)
1273{
1274 d_value = updatedRepresentation();
1275}
1276
1277// MANIPULATORS
1278inline
1280{
1281 d_value = rhs.d_value;
1282 d_value = updatedRepresentation();
1283
1284 return *this;
1285}
1286
1287inline
1289{
1291 <= static_cast<bsls::Types::Int64>(
1292 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1293
1295 <= static_cast<bsls::Types::Int64>(
1296 microsecondsFromEpoch()));
1297
1298 bsls::Types::Uint64 totalMicroseconds =
1299 microsecondsFromEpoch() + rhs.totalMicroseconds();
1300 setMicrosecondsFromEpoch(totalMicroseconds);
1301
1302 return *this;
1303}
1304
1305inline
1307{
1309 <= static_cast<bsls::Types::Int64>(
1310 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1311
1313 <= static_cast<bsls::Types::Int64>(
1314 microsecondsFromEpoch()));
1315
1316 bsls::Types::Uint64 totalMicroseconds =
1317 microsecondsFromEpoch() - rhs.totalMicroseconds();
1318 setMicrosecondsFromEpoch(totalMicroseconds);
1319
1320 return *this;
1321}
1322
1323inline
1325{
1327 <= static_cast<bsls::Types::Int64>(
1328 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1329
1331 <= static_cast<bsls::Types::Int64>(
1332 microsecondsFromEpoch()));
1333
1334 bsls::Types::Uint64 totalMicroseconds =
1335 microsecondsFromEpoch() + rhs.totalMicroseconds();
1336 setMicrosecondsFromEpoch(totalMicroseconds);
1337
1338 return *this;
1339}
1340
1341inline
1343{
1345 <= static_cast<bsls::Types::Int64>(
1346 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1347
1349 <= static_cast<bsls::Types::Int64>(
1350 microsecondsFromEpoch()));
1351
1352 bsls::Types::Uint64 totalMicroseconds =
1353 microsecondsFromEpoch() - rhs.totalMicroseconds();
1354 setMicrosecondsFromEpoch(totalMicroseconds);
1355
1356 return *this;
1357}
1358
1359inline
1361 int hour,
1362 int minute,
1363 int second,
1364 int millisecond,
1365 int microsecond)
1366{
1368 date.month(),
1369 date.day(),
1370 hour,
1371 minute,
1372 second,
1374 microsecond));
1375
1376 d_value = (static_cast<bsls::Types::Uint64>(date - Date())
1377 << k_NUM_TIME_BITS)
1382 + microsecond;
1383
1384 d_value |= k_REP_MASK;
1385}
1386
1387inline
1388void Datetime::setDatetime(const Date& date, const Time& time)
1389{
1390 if (24 != time.hour()) {
1391 d_value = (static_cast<bsls::Types::Uint64>(date - Date())
1392 << k_NUM_TIME_BITS)
1393 + (time - Time(0)).totalMicroseconds();
1394 }
1395 else {
1396 d_value = (static_cast<bsls::Types::Uint64>(date - Date())
1397 << k_NUM_TIME_BITS)
1399 }
1400
1401 d_value |= k_REP_MASK;
1402}
1403
1404inline
1406 int month,
1407 int day,
1408 int hour,
1409 int minute,
1410 int second,
1411 int millisecond,
1412 int microsecond)
1413{
1415 month,
1416 day,
1417 hour,
1418 minute,
1419 second,
1421 microsecond));
1422
1424 hour,
1425 minute,
1426 second,
1428 microsecond);
1429}
1430
1431inline
1433 int month,
1434 int day,
1435 int hour,
1436 int minute,
1437 int second,
1438 int millisecond,
1439 int microsecond)
1440{
1441 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1442
1444 month,
1445 day,
1446 hour,
1447 minute,
1448 second,
1450 microsecond)) {
1452 hour,
1453 minute,
1454 second,
1456 microsecond);
1457
1458 return k_SUCCESS; // RETURN
1459 }
1460
1461 return k_FAILURE;
1462}
1463
1464inline
1466 int hour,
1467 int minute,
1468 int second,
1469 int millisecond,
1470 int microsecond)
1471{
1472 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1473
1475 date.month(),
1476 date.day(),
1477 hour,
1478 minute,
1479 second,
1481 microsecond)) {
1483 hour,
1484 minute,
1485 second,
1487 microsecond);
1488
1489 return k_SUCCESS; // RETURN
1490 }
1491
1492 return k_FAILURE;
1493}
1494
1495inline
1496void Datetime::setDate(const Date& date)
1497{
1498 d_value = updatedRepresentation();
1499
1500 d_value = (static_cast<bsls::Types::Uint64>(date - Date())
1501 << k_NUM_TIME_BITS)
1502 | (d_value & k_TIME_MASK);
1503
1504 d_value |= k_REP_MASK;
1505}
1506
1507inline
1508void Datetime::setYearDay(int year, int dayOfYear)
1509{
1511
1513}
1514
1515inline
1516int Datetime::setYearDayIfValid(int year, int dayOfYear)
1517{
1518 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1519
1522 return k_SUCCESS; // RETURN
1523 }
1524 return k_FAILURE;
1525}
1526
1527inline
1536
1537inline
1538int Datetime::setYearMonthDayIfValid(int year, int month, int day)
1539{
1540 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1541
1544 return k_SUCCESS; // RETURN
1545 }
1546 return k_FAILURE;
1547}
1548
1549inline
1550void Datetime::setTime(const Time& time)
1551{
1552 d_value = updatedRepresentation();
1553
1554 if (24 != time.hour()) {
1555 d_value = (d_value & k_DATE_MASK)
1556 | (time - Time(0)).totalMicroseconds();
1557 }
1558 else {
1559 d_value = (d_value & k_DATE_MASK) | TimeUnitRatio::k_US_PER_D;
1560 }
1561}
1562
1563inline
1564void Datetime::setTime(int hour,
1565 int minute,
1566 int second,
1567 int millisecond,
1568 int microsecond)
1569{
1575 0 <= millisecond && millisecond
1577 0 <= microsecond && microsecond
1580 0 == minute &&
1581 0 == second &&
1582 0 == millisecond &&
1583 0 == microsecond));
1585
1586 d_value = updatedRepresentation();
1587
1592 + microsecond
1593 + (d_value & k_DATE_MASK);
1594}
1595
1596inline
1598 int minute,
1599 int second,
1600 int millisecond,
1601 int microsecond)
1602{
1603 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1604
1608 0 <= millisecond && millisecond
1610 0 <= microsecond && microsecond
1613 0 == minute &&
1614 0 == second &&
1615 0 == millisecond &&
1616 0 == microsecond)) {
1618 return k_SUCCESS; // RETURN
1619 }
1620 return k_FAILURE;
1621}
1622
1623inline
1624void Datetime::setHour(int hour)
1625{
1626 BSLS_ASSERT_SAFE(0 <= hour);
1627 BSLS_ASSERT_SAFE( hour <= 24);
1628
1629 d_value = updatedRepresentation();
1630
1632 bsls::Types::Uint64 microseconds = d_value & k_TIME_MASK;
1633 microseconds = microseconds % TimeUnitRatio::k_US_PER_H
1635 d_value = microseconds | (d_value & k_DATE_MASK);
1636 }
1637 else {
1638 d_value = TimeUnitRatio::k_US_PER_D | (d_value & k_DATE_MASK);
1639 }
1640}
1641
1642inline
1644{
1645 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1646
1647 if (0 <= hour && hour <= 24) {
1648 setHour(hour);
1649 return k_SUCCESS; // RETURN
1650 }
1651 return k_FAILURE;
1652}
1653
1654inline
1655void Datetime::setMinute(int minute)
1656{
1658 BSLS_ASSERT_SAFE( minute <= 59);
1659
1660 d_value = updatedRepresentation();
1661
1663 bsls::Types::Uint64 microseconds = d_value & k_TIME_MASK;
1664 microseconds = microseconds / TimeUnitRatio::k_US_PER_H
1666 + microseconds % TimeUnitRatio::k_US_PER_M
1668 d_value = microseconds | (d_value & k_DATE_MASK);
1669 }
1670 else {
1672 | (d_value & k_DATE_MASK);
1673 }
1674}
1675
1676inline
1678{
1679 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1680
1681 if (0 <= minute && minute <= 59) {
1683 return k_SUCCESS; // RETURN
1684 }
1685 return k_FAILURE;
1686}
1687
1688inline
1689void Datetime::setSecond(int second)
1690{
1692 BSLS_ASSERT_SAFE( second <= 59);
1693
1694 d_value = updatedRepresentation();
1695
1697 bsls::Types::Uint64 microseconds = d_value & k_TIME_MASK;
1698 microseconds = microseconds / TimeUnitRatio::k_US_PER_M
1700 + microseconds % TimeUnitRatio::k_US_PER_S
1702 d_value = microseconds | (d_value & k_DATE_MASK);
1703 }
1704 else {
1706 | (d_value & k_DATE_MASK);
1707 }
1708}
1709
1710inline
1712{
1713 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1714
1715 if (0 <= second && second <= 59) {
1717 return k_SUCCESS; // RETURN
1718 }
1719 return k_FAILURE;
1720}
1721
1722inline
1723void Datetime::setMillisecond(int millisecond)
1724{
1727
1728 d_value = updatedRepresentation();
1729
1731 bsls::Types::Uint64 microseconds = d_value & k_TIME_MASK;
1732 microseconds = microseconds / TimeUnitRatio::k_US_PER_S
1734 + microseconds % TimeUnitRatio::k_US_PER_MS
1736 d_value = microseconds | (d_value & k_DATE_MASK);
1737 }
1738 else {
1740 | (d_value & k_DATE_MASK);
1741 }
1742}
1743
1744inline
1746{
1747 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1748
1749 if (0 <= millisecond && millisecond <= 999) {
1751 return k_SUCCESS; // RETURN
1752 }
1753 return k_FAILURE;
1754}
1755
1756inline
1757void Datetime::setMicrosecond(int microsecond)
1758{
1761
1762 d_value = updatedRepresentation();
1763
1765 bsls::Types::Uint64 microseconds = d_value & k_TIME_MASK;
1766 microseconds = microseconds / TimeUnitRatio::k_US_PER_MS
1768 + microsecond;
1769 d_value = microseconds | (d_value & k_DATE_MASK);
1770 }
1771 else {
1772 d_value = (d_value & k_DATE_MASK) | microsecond;
1773 }
1774}
1775
1776inline
1778{
1779 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1780
1781 if (0 <= microsecond && microsecond <= 999) {
1783 return k_SUCCESS; // RETURN
1784 }
1785 return k_FAILURE;
1786}
1787
1788inline
1790{
1792
1793 d_value = updatedRepresentation(); // needed to avoid double logging from
1794 // 'date' and then 'setDate'
1795
1796 setDate(date() + days);
1797
1798 return *this;
1799}
1800
1801inline
1803{
1804 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1805
1806 if (0 == Date(date()).addDaysIfValid(days)) {
1807 addDays(days);
1808 return k_SUCCESS; // RETURN
1809 }
1810 return k_FAILURE;
1811}
1812
1813inline
1815 bsls::Types::Int64 minutes,
1816 bsls::Types::Int64 seconds,
1817 bsls::Types::Int64 milliseconds,
1818 bsls::Types::Int64 microseconds)
1819{
1820 // Reduce the input parameters to 'days' and 'microseconds', without any
1821 // constraints on the representation, without the possibility of overflow
1822 // or underflow.
1823
1825 + minutes / TimeUnitRatio::k_M_PER_D
1826 + seconds / TimeUnitRatio::k_S_PER_D
1827 + milliseconds / TimeUnitRatio::k_MS_PER_D
1828 + microseconds / TimeUnitRatio::k_US_PER_D;
1829
1830 hours %= TimeUnitRatio::k_H_PER_D;
1831 minutes %= TimeUnitRatio::k_M_PER_D;
1832 seconds %= TimeUnitRatio::k_S_PER_D;
1833 milliseconds %= TimeUnitRatio::k_MS_PER_D;
1834 microseconds %= TimeUnitRatio::k_US_PER_D;
1835
1836 microseconds = hours * TimeUnitRatio::k_US_PER_H
1837 + minutes * TimeUnitRatio::k_US_PER_M
1838 + seconds * TimeUnitRatio::k_US_PER_S
1839 + milliseconds * TimeUnitRatio::k_US_PER_MS
1840 + microseconds;
1841
1842 // Modify the representation to ensure 'days' and 'microseconds' have the
1843 // same sign (i.e., both are positive or both are negative or 'days == 0').
1844
1845 days += microseconds / TimeUnitRatio::k_US_PER_D;
1846 microseconds %= TimeUnitRatio::k_US_PER_D;
1847
1848 if (days > 0 && microseconds < 0) {
1849 --days;
1850 microseconds += TimeUnitRatio::k_US_PER_D;
1851 }
1852 else if (days < 0 && microseconds > 0) {
1853 ++days;
1854 microseconds -= TimeUnitRatio::k_US_PER_D;
1855 }
1856
1857 // Piecewise add the 'days' and 'microseconds' to this datetime.
1858
1859 bsls::Types::Uint64 totalMicroseconds = microsecondsFromEpoch();
1860
1861 BSLS_ASSERT_SAFE( days <= static_cast<bsls::Types::Int64>
1862 ((k_MAX_US_FROM_EPOCH - totalMicroseconds)
1864 BSLS_ASSERT_SAFE(-days <= static_cast<bsls::Types::Int64>
1865 (totalMicroseconds / TimeUnitRatio::k_US_PER_D));
1866
1867 totalMicroseconds += days * TimeUnitRatio::k_US_PER_D;
1868
1869 BSLS_ASSERT_SAFE( microseconds <= static_cast<bsls::Types::Int64>
1870 (k_MAX_US_FROM_EPOCH - totalMicroseconds));
1871 BSLS_ASSERT_SAFE(-microseconds <= static_cast<bsls::Types::Int64>
1872 (totalMicroseconds));
1873
1874 totalMicroseconds += microseconds;
1875
1876 // Assign the value.
1877
1878 setMicrosecondsFromEpoch(totalMicroseconds);
1879
1880 return *this;
1881}
1882
1883inline
1885 bsls::Types::Int64 minutes,
1886 bsls::Types::Int64 seconds,
1887 bsls::Types::Int64 milliseconds,
1888 bsls::Types::Int64 microseconds)
1889{
1890 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1891
1892 // Reduce the input parameters to 'days' and 'microseconds', without any
1893 // constraints on the representation, without the possibility of overflow
1894 // or underflow.
1895
1897 + minutes / TimeUnitRatio::k_M_PER_D
1898 + seconds / TimeUnitRatio::k_S_PER_D
1899 + milliseconds / TimeUnitRatio::k_MS_PER_D
1900 + microseconds / TimeUnitRatio::k_US_PER_D;
1901
1902 hours %= TimeUnitRatio::k_H_PER_D;
1903 minutes %= TimeUnitRatio::k_M_PER_D;
1904 seconds %= TimeUnitRatio::k_S_PER_D;
1905 milliseconds %= TimeUnitRatio::k_MS_PER_D;
1906 microseconds %= TimeUnitRatio::k_US_PER_D;
1907
1908 microseconds = hours * TimeUnitRatio::k_US_PER_H
1909 + minutes * TimeUnitRatio::k_US_PER_M
1910 + seconds * TimeUnitRatio::k_US_PER_S
1911 + milliseconds * TimeUnitRatio::k_US_PER_MS
1912 + microseconds;
1913
1914 // Modify the representation to ensure 'days' and 'microseconds' have the
1915 // same sign (i.e., both are positive or both are negative or 'days == 0').
1916
1917 days += microseconds / TimeUnitRatio::k_US_PER_D;
1918 microseconds %= TimeUnitRatio::k_US_PER_D;
1919
1920 if (days > 0 && microseconds < 0) {
1921 --days;
1922 microseconds += TimeUnitRatio::k_US_PER_D;
1923 }
1924 else if (days < 0 && microseconds > 0) {
1925 ++days;
1926 microseconds -= TimeUnitRatio::k_US_PER_D;
1927 }
1928
1929 // Piecewise add the 'days' and 'microseconds' to this datetime.
1930
1931 bsls::Types::Uint64 totalMicroseconds = microsecondsFromEpoch();
1932
1933 if (!( days <= static_cast<bsls::Types::Int64>
1934 ((k_MAX_US_FROM_EPOCH - totalMicroseconds)
1936 && -days <= static_cast<bsls::Types::Int64>
1937 (totalMicroseconds / TimeUnitRatio::k_US_PER_D))) {
1938 return k_FAILURE; // RETURN
1939 }
1940
1941 totalMicroseconds += days * TimeUnitRatio::k_US_PER_D;
1942
1943 if (!( microseconds <= static_cast<bsls::Types::Int64>
1944 (k_MAX_US_FROM_EPOCH - totalMicroseconds)
1945 && -microseconds <= static_cast<bsls::Types::Int64>
1946 (totalMicroseconds))) {
1947 return k_FAILURE; // RETURN
1948 }
1949
1950 totalMicroseconds += microseconds;
1951
1952 // Assign the value.
1953
1954 setMicrosecondsFromEpoch(totalMicroseconds);
1955 return k_SUCCESS;
1956}
1957
1958inline
1960{
1961 BSLS_ASSERT_SAFE( hours <= static_cast<bsls::Types::Int64>
1962 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
1964 BSLS_ASSERT_SAFE(-hours <= static_cast<bsls::Types::Int64>
1965 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_H));
1966
1967 bsls::Types::Uint64 totalMicroseconds = microsecondsFromEpoch();
1968
1969 setMicrosecondsFromEpoch(hours * TimeUnitRatio::k_US_PER_H
1970 + totalMicroseconds);
1971
1972 return *this;
1973}
1974
1975inline
1977{
1978 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1979
1980 if ( hours <= static_cast<bsls::Types::Int64>
1981 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
1983 && -hours <= static_cast<bsls::Types::Int64>
1984 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_H)) {
1985 addHours(hours);
1986 return k_SUCCESS; // RETURN
1987 }
1988 return k_FAILURE;
1989}
1990
1991inline
1993{
1994 BSLS_ASSERT_SAFE( minutes <= static_cast<bsls::Types::Int64>
1995 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
1997 BSLS_ASSERT_SAFE(-minutes <= static_cast<bsls::Types::Int64>
1998 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_M));
1999
2000 bsls::Types::Uint64 totalMicroseconds = microsecondsFromEpoch();
2001
2002 setMicrosecondsFromEpoch(minutes * TimeUnitRatio::k_US_PER_M
2003 + totalMicroseconds);
2004 return *this;
2005}
2006
2007inline
2009{
2010 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2011
2012 if ( minutes <= static_cast<bsls::Types::Int64>
2013 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2015 && -minutes <= static_cast<bsls::Types::Int64>
2016 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_M)) {
2017 addMinutes(minutes);
2018 return k_SUCCESS; // RETURN
2019 }
2020 return k_FAILURE;
2021}
2022
2023inline
2025{
2026 BSLS_ASSERT_SAFE( seconds <= static_cast<bsls::Types::Int64>
2027 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2029 BSLS_ASSERT_SAFE(-seconds <= static_cast<bsls::Types::Int64>
2030 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_S));
2031
2032 bsls::Types::Uint64 totalMicroseconds = microsecondsFromEpoch();
2033
2034 setMicrosecondsFromEpoch(seconds * TimeUnitRatio::k_US_PER_S
2035 + totalMicroseconds);
2036 return *this;
2037}
2038
2039inline
2041{
2042 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2043
2044 if ( seconds <= static_cast<bsls::Types::Int64>
2045 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2047 && -seconds <= static_cast<bsls::Types::Int64>
2048 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_S)) {
2049 addSeconds(seconds);
2050 return k_SUCCESS; // RETURN
2051 }
2052 return k_FAILURE;
2053}
2054
2055inline
2057{
2058 BSLS_ASSERT_SAFE( milliseconds <= static_cast<bsls::Types::Int64>
2059 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2061 BSLS_ASSERT_SAFE(-milliseconds <= static_cast<bsls::Types::Int64>
2062 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_MS));
2063
2064 bsls::Types::Uint64 totalMicroseconds = microsecondsFromEpoch();
2065
2066 setMicrosecondsFromEpoch(milliseconds * TimeUnitRatio::k_US_PER_MS
2067 + totalMicroseconds);
2068 return *this;
2069}
2070
2071inline
2073{
2074 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2075
2076 if ( milliseconds <= static_cast<bsls::Types::Int64>
2077 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2079 && -milliseconds <= static_cast<bsls::Types::Int64>
2080 (microsecondsFromEpoch() / TimeUnitRatio::k_US_PER_MS)) {
2081 addMilliseconds(milliseconds);
2082 return k_SUCCESS; // RETURN
2083 }
2084 return k_FAILURE;
2085}
2086
2087inline
2089{
2090 BSLS_ASSERT_SAFE( microseconds <= static_cast<bsls::Types::Int64>
2091 (k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
2092 BSLS_ASSERT_SAFE(-microseconds <= static_cast<bsls::Types::Int64>
2093 (microsecondsFromEpoch()));
2094
2095 bsls::Types::Uint64 totalMicroseconds = microsecondsFromEpoch();
2096
2097 setMicrosecondsFromEpoch(microseconds + totalMicroseconds);
2098
2099 return *this;
2100}
2101
2102inline
2104{
2105 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2106
2107 if ( microseconds <= static_cast<bsls::Types::Int64>
2108 (k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2109 && -microseconds <= static_cast<bsls::Types::Int64>
2110 (microsecondsFromEpoch())) {
2111 addMicroseconds(microseconds);
2112 return k_SUCCESS; // RETURN
2113 }
2114 return k_FAILURE;
2115}
2116
2117 // Aspects
2118
2119template <class STREAM>
2120STREAM& Datetime::bdexStreamIn(STREAM& stream, int version)
2121{
2122 if (stream) {
2123 switch (version) { // switch on the schema version
2124 case 2: {
2125 bsls::Types::Uint64 tmp = 0; // Note that we have to initialize
2126 // this to a value to silence
2127 // potential -Wmaybe-uninitialized
2128
2129 stream.getUint64(tmp);
2130
2131 if ( stream
2132 && tmp <= (DatetimeImpUtil::k_MAX_VALUE & (~k_REP_MASK))) {
2133 d_value = tmp;
2134 d_value |= k_REP_MASK;
2135 }
2136 else {
2137 stream.invalidate();
2138 }
2139 } break;
2140 case 1: {
2141 Date date;
2142 Time time;
2143
2144 date.bdexStreamIn(stream, 1);
2145 time.bdexStreamIn(stream, 1);
2146
2147 if (stream) {
2149 }
2150 else {
2151 stream.invalidate();
2152 }
2153 } break;
2154 default: {
2155 stream.invalidate(); // unrecognized version number
2156 }
2157 }
2158 }
2159 return stream;
2160}
2161
2162// ACCESSORS
2163inline
2165{
2166 bsls::Types::Uint64 value = updatedRepresentation() & (~k_REP_MASK);
2167
2168 return Date() + static_cast<int>(value >> k_NUM_TIME_BITS);
2169}
2170
2171inline
2172int Datetime::day() const
2173{
2174 return date().day();
2175}
2176
2177inline
2179{
2180 return date().dayOfWeek();
2181}
2182
2183inline
2185{
2186 return date().dayOfYear();
2187}
2188
2189inline
2190void Datetime::getTime(int *hour,
2191 int *minute,
2192 int *second,
2193 int *millisecond,
2194 int *microsecond) const
2195{
2196 bsls::Types::Uint64 microseconds = updatedRepresentation() & k_TIME_MASK;
2197
2198 if (hour) {
2199 *hour = static_cast<int>(microseconds / TimeUnitRatio::k_US_PER_H);
2200 }
2201 if (minute) {
2202 *minute = static_cast<int>( microseconds
2205 }
2206 if (second) {
2207 *second = static_cast<int>( microseconds
2210 }
2211 if (millisecond) {
2212 *millisecond = static_cast<int>( microseconds
2215 }
2216 if (microsecond) {
2217 *microsecond = static_cast<int>(
2218 microseconds % TimeUnitRatio::k_US_PER_MS);
2219 }
2220}
2221
2222inline
2224{
2225 bsls::Types::Uint64 microseconds = updatedRepresentation() & k_TIME_MASK;
2226
2227 return static_cast<int>(microseconds / TimeUnitRatio::k_US_PER_H);
2228}
2229
2230inline
2232{
2233 bsls::Types::Uint64 microseconds = updatedRepresentation() & k_TIME_MASK;
2234
2235 return static_cast<int>(microseconds % TimeUnitRatio::k_US_PER_MS);
2236}
2237
2238inline
2240{
2241 bsls::Types::Uint64 microseconds = updatedRepresentation() & k_TIME_MASK;
2242
2243 return static_cast<int>( microseconds
2246}
2247
2248inline
2250{
2251 bsls::Types::Uint64 microseconds = updatedRepresentation() & k_TIME_MASK;
2252
2253 return static_cast<int>( microseconds
2256}
2257
2258inline
2260{
2261 return date().month();
2262}
2263
2264inline
2266{
2267 bsls::Types::Uint64 microseconds = updatedRepresentation() & k_TIME_MASK;
2268
2269 return static_cast<int>( microseconds
2272}
2273
2274inline
2276{
2277 int hour;
2278 int minute;
2279 int second;
2280 int millisecond;
2281 int microsecond;
2282
2284
2286}
2287
2288inline
2290{
2291 return date().year();
2292}
2293
2294 // Aspects
2295
2296template <class STREAM>
2297STREAM& Datetime::bdexStreamOut(STREAM& stream, int version) const
2298{
2299 if (stream) {
2300 switch (version) { // switch on the schema version
2301 case 2: {
2302 bsls::Types::Uint64 value =
2303 updatedRepresentation() & (~k_REP_MASK);
2304
2305 stream.putUint64(value);
2306 } break;
2307 case 1: {
2308 date().bdexStreamOut(stream, 1);
2309 time().bdexStreamOut(stream, 1);
2310 } break;
2311 default: {
2312 stream.invalidate(); // unrecognized version number
2313 }
2314 }
2315 }
2316 return stream;
2317}
2318
2319#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
2320inline
2325
2326#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
2327#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
2328inline
2333
2334inline
2335bsl::ostream& Datetime::streamOut(bsl::ostream& stream) const
2336{
2337 return stream << *this;
2338}
2339
2340inline
2342 int month,
2343 int day,
2344 int hour,
2345 int minute,
2346 int second,
2347 int millisecond)
2348{
2349 return setDatetimeIfValid(year,
2350 month,
2351 day,
2352 hour,
2353 minute,
2354 second,
2355 millisecond);
2356}
2357
2358#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
2359
2360} // close package namespace
2361
2362// FREE OPERATORS
2363inline
2364bdlt::Datetime bdlt::operator+(const Datetime& lhs,
2365 const bsls::TimeInterval& rhs)
2366{
2367 Datetime result(lhs);
2368
2369 return result += rhs;
2370}
2371
2372inline
2374 const Datetime& rhs)
2375{
2376 Datetime result(rhs);
2377
2378 return result += lhs;
2379}
2380
2381inline
2382bdlt::Datetime bdlt::operator+(const Datetime& lhs,
2383 const DatetimeInterval& rhs)
2384{
2385 Datetime result(lhs);
2386
2387 return result += rhs;
2388}
2389
2390inline
2391bdlt::Datetime bdlt::operator+(const DatetimeInterval& lhs,
2392 const Datetime& rhs)
2393{
2394 Datetime result(rhs);
2395
2396 return result += lhs;
2397}
2398
2399inline
2400bdlt::Datetime bdlt::operator-(const Datetime& lhs,
2401 const bsls::TimeInterval& rhs)
2402{
2403 Datetime result(lhs);
2404
2405 return result -= rhs;
2406}
2407
2408inline
2409bdlt::Datetime bdlt::operator-(const Datetime& lhs,
2410 const DatetimeInterval& rhs)
2411{
2412 Datetime result(lhs);
2413
2414 return result -= rhs;
2415}
2416
2417inline
2418bdlt::DatetimeInterval bdlt::operator-(const Datetime& lhs,
2419 const Datetime& rhs)
2420{
2421 bsls::Types::Uint64 lhsTotalMicroseconds = lhs.microsecondsFromEpoch();
2422 bsls::Types::Uint64 rhsTotalMicroseconds = rhs.microsecondsFromEpoch();
2423
2424 if (lhsTotalMicroseconds >= rhsTotalMicroseconds) {
2425 lhsTotalMicroseconds -= rhsTotalMicroseconds;
2426
2428 0, 0, 0, 0, 0, lhsTotalMicroseconds); // RETURN
2429 }
2430
2431 rhsTotalMicroseconds -= lhsTotalMicroseconds;
2432
2434 0, 0, 0, 0, 0, -static_cast<bsls::Types::Int64>(rhsTotalMicroseconds));
2435}
2436
2437inline
2438bool bdlt::operator==(const Datetime& lhs, const Datetime& rhs)
2439{
2440 bsls::Types::Uint64 lhsValue = lhs.updatedRepresentation();
2441 bsls::Types::Uint64 rhsValue = rhs.updatedRepresentation();
2442
2443 return lhsValue == rhsValue;
2444}
2445
2446inline
2447bool bdlt::operator!=(const Datetime& lhs, const Datetime& rhs)
2448{
2449 bsls::Types::Uint64 lhsValue = lhs.updatedRepresentation();
2450 bsls::Types::Uint64 rhsValue = rhs.updatedRepresentation();
2451
2452 return lhsValue != rhsValue;
2453}
2454
2455inline
2456bool bdlt::operator<(const Datetime& lhs, const Datetime& rhs)
2457{
2458 BSLS_ASSERT_SAFE(24 != lhs.hour());
2459 BSLS_ASSERT_SAFE(24 != rhs.hour());
2460
2461 bsls::Types::Uint64 lhsValue = lhs.updatedRepresentation();
2462 bsls::Types::Uint64 rhsValue = rhs.updatedRepresentation();
2463
2464 return lhsValue < rhsValue;
2465}
2466
2467inline
2468bool bdlt::operator<=(const Datetime& lhs, const Datetime& rhs)
2469{
2470 BSLS_ASSERT_SAFE(24 != lhs.hour());
2471 BSLS_ASSERT_SAFE(24 != rhs.hour());
2472
2473 bsls::Types::Uint64 lhsValue = lhs.updatedRepresentation();
2474 bsls::Types::Uint64 rhsValue = rhs.updatedRepresentation();
2475
2476 return lhsValue <= rhsValue;
2477}
2478
2479inline
2480bool bdlt::operator>(const Datetime& lhs, const Datetime& rhs)
2481{
2482 BSLS_ASSERT_SAFE(24 != lhs.hour());
2483 BSLS_ASSERT_SAFE(24 != rhs.hour());
2484
2485 bsls::Types::Uint64 lhsValue = lhs.updatedRepresentation();
2486 bsls::Types::Uint64 rhsValue = rhs.updatedRepresentation();
2487
2488 return lhsValue > rhsValue;
2489}
2490
2491inline
2492bool bdlt::operator>=(const Datetime& lhs, const Datetime& rhs)
2493{
2494 BSLS_ASSERT_SAFE(24 != lhs.hour());
2495 BSLS_ASSERT_SAFE(24 != rhs.hour());
2496
2497 bsls::Types::Uint64 lhsValue = lhs.updatedRepresentation();
2498 bsls::Types::Uint64 rhsValue = rhs.updatedRepresentation();
2499
2500 return lhsValue >= rhsValue;
2501}
2502
2503// FREE FUNCTIONS
2504template <class HASHALG>
2505inline
2506void bdlt::hashAppend(HASHALG& hashAlg, const Datetime& object)
2507{
2508 using ::BloombergLP::bslh::hashAppend;
2509 hashAppend(hashAlg, object.updatedRepresentation());
2510}
2511
2512namespace bslmf {
2513
2514// TRAITS
2515
2516/// This template specialization for `IsBitwiseCopyable` indicates that
2517/// `bdlt::Datetime` is a bitwise copyable type.
2518template <>
2519struct IsBitwiseCopyable<BloombergLP::bdlt::Datetime> : bsl::true_type {
2520};
2521
2522} // close namespace bslmf
2523
2524
2525#endif
2526
2527// ----------------------------------------------------------------------------
2528// Copyright 2017 Bloomberg Finance L.P.
2529//
2530// Licensed under the Apache License, Version 2.0 (the "License");
2531// you may not use this file except in compliance with the License.
2532// You may obtain a copy of the License at
2533//
2534// http://www.apache.org/licenses/LICENSE-2.0
2535//
2536// Unless required by applicable law or agreed to in writing, software
2537// distributed under the License is distributed on an "AS IS" BASIS,
2538// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2539// See the License for the specific language governing permissions and
2540// limitations under the License.
2541// ----------------------------- END-OF-FILE ----------------------------------
2542
2543/** @} */
2544/** @} */
2545/** @} */
Definition bdlt_date.h:294
int dayOfYear() const
Return the day of the year in the range [1 .. 366] of this date.
Definition bdlt_date.h:940
static bool isValidYearDay(int year, int dayOfYear)
Definition bdlt_date.h:753
int day() const
Return the day of the month in the range [1 .. 31] of this date.
Definition bdlt_date.h:927
int year() const
Return the year in the range [1 .. 9999] of this date.
Definition bdlt_date.h:977
static bool isValidYearMonthDay(int year, int month, int day)
Definition bdlt_date.h:759
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_date.h:985
int month() const
Return the month of the year in the range [1 .. 12] of this date.
Definition bdlt_date.h:965
DayOfWeek::Enum dayOfWeek() const
Definition bdlt_date.h:933
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_date.h:896
Definition bdlt_datetimeinterval.h:201
bsls::Types::Int64 totalMicroseconds() const
Definition bdlt_datetimeinterval.h:1192
Definition bdlt_datetime.h:331
int setHourIfValid(int hour)
Definition bdlt_datetime.h:1643
Date date() const
Return the value of the "date" part of this object.
Definition bdlt_datetime.h:2164
static int maxSupportedVersion()
Definition bdlt_datetime.h:2329
int addMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetime.h:2072
int addMicrosecondsIfValid(bsls::Types::Int64 microseconds)
Definition bdlt_datetime.h:2103
Datetime()
Definition bdlt_datetime.h:1231
int year() const
Return the value of the year attribute of this object.
Definition bdlt_datetime.h:2289
int addDaysIfValid(int days)
Definition bdlt_datetime.h:1802
int addMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetime.h:2008
friend bool operator!=(const Datetime &, const Datetime &)
void setTime(const Time &time)
Definition bdlt_datetime.h:1550
int printToBuffer(char *result, int numBytes, int fractionalSecondPrecision=6) const
void setMinute(int minute)
Definition bdlt_datetime.h:1655
int hour() const
Return the value of the hour attribute of this object.
Definition bdlt_datetime.h:2223
int minute() const
Return the value of the minute attribute of this object.
Definition bdlt_datetime.h:2249
int millisecond() const
Return the value of the millisecond attribute of this object.
Definition bdlt_datetime.h:2239
Datetime & addTime(bsls::Types::Int64 hours, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
Definition bdlt_datetime.h:1814
void setDatetime(const Date &date, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1360
Datetime & addMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetime.h:1992
int setDatetimeIfValid(int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1432
int microsecond() const
Return the value of the microsecond attribute of this object.
Definition bdlt_datetime.h:2231
int addSecondsIfValid(bsls::Types::Int64 seconds)
Definition bdlt_datetime.h:2040
int validateAndSetDatetime(int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0)
Definition bdlt_datetime.h:2341
bsl::ostream & streamOut(bsl::ostream &stream) const
Definition bdlt_datetime.h:2335
Datetime & addMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetime.h:2088
int setMillisecondIfValid(int millisecond)
Definition bdlt_datetime.h:1745
Datetime & addHours(bsls::Types::Int64 hours)
Definition bdlt_datetime.h:1959
void setHour(int hour)
Definition bdlt_datetime.h:1624
void setMicrosecond(int microsecond)
Definition bdlt_datetime.h:1757
static int maxSupportedBdexVersion()
Definition bdlt_datetime.h:2321
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Time time() const
Return the value of the "time" part of this object.
Definition bdlt_datetime.h:2275
friend bool operator==(const Datetime &, const Datetime &)
static bool isValid(int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1194
Datetime & operator-=(const bsls::TimeInterval &rhs)
Definition bdlt_datetime.h:1306
friend void hashAppend(HASHALG &hashAlg, const Datetime &)
friend DatetimeInterval operator-(const Datetime &, const Datetime &)
int setYearDayIfValid(int year, int dayOfYear)
Definition bdlt_datetime.h:1516
int setYearMonthDayIfValid(int year, int month, int day)
Definition bdlt_datetime.h:1538
Datetime & addSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetime.h:2024
friend bool operator>(const Datetime &, const Datetime &)
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_datetime.h:2297
DayOfWeek::Enum dayOfWeek() const
Definition bdlt_datetime.h:2178
friend bool operator>=(const Datetime &, const Datetime &)
void setSecond(int second)
Definition bdlt_datetime.h:1689
void setYearDay(int year, int dayOfYear)
Definition bdlt_datetime.h:1508
Datetime & addDays(int days)
Definition bdlt_datetime.h:1789
Datetime & addMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetime.h:2056
int second() const
Return the value of the second attribute of this object.
Definition bdlt_datetime.h:2265
int month() const
Return the value of the month attribute of this object.
Definition bdlt_datetime.h:2259
friend bool operator<=(const Datetime &, const Datetime &)
void getTime(int *hour, int *minute=0, int *second=0, int *millisecond=0, int *microsecond=0) const
Definition bdlt_datetime.h:2190
Datetime & operator=(const Datetime &rhs)
Definition bdlt_datetime.h:1279
int setMicrosecondIfValid(int microsecond)
Definition bdlt_datetime.h:1777
void setMillisecond(int millisecond)
Definition bdlt_datetime.h:1723
~Datetime()=default
int setTimeIfValid(int hour, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1597
int setMinuteIfValid(int minute)
Definition bdlt_datetime.h:1677
friend bool operator<(const Datetime &, const Datetime &)
void setYearMonthDay(int year, int month, int day)
Definition bdlt_datetime.h:1528
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_datetime.h:2120
Datetime & operator+=(const bsls::TimeInterval &rhs)
Definition bdlt_datetime.h:1288
int addHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetime.h:1976
int dayOfYear() const
Return the value of the dayOfYear attribute of this object.
Definition bdlt_datetime.h:2184
void setDate(const Date &date)
Definition bdlt_datetime.h:1496
int setSecondIfValid(int second)
Definition bdlt_datetime.h:1711
int day() const
Definition bdlt_datetime.h:2172
int addTimeIfValid(bsls::Types::Int64 hours, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
Definition bdlt_datetime.h:1884
Definition bdlt_time.h:196
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_time.h:858
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_time.h:938
int hour() const
Return the value of the hour attribute of this time object.
Definition bdlt_time.h:898
Definition bsls_atomic.h:892
Definition bsls_timeinterval.h:301
BSLS_KEYWORD_CONSTEXPR_CPP14 bsls::Types::Int64 totalMicroseconds() const
Definition bsls_timeinterval.h:1397
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_PERFORMANCEHINT_PREDICT_LIKELY(expr)
Definition bsls_performancehint.h:451
#define BSLS_PRECONDITIONS_END()
Definition bsls_preconditions.h:131
#define BSLS_PRECONDITIONS_BEGIN()
Definition bsls_preconditions.h:130
#define BSLS_REVIEW_INVOKE(X)
Definition bsls_review.h:881
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 bdlbb_blob.h:576
Definition bdlt_iso8601util.h:691
static const bsls::Types::Uint64 k_MAX_VALUE
Definition bdlt_datetimeimputil.h:96
Enum
Enumerated day-of-week values.
Definition bdlt_dayofweek.h:123
Definition bdlt_timeunitratio.h:199
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 int k_S_PER_M_32
Definition bdlt_timeunitratio.h:339
static const int k_H_PER_D_32
Definition bdlt_timeunitratio.h:346
static const int k_US_PER_MS_32
Definition bdlt_timeunitratio.h:330
static const int k_MS_PER_D_32
Definition bdlt_timeunitratio.h:337
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 int k_M_PER_H_32
Definition bdlt_timeunitratio.h:343
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 int k_MS_PER_S_32
Definition bdlt_timeunitratio.h:334
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_MS_PER_D
Definition bdlt_timeunitratio.h:283
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132