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