8#ifndef INCLUDED_BDLT_DATETIME
9#define INCLUDED_BDLT_DATETIME
283#include <bdlscm_version.h>
310#include <bsl_iosfwd.h>
311#include <bsl_cstring.h>
312#include <bsl_sstream.h>
335 k_NUM_TIME_BITS = 37,
336 k_DEFAULT_FRACTIONAL_SECOND_PRECISION = 6
360 template <
class HASHALG>
389 bool validateAndTraceLogRepresentation()
const;
850 template <
class STREAM>
922 int fractionalSecondPrecision = 6)
const;
934 template <
class STREAM>
950 bsl::ostream&
print(bsl::ostream& stream,
952 int spacesPerLevel = 4)
const;
954#ifndef BDE_OPENSOURCE_PUBLICATION
963#ifndef BDE_OMIT_INTERNAL_DEPRECATED
975 bsl::ostream&
streamOut(bsl::ostream& stream)
const;
1105template <
class HASHALG>
1123 d_value |= k_REP_MASK;
1130 if (validateAndTraceLogRepresentation()) {
1137 + (value & k_TIME_MASK);
1140 return (value >> k_NUM_TIME_BITS)
1144#if BSLS_PLATFORM_IS_LITTLE_ENDIAN
1161 if (validateAndTraceLogRepresentation()) {
1165#if BSLS_PLATFORM_IS_LITTLE_ENDIAN
1173 return (days << k_NUM_TIME_BITS)
1179bool Datetime::validateAndTraceLogRepresentation()
const
1185 0 &&
"detected invalid 'bdlt::Datetime'; see TEAM 579660115");
1187 "detected invalid 'bdlt::Datetime'; see TEAM 579660115");
1223 if (versionSelector >= 20160411) {
1234 d_value |= k_REP_MASK;
1239: d_value(static_cast<
bsls::Types::Uint64>(date -
Date()) << k_NUM_TIME_BITS)
1241 d_value |= k_REP_MASK;
1272: d_value(original.d_value)
1274 d_value = updatedRepresentation();
1281 d_value = rhs.d_value;
1282 d_value = updatedRepresentation();
1292 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1296 microsecondsFromEpoch()));
1300 setMicrosecondsFromEpoch(totalMicroseconds);
1310 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1314 microsecondsFromEpoch()));
1318 setMicrosecondsFromEpoch(totalMicroseconds);
1328 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1332 microsecondsFromEpoch()));
1336 setMicrosecondsFromEpoch(totalMicroseconds);
1346 k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
1350 microsecondsFromEpoch()));
1354 setMicrosecondsFromEpoch(totalMicroseconds);
1384 d_value |= k_REP_MASK;
1393 + (
time -
Time(0)).totalMicroseconds();
1401 d_value |= k_REP_MASK;
1441 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1472 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1498 d_value = updatedRepresentation();
1502 | (d_value & k_TIME_MASK);
1504 d_value |= k_REP_MASK;
1518 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1540 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1552 d_value = updatedRepresentation();
1555 d_value = (d_value & k_DATE_MASK)
1556 | (
time -
Time(0)).totalMicroseconds();
1586 d_value = updatedRepresentation();
1593 + (d_value & k_DATE_MASK);
1603 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1629 d_value = updatedRepresentation();
1635 d_value = microseconds | (d_value & k_DATE_MASK);
1645 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1660 d_value = updatedRepresentation();
1668 d_value = microseconds | (d_value & k_DATE_MASK);
1672 | (d_value & k_DATE_MASK);
1679 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1694 d_value = updatedRepresentation();
1702 d_value = microseconds | (d_value & k_DATE_MASK);
1706 | (d_value & k_DATE_MASK);
1713 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1728 d_value = updatedRepresentation();
1736 d_value = microseconds | (d_value & k_DATE_MASK);
1740 | (d_value & k_DATE_MASK);
1747 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1762 d_value = updatedRepresentation();
1769 d_value = microseconds | (d_value & k_DATE_MASK);
1779 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1793 d_value = updatedRepresentation();
1804 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1848 if (days > 0 && microseconds < 0) {
1852 else if (days < 0 && microseconds > 0) {
1862 ((k_MAX_US_FROM_EPOCH - totalMicroseconds)
1870 (k_MAX_US_FROM_EPOCH - totalMicroseconds));
1872 (totalMicroseconds));
1874 totalMicroseconds += microseconds;
1878 setMicrosecondsFromEpoch(totalMicroseconds);
1890 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1920 if (days > 0 && microseconds < 0) {
1924 else if (days < 0 && microseconds > 0) {
1934 ((k_MAX_US_FROM_EPOCH - totalMicroseconds)
1944 (k_MAX_US_FROM_EPOCH - totalMicroseconds)
1946 (totalMicroseconds))) {
1950 totalMicroseconds += microseconds;
1954 setMicrosecondsFromEpoch(totalMicroseconds);
1962 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
1970 + totalMicroseconds);
1978 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1981 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
1995 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2003 + totalMicroseconds);
2010 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2013 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2027 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2035 + totalMicroseconds);
2042 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2045 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2059 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2067 + totalMicroseconds);
2074 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2077 ((k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2091 (k_MAX_US_FROM_EPOCH - microsecondsFromEpoch()));
2093 (microsecondsFromEpoch()));
2097 setMicrosecondsFromEpoch(microseconds + totalMicroseconds);
2105 enum { k_SUCCESS = 0, k_FAILURE = -1 };
2108 (k_MAX_US_FROM_EPOCH - microsecondsFromEpoch())
2110 (microsecondsFromEpoch())) {
2119template <
class STREAM>
2129 stream.getUint64(tmp);
2134 d_value |= k_REP_MASK;
2137 stream.invalidate();
2151 stream.invalidate();
2155 stream.invalidate();
2168 return Date() +
static_cast<int>(value >> k_NUM_TIME_BITS);
2194 int *microsecond)
const
2202 *
minute =
static_cast<int>( microseconds
2207 *
second =
static_cast<int>( microseconds
2243 return static_cast<int>( microseconds
2253 return static_cast<int>( microseconds
2269 return static_cast<int>( microseconds
2296template <
class STREAM>
2303 updatedRepresentation() & (~k_REP_MASK);
2305 stream.putUint64(value);
2312 stream.invalidate();
2319#ifndef BDE_OPENSOURCE_PUBLICATION
2327#ifndef BDE_OMIT_INTERNAL_DEPRECATED
2337 return stream << *
this;
2367 Datetime result(lhs);
2369 return result += rhs;
2374 const Datetime& rhs)
2376 Datetime result(rhs);
2378 return result += lhs;
2383 const DatetimeInterval& rhs)
2385 Datetime result(lhs);
2387 return result += rhs;
2392 const Datetime& rhs)
2394 Datetime result(rhs);
2396 return result += lhs;
2403 Datetime result(lhs);
2405 return result -= rhs;
2410 const DatetimeInterval& rhs)
2412 Datetime result(lhs);
2414 return result -= rhs;
2419 const Datetime& rhs)
2424 if (lhsTotalMicroseconds >= rhsTotalMicroseconds) {
2425 lhsTotalMicroseconds -= rhsTotalMicroseconds;
2428 0, 0, 0, 0, 0, lhsTotalMicroseconds);
2431 rhsTotalMicroseconds -= lhsTotalMicroseconds;
2443 return lhsValue == rhsValue;
2452 return lhsValue != rhsValue;
2464 return lhsValue < rhsValue;
2476 return lhsValue <= rhsValue;
2488 return lhsValue > rhsValue;
2500 return lhsValue >= rhsValue;
2504template <
class HASHALG>
2508 using ::BloombergLP::bslh::hashAppend;
2509 hashAppend(hashAlg,
object.updatedRepresentation());
Definition bdlt_date.h:294
int dayOfYear() const
Return the day of the year in the range [1 .. 366] of this date.
Definition bdlt_date.h:940
static bool isValidYearDay(int year, int dayOfYear)
Definition bdlt_date.h:753
int day() const
Return the day of the month in the range [1 .. 31] of this date.
Definition bdlt_date.h:927
int year() const
Return the year in the range [1 .. 9999] of this date.
Definition bdlt_date.h:977
static bool isValidYearMonthDay(int year, int month, int day)
Definition bdlt_date.h:759
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_date.h:985
int month() const
Return the month of the year in the range [1 .. 12] of this date.
Definition bdlt_date.h:965
DayOfWeek::Enum dayOfWeek() const
Definition bdlt_date.h:933
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_date.h:896
Definition bdlt_datetimeinterval.h:201
bsls::Types::Int64 totalMicroseconds() const
Definition bdlt_datetimeinterval.h:1192
Definition bdlt_datetime.h:331
int setHourIfValid(int hour)
Definition bdlt_datetime.h:1643
Date date() const
Return the value of the "date" part of this object.
Definition bdlt_datetime.h:2164
static int maxSupportedVersion()
Definition bdlt_datetime.h:2329
int addMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetime.h:2072
int addMicrosecondsIfValid(bsls::Types::Int64 microseconds)
Definition bdlt_datetime.h:2103
Datetime()
Definition bdlt_datetime.h:1231
int year() const
Return the value of the year attribute of this object.
Definition bdlt_datetime.h:2289
int addDaysIfValid(int days)
Definition bdlt_datetime.h:1802
int addMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetime.h:2008
friend bool operator!=(const Datetime &, const Datetime &)
void setTime(const Time &time)
Definition bdlt_datetime.h:1550
int printToBuffer(char *result, int numBytes, int fractionalSecondPrecision=6) const
void setMinute(int minute)
Definition bdlt_datetime.h:1655
int hour() const
Return the value of the hour attribute of this object.
Definition bdlt_datetime.h:2223
int minute() const
Return the value of the minute attribute of this object.
Definition bdlt_datetime.h:2249
int millisecond() const
Return the value of the millisecond attribute of this object.
Definition bdlt_datetime.h:2239
Datetime & addTime(bsls::Types::Int64 hours, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
Definition bdlt_datetime.h:1814
void setDatetime(const Date &date, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1360
Datetime & addMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetime.h:1992
int setDatetimeIfValid(int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1432
int microsecond() const
Return the value of the microsecond attribute of this object.
Definition bdlt_datetime.h:2231
int addSecondsIfValid(bsls::Types::Int64 seconds)
Definition bdlt_datetime.h:2040
int validateAndSetDatetime(int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0)
Definition bdlt_datetime.h:2341
bsl::ostream & streamOut(bsl::ostream &stream) const
Definition bdlt_datetime.h:2335
Datetime & addMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetime.h:2088
int setMillisecondIfValid(int millisecond)
Definition bdlt_datetime.h:1745
Datetime & addHours(bsls::Types::Int64 hours)
Definition bdlt_datetime.h:1959
void setHour(int hour)
Definition bdlt_datetime.h:1624
void setMicrosecond(int microsecond)
Definition bdlt_datetime.h:1757
static int maxSupportedBdexVersion()
Definition bdlt_datetime.h:2321
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Time time() const
Return the value of the "time" part of this object.
Definition bdlt_datetime.h:2275
friend bool operator==(const Datetime &, const Datetime &)
static bool isValid(int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1194
Datetime & operator-=(const bsls::TimeInterval &rhs)
Definition bdlt_datetime.h:1306
friend void hashAppend(HASHALG &hashAlg, const Datetime &)
friend DatetimeInterval operator-(const Datetime &, const Datetime &)
int setYearDayIfValid(int year, int dayOfYear)
Definition bdlt_datetime.h:1516
int setYearMonthDayIfValid(int year, int month, int day)
Definition bdlt_datetime.h:1538
Datetime & addSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetime.h:2024
friend bool operator>(const Datetime &, const Datetime &)
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_datetime.h:2297
DayOfWeek::Enum dayOfWeek() const
Definition bdlt_datetime.h:2178
friend bool operator>=(const Datetime &, const Datetime &)
void setSecond(int second)
Definition bdlt_datetime.h:1689
void setYearDay(int year, int dayOfYear)
Definition bdlt_datetime.h:1508
Datetime & addDays(int days)
Definition bdlt_datetime.h:1789
Datetime & addMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetime.h:2056
int second() const
Return the value of the second attribute of this object.
Definition bdlt_datetime.h:2265
int month() const
Return the value of the month attribute of this object.
Definition bdlt_datetime.h:2259
friend bool operator<=(const Datetime &, const Datetime &)
void getTime(int *hour, int *minute=0, int *second=0, int *millisecond=0, int *microsecond=0) const
Definition bdlt_datetime.h:2190
Datetime & operator=(const Datetime &rhs)
Definition bdlt_datetime.h:1279
int setMicrosecondIfValid(int microsecond)
Definition bdlt_datetime.h:1777
void setMillisecond(int millisecond)
Definition bdlt_datetime.h:1723
int setTimeIfValid(int hour, int minute=0, int second=0, int millisecond=0, int microsecond=0)
Definition bdlt_datetime.h:1597
int setMinuteIfValid(int minute)
Definition bdlt_datetime.h:1677
friend bool operator<(const Datetime &, const Datetime &)
void setYearMonthDay(int year, int month, int day)
Definition bdlt_datetime.h:1528
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_datetime.h:2120
Datetime & operator+=(const bsls::TimeInterval &rhs)
Definition bdlt_datetime.h:1288
int addHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetime.h:1976
int dayOfYear() const
Return the value of the dayOfYear attribute of this object.
Definition bdlt_datetime.h:2184
void setDate(const Date &date)
Definition bdlt_datetime.h:1496
int setSecondIfValid(int second)
Definition bdlt_datetime.h:1711
int day() const
Definition bdlt_datetime.h:2172
int addTimeIfValid(bsls::Types::Int64 hours, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
Definition bdlt_datetime.h:1884
Definition bdlt_time.h:196
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_time.h:858
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_time.h:938
int hour() const
Return the value of the hour attribute of this time object.
Definition bdlt_time.h:898
Definition bsls_atomic.h:892
Definition bsls_timeinterval.h:301
BSLS_KEYWORD_CONSTEXPR_CPP14 bsls::Types::Int64 totalMicroseconds() const
Definition bsls_timeinterval.h:1397
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_PRECONDITIONS_END()
Definition bsls_preconditions.h:131
#define BSLS_PRECONDITIONS_BEGIN()
Definition bsls_preconditions.h:130
#define BSLS_REVIEW_INVOKE(X)
Definition bsls_review.h:881
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
Definition bbldc_basicisma30360.h:112
bool operator>(const Date &lhs, const Date &rhs)
bool operator<(const Date &lhs, const Date &rhs)
bool operator==(const Calendar &lhs, const Calendar &rhs)
Date operator-(const Date &date, int numDays)
bool operator>=(const Date &lhs, const Date &rhs)
Date operator+(const Date &date, int numDays)
bsl::ostream & operator<<(bsl::ostream &stream, const Calendar &calendar)
bool operator<=(const Date &lhs, const Date &rhs)
void hashAppend(HASHALG &hashAlg, const Calendar &object)
bool operator!=(const Calendar &lhs, const Calendar &rhs)
Definition bdlbb_blob.h:576
Definition bdlt_iso8601util.h:691
static const bsls::Types::Uint64 k_MAX_VALUE
Definition bdlt_datetimeimputil.h:96
Enum
Enumerated day-of-week values.
Definition bdlt_dayofweek.h:123
Definition bdlt_timeunitratio.h:199
static const bsls::Types::Int64 k_M_PER_D
Definition bdlt_timeunitratio.h:290
static const bsls::Types::Int64 k_S_PER_M
Definition bdlt_timeunitratio.h:285
static const int k_S_PER_M_32
Definition bdlt_timeunitratio.h:339
static const int k_H_PER_D_32
Definition bdlt_timeunitratio.h:346
static const int k_US_PER_MS_32
Definition bdlt_timeunitratio.h:330
static const int k_MS_PER_D_32
Definition bdlt_timeunitratio.h:337
static const bsls::Types::Int64 k_MS_PER_S
Definition bdlt_timeunitratio.h:280
static const bsls::Types::Int64 k_US_PER_H
Definition bdlt_timeunitratio.h:277
static const int k_M_PER_H_32
Definition bdlt_timeunitratio.h:343
static const bsls::Types::Int64 k_M_PER_H
Definition bdlt_timeunitratio.h:289
static const bsls::Types::Int64 k_US_PER_MS
Definition bdlt_timeunitratio.h:273
static const int k_MS_PER_S_32
Definition bdlt_timeunitratio.h:334
static const bsls::Types::Int64 k_US_PER_D
Definition bdlt_timeunitratio.h:278
static const bsls::Types::Int64 k_H_PER_D
Definition bdlt_timeunitratio.h:292
static const bsls::Types::Int64 k_US_PER_S
Definition bdlt_timeunitratio.h:275
static const bsls::Types::Int64 k_US_PER_M
Definition bdlt_timeunitratio.h:276
static const bsls::Types::Int64 k_S_PER_D
Definition bdlt_timeunitratio.h:287
static const bsls::Types::Int64 k_MS_PER_D
Definition bdlt_timeunitratio.h:283
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132