8#ifndef INCLUDED_BDLT_DATETIMEINTERVAL
9#define INCLUDED_BDLT_DATETIMEINTERVAL
167#include <bdlscm_version.h>
185#include <bsl_cstdint.h>
186#include <bsl_limits.h>
187#include <bsl_iosfwd.h>
207 k_DEFAULT_FRACTIONAL_SECOND_PRECISION = 6
224 template <
class HASHALG>
555 template <
class STREAM>
611 int fractionalSecondPrecision = 6)
const;
656 template <
class STREAM>
671 bsl::ostream&
print(bsl::ostream& stream,
673 int spacesPerLevel = 4)
const;
675#ifndef BDE_OPENSOURCE_PUBLICATION
686#ifndef BDE_OMIT_INTERNAL_DEPRECATED
765template <
class HASHALG>
783 if (versionSelector >= 20170401) {
815: d_days(original.d_days)
816, d_microseconds(original.d_microseconds)
825 d_microseconds = rhs.d_microseconds;
832#ifdef BSLS_ASSERT_IS_USED
834 BSLS_ASSERT(0 == rc &&
"operator+= over/under flow"); (void) rc;
836 addInterval(rhs.d_days, 0, 0, 0, 0, rhs.d_microseconds);
845 Int64 rhsDays = rhs.d_days;
846 Int64 rhsMicroseconds = rhs.d_microseconds;
847 if (INT_MIN == rhsDays) {
852 rhsMicroseconds = -rhsMicroseconds;
855#ifdef BSLS_ASSERT_IS_USED
857 static_cast<int>(rhsDays), 0, 0, 0, 0, rhsMicroseconds);
858 BSLS_ASSERT(0 == rc &&
"operator-= over/under flow"); (void) rc;
860 addInterval(
static_cast<int>(rhsDays), 0, 0, 0, 0, rhsMicroseconds);
1060template <
class STREAM>
1067 stream.getInt32(tmpDays);
1070 stream.getInt64(tmpMicroseconds);
1073 && ( (0 <= tmpDays && 0 <= tmpMicroseconds)
1074 || (0 >= tmpDays && 0 >= tmpMicroseconds))
1077 assign(tmpDays, tmpMicroseconds);
1080 stream.invalidate();
1085 stream.getInt64(tmp);
1088 && k_MILLISECONDS_MIN <= tmp && k_MILLISECONDS_MAX >= tmp) {
1092 stream.invalidate();
1096 stream.invalidate();
1113 return d_microseconds;
1180 static_cast<double>(d_microseconds) /
1195 || (bsl::numeric_limits<bsls::Types::Int64>::max() -
1198#if !defined(BSLS_PLATFORM_CMP_SUN) \
1199 || !defined(BDE_BUILD_TARGET_OPT) \
1200 || BSLS_PLATFORM_CMP_VERSION >= 0x5140
1206 || (bsl::numeric_limits<bsls::Types::Int64>::min() -
1217template <
class STREAM>
1223 stream.putInt32(d_days);
1224 stream.putInt64(d_microseconds);
1230 stream.invalidate();
1237#ifndef BDE_OPENSOURCE_PUBLICATION
1247#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1261 const DatetimeInterval& rhs)
1263 DatetimeInterval ret(lhs);
1265#ifdef BSLS_ASSERT_IS_USED
1266 int rc = ret.addIntervalIfValid(0, 0, 0, 0,
1267 rhs.totalMilliseconds(), rhs.microseconds());
1268 BSLS_ASSERT(0 == rc &&
"operator+ over/under flow"); (void) rc;
1270 ret.addInterval(0, 0, 0, 0, rhs.totalMilliseconds(), rhs.microseconds());
1278 const DatetimeInterval& rhs)
1280 DatetimeInterval ret(lhs);
1282#ifdef BSLS_ASSERT_IS_USED
1283 int rc = ret.addIntervalIfValid(0, 0, 0, 0,
1284 -rhs.totalMilliseconds(), -rhs.microseconds());
1285 BSLS_ASSERT(0 == rc &&
"operator- over/under flow"); (void) rc;
1287 ret.addInterval(0, 0, 0, 0, -rhs.totalMilliseconds(), -rhs.microseconds());
1296 BSLS_REVIEW(value.d_days > bsl::numeric_limits<int32_t>::min());
1298 DatetimeInterval interval;
1300 interval.d_days = -value.d_days;
1301 interval.d_microseconds = -value.d_microseconds;
1307bool bdlt::operator==(
const DatetimeInterval& lhs,
const DatetimeInterval& rhs)
1309 return lhs.d_days == rhs.d_days
1310 && lhs.d_microseconds == rhs.d_microseconds;
1314bool bdlt::operator!=(
const DatetimeInterval& lhs,
const DatetimeInterval& rhs)
1316 return lhs.d_days != rhs.d_days
1317 || lhs.d_microseconds != rhs.d_microseconds;
1322 const DatetimeInterval& rhs)
1324 return lhs.d_days < rhs.d_days
1325 || ( lhs.d_days == rhs.d_days
1326 && lhs.d_microseconds < rhs.d_microseconds);
1331 const DatetimeInterval& rhs)
1333 return lhs.d_days < rhs.d_days
1334 || ( lhs.d_days == rhs.d_days
1335 && lhs.d_microseconds <= rhs.d_microseconds);
1339bool bdlt::operator> (
const DatetimeInterval& lhs,
const DatetimeInterval& rhs)
1341 return lhs.d_days > rhs.d_days
1342 || ( lhs.d_days == rhs.d_days
1343 && lhs.d_microseconds > rhs.d_microseconds);
1347bool bdlt::operator>=(
const DatetimeInterval& lhs,
const DatetimeInterval& rhs)
1349 return lhs.d_days > rhs.d_days
1350 || ( lhs.d_days == rhs.d_days
1351 && lhs.d_microseconds >= rhs.d_microseconds);
1356 const DatetimeInterval&
object)
1358 return object.print(stream, 0, -1);
1362template <
class HASHALG>
1365 using ::BloombergLP::bslh::hashAppend;
Definition bdlt_datetimeinterval.h:201
int days() const
Definition bdlt_datetimeinterval.h:1105
friend DatetimeInterval operator-(const DatetimeInterval &)
int setIntervalIfValid(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
friend bool operator>(const DatetimeInterval &, const DatetimeInterval &)
~DatetimeInterval()=default
int setTotalSecondsFromDoubleIfValid(double seconds)
int addSecondsIfValid(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:1009
int addIntervalIfValid(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
bsls::Types::Int64 totalMinutes() const
Definition bdlt_datetimeinterval.h:1163
int totalDays() const
Definition bdlt_datetimeinterval.h:1150
DatetimeInterval & addMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:1041
int milliseconds() const
Definition bdlt_datetimeinterval.h:1137
static const bsls::Types::Int64 k_MILLISECONDS_MIN
Definition bdlt_datetimeinterval.h:257
int seconds() const
Definition bdlt_datetimeinterval.h:1130
int addMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:989
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_datetimeinterval.h:1061
void setTotalDays(int days)
Definition bdlt_datetimeinterval.h:867
int setTotalHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:881
DatetimeInterval & operator-=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:843
void setTotalMicroseconds(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:936
DatetimeInterval & operator=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:822
bsls::Types::Int64 totalSeconds() const
Definition bdlt_datetimeinterval.h:1170
int setTotalMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:927
void setTotalMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:889
void setTotalMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:919
double totalSecondsAsDouble() const
Definition bdlt_datetimeinterval.h:1177
DatetimeInterval & addHours(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:960
int setTotalSecondsIfValid(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:911
int addMillisecondsIfValid(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:1030
void setTotalHours(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:874
static bool isValid(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
friend bool operator!=(const DatetimeInterval &, const DatetimeInterval &)
int minutes() const
Definition bdlt_datetimeinterval.h:1123
bsls::Types::Int64 fractionalDayInMicroseconds() const
Definition bdlt_datetimeinterval.h:1111
static int maxSupportedVersion()
Definition bdlt_datetimeinterval.h:1249
DatetimeInterval & addDays(int days)
Definition bdlt_datetimeinterval.h:943
int addMicrosecondsIfValid(bsls::Types::Int64 microseconds)
Definition bdlt_datetimeinterval.h:1050
DatetimeInterval & addInterval(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
int hours() const
Definition bdlt_datetimeinterval.h:1117
int microseconds() const
Definition bdlt_datetimeinterval.h:1144
bsls::Types::Int64 totalMilliseconds() const
Definition bdlt_datetimeinterval.h:1185
bsl::ostream & streamOut(bsl::ostream &stream) const
int addHoursIfValid(bsls::Types::Int64 hours)
Definition bdlt_datetimeinterval.h:970
void setInterval(int days, bsls::Types::Int64 hours=0, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
DatetimeInterval()
Create a time interval object having the value 0.
Definition bdlt_datetimeinterval.h:791
friend bool operator==(const DatetimeInterval &, const DatetimeInterval &)
int printToBuffer(char *result, int numBytes, int fractionalSecondPrecision=6) const
DatetimeInterval & operator+=(const DatetimeInterval &rhs)
Definition bdlt_datetimeinterval.h:830
void setTotalSecondsFromDouble(double seconds)
DatetimeInterval & addMinutes(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:979
bsls::Types::Int64 totalMicroseconds() const
Definition bdlt_datetimeinterval.h:1192
int setTotalMinutesIfValid(bsls::Types::Int64 minutes)
Definition bdlt_datetimeinterval.h:896
int addDaysIfValid(int days)
Definition bdlt_datetimeinterval.h:952
DatetimeInterval & addMilliseconds(bsls::Types::Int64 milliseconds)
Definition bdlt_datetimeinterval.h:1020
friend bool operator<=(const DatetimeInterval &, const DatetimeInterval &)
DatetimeInterval & addSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:999
static int maxSupportedBdexVersion()
Definition bdlt_datetimeinterval.h:1241
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_datetimeinterval.h:1218
friend bool operator>=(const DatetimeInterval &, const DatetimeInterval &)
friend void hashAppend(HASHALG &, const DatetimeInterval &)
void setTotalSeconds(bsls::Types::Int64 seconds)
Definition bdlt_datetimeinterval.h:904
friend bool operator<(const DatetimeInterval &, const DatetimeInterval &)
static const bsls::Types::Int64 k_MILLISECONDS_MAX
Definition bdlt_datetimeinterval.h:253
bsls::Types::Int64 totalHours() const
Definition bdlt_datetimeinterval.h:1156
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_REVIEW(X)
Definition bsls_review.h:949
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
Definition bbldc_basicisma30360.h:112
bool operator>(const Date &lhs, const Date &rhs)
bool operator<(const Date &lhs, const Date &rhs)
bool operator==(const Calendar &lhs, const Calendar &rhs)
Date operator-(const Date &date, int numDays)
bool operator>=(const Date &lhs, const Date &rhs)
Date operator+(const Date &date, int numDays)
bsl::ostream & operator<<(bsl::ostream &stream, const Calendar &calendar)
bool operator<=(const Date &lhs, const Date &rhs)
void hashAppend(HASHALG &hashAlg, const Calendar &object)
bool operator!=(const Calendar &lhs, const Calendar &rhs)
Definition bdlb_printmethods.h:283
static const bsls::Types::Int64 k_M_PER_D
Definition bdlt_timeunitratio.h:290
static const bsls::Types::Int64 k_S_PER_M
Definition bdlt_timeunitratio.h:285
static const bsls::Types::Int64 k_MS_PER_S
Definition bdlt_timeunitratio.h:280
static const bsls::Types::Int64 k_US_PER_H
Definition bdlt_timeunitratio.h:277
static const bsls::Types::Int64 k_M_PER_H
Definition bdlt_timeunitratio.h:289
static const bsls::Types::Int64 k_US_PER_MS
Definition bdlt_timeunitratio.h:273
static const bsls::Types::Int64 k_US_PER_D
Definition bdlt_timeunitratio.h:278
static const bsls::Types::Int64 k_H_PER_D
Definition bdlt_timeunitratio.h:292
static const bsls::Types::Int64 k_US_PER_S
Definition bdlt_timeunitratio.h:275
static const bsls::Types::Int64 k_US_PER_M
Definition bdlt_timeunitratio.h:276
static const bsls::Types::Int64 k_S_PER_D
Definition bdlt_timeunitratio.h:287
static const bsls::Types::Int64 k_MILLISECONDS_PER_DAY
Definition bdlt_timeunitratio.h:249
static const bsls::Types::Int64 k_MS_PER_D
Definition bdlt_timeunitratio.h:283
long long Int64
Definition bsls_types.h:132