summaryrefslogtreecommitdiff
path: root/src/mongo/util
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2015-05-07 16:45:29 -0400
committerAndy Schwerin <schwerin@mongodb.com>2015-05-13 17:58:55 -0400
commit532dfe1180c2da552bebed70af1e7fba34cf355c (patch)
tree9fb15c1576003307169bd249db500ad1aee21d99 /src/mongo/util
parentcd97edbe4be0e6ddc9139a21e13594fd19a26a5e (diff)
downloadmongo-532dfe1180c2da552bebed70af1e7fba34cf355c.tar.gz
SERVER-13874 Make mongo::Milliseconds et al. aliases for equivalent stdx::chrono types.
Also introduces operators for adding stdx::chrono::duration to Date_t, subtracting two Date_ts to get Milliseconds, and remove the use of reinterpret_cast from the implementation of BSON Timestamp type.
Diffstat (limited to 'src/mongo/util')
-rw-r--r--src/mongo/util/net/ssl_expiration.cpp25
-rw-r--r--src/mongo/util/net/ssl_manager.cpp2
-rw-r--r--src/mongo/util/signal_handlers_synchronous.cpp2
-rw-r--r--src/mongo/util/time_support.cpp102
-rw-r--r--src/mongo/util/time_support.h119
-rw-r--r--src/mongo/util/time_support_test.cpp334
6 files changed, 384 insertions, 200 deletions
diff --git a/src/mongo/util/net/ssl_expiration.cpp b/src/mongo/util/net/ssl_expiration.cpp
index 9f1d6ef9676..d05462ce442 100644
--- a/src/mongo/util/net/ssl_expiration.cpp
+++ b/src/mongo/util/net/ssl_expiration.cpp
@@ -32,14 +32,15 @@
#include <string>
#include "mongo/util/log.h"
+#include "mongo/util/time_support.h"
namespace mongo {
- static const unsigned long long dayInMillis = 24 * 60 * 60 * 1000;
+ static const auto oneDay = stdx::chrono::hours(24);
CertificateExpirationMonitor::CertificateExpirationMonitor(Date_t date)
: _certExpiration(date)
- , _lastCheckTime(Date_t(curTimeMillis64())) {
+ , _lastCheckTime(Date_t::now()) {
}
std::string CertificateExpirationMonitor::taskName() const {
@@ -47,30 +48,28 @@ namespace mongo {
}
void CertificateExpirationMonitor::taskDoWork() {
- const unsigned long long timeSinceLastCheck =
- curTimeMillis64() - _lastCheckTime.millis;
+ const Milliseconds timeSinceLastCheck = Date_t::now() - _lastCheckTime;
- if (timeSinceLastCheck < dayInMillis)
+ if (timeSinceLastCheck < oneDay)
return;
- const Date_t now = Date_t(curTimeMillis64());
+ const Date_t now = Date_t::now();
_lastCheckTime = now;
- if (_certExpiration.millis <= now.millis) {
+ if (_certExpiration <= now) {
// The certificate has expired.
warning() << "Server certificate is now invalid. It expired on "
- << dateToCtimeString(_certExpiration);
+ << dateToISOStringUTC(_certExpiration);
return;
}
- const unsigned long long remainingValidMillis =
- _certExpiration.millis - now.millis;
+ const auto remainingValidDuration = _certExpiration - now;
- if (remainingValidMillis / dayInMillis <= 30) {
+ if (remainingValidDuration <= 30 * oneDay) {
// The certificate will expire in the next 30 days.
warning() << "Server certificate will expire on "
- << dateToCtimeString(_certExpiration) << " in "
- << (remainingValidMillis / dayInMillis)
+ << dateToISOStringUTC(_certExpiration) << " in "
+ << durationCount<stdx::chrono::hours>(remainingValidDuration) / 24
<< " days.";
}
}
diff --git a/src/mongo/util/net/ssl_manager.cpp b/src/mongo/util/net/ssl_manager.cpp
index 6f9be1a1c03..652807e7e71 100644
--- a/src/mongo/util/net/ssl_manager.cpp
+++ b/src/mongo/util/net/ssl_manager.cpp
@@ -699,7 +699,7 @@ namespace mongo {
"The provided SSL certificate is expired or not yet valid.");
}
- *serverCertificateExpirationDate = Date_t(notAfterMillis);
+ *serverCertificateExpirationDate = Date_t::fromMillisSinceEpoch(notAfterMillis);
}
return true;
diff --git a/src/mongo/util/signal_handlers_synchronous.cpp b/src/mongo/util/signal_handlers_synchronous.cpp
index e28d2796fd5..e0d69350203 100644
--- a/src/mongo/util/signal_handlers_synchronous.cpp
+++ b/src/mongo/util/signal_handlers_synchronous.cpp
@@ -114,7 +114,7 @@ namespace {
// must hold streamMutex to call
void writeMallocFreeStreamToLog() {
logger::globalLogDomain()->append(
- logger::MessageEventEphemeral(curTimeMillis64(),
+ logger::MessageEventEphemeral(Date_t::now(),
logger::LogSeverity::Severe(),
getThreadName(),
mallocFreeOStream.str()));
diff --git a/src/mongo/util/time_support.cpp b/src/mongo/util/time_support.cpp
index 69369582058..f6e44c1e3a3 100644
--- a/src/mongo/util/time_support.cpp
+++ b/src/mongo/util/time_support.cpp
@@ -41,6 +41,7 @@
#include "mongo/bson/util/builder.h"
#include "mongo/platform/cstdint.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/mongoutils/str.h"
#ifdef _WIN32
#include <boost/date_time/filetime_functions.hpp>
@@ -64,15 +65,80 @@ timegm(struct tm *const tmp);
namespace mongo {
+namespace {
+ template <typename Stream> Stream& streamPut(Stream& os, Microseconds us) {
+ return os << us.count() << "\xce\xbcs";
+ }
+
+ template <typename Stream> Stream& streamPut(Stream& os, Milliseconds ms) {
+ return os << ms.count() << "ms";
+ }
+
+ template <typename Stream> Stream& streamPut(Stream& os, Seconds s) {
+ return os << s.count() << 's';
+ }
+} // namespace
+
+ std::ostream& operator<<(std::ostream& os, Microseconds us) {
+ return streamPut(os, us);
+ }
+
+ std::ostream& operator<<(std::ostream& os, Milliseconds ms) {
+ return streamPut(os, ms);
+ }
+ std::ostream& operator<<(std::ostream& os, Seconds s) {
+ return streamPut(os, s);
+ }
+
+ template <typename Allocator>
+ StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Microseconds us) {
+ return streamPut(os, us);
+ }
+
+ template <typename Allocator>
+ StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Milliseconds ms) {
+ return streamPut(os, ms);
+ }
+
+ template <typename Allocator>
+ StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Seconds s) {
+ return streamPut(os, s);
+ }
+
+ template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&,
+ Microseconds);
+ template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&,
+ Milliseconds);
+ template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&,
+ Seconds);
+ template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
+ Microseconds);
+ template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
+ Milliseconds);
+ template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
+ Seconds);
+
+ Date_t Date_t::max() {
+ return fromMillisSinceEpoch(std::numeric_limits<long long>::max());
+ }
+
+ Date_t Date_t::now() {
+ return fromMillisSinceEpoch(curTimeMillis64());
+ }
+
bool Date_t::isFormatable() const {
+ if (millis < 0) {
+ return false;
+ }
if (sizeof(time_t) == sizeof(int32_t)) {
- return millis < 2147483647000ULL; // "2038-01-19T03:14:07Z"
+ return millis < 2147483647000LL; // "2038-01-19T03:14:07Z"
}
else {
- return millis < 32535215999000ULL; // "3000-12-31T23:59:59Z"
+ return millis < 32535215999000LL; // "3000-12-31T23:59:59Z"
}
}
+
// jsTime_virtual_skew is just for testing. a test command manipulates it.
long long jsTime_virtual_skew = 0;
boost::thread_specific_ptr<long long> jsTime_virtual_thread_skew;
@@ -690,7 +756,11 @@ namespace {
resultMillis += (tzAdjSecs * 1000);
- return StatusWith<Date_t>(resultMillis);
+ if (resultMillis > static_cast<unsigned long long>(std::numeric_limits<long long>::max())) {
+ return {ErrorCodes::BadValue,
+ str::stream() << dateString << " is too far in the future"};
+ }
+ return Date_t::fromMillisSinceEpoch(static_cast<long long>(resultMillis));
}
#undef MONGO_ISO_DATE_FMT_NO_TZ
@@ -709,9 +779,10 @@ namespace {
}
time_t Date_t::toTimeT() const {
- verify((long long)millis >= 0); // TODO when millis is signed, delete
- verify(((long long)millis/1000) < (std::numeric_limits<time_t>::max)());
- return millis / 1000;
+ const auto secs = millis / 1000;
+ verify(secs >= std::numeric_limits<time_t>::min());
+ verify(secs <= std::numeric_limits<time_t>::max());
+ return secs;
}
boost::gregorian::date currentDate() {
@@ -848,7 +919,11 @@ namespace {
}
/** Date_t is milliseconds since epoch */
- Date_t jsTime();
+ Date_t jsTime() {
+ return Date_t::now() +
+ Milliseconds(getJSTimeVirtualThreadSkew()) +
+ Milliseconds(getJSTimeVirtualSkew());
+ }
/** warning this will wrap */
unsigned curTimeMicros();
@@ -860,12 +935,6 @@ namespace {
boost::xtime_get(&xt, MONGO_BOOST_TIME_UTC);
return ((unsigned long long)xt.sec) * 1000 + xt.nsec / 1000000;
}
- Date_t jsTime() {
- boost::xtime xt;
- boost::xtime_get(&xt, MONGO_BOOST_TIME_UTC);
- unsigned long long t = xt.nsec / 1000000;
- return ((unsigned long long) xt.sec * 1000) + t + getJSTimeVirtualSkew() + getJSTimeVirtualThreadSkew();
- }
static unsigned long long getFiletime() {
FILETIME ft;
@@ -975,12 +1044,7 @@ namespace {
gettimeofday(&tv, NULL);
return ((unsigned long long)tv.tv_sec) * 1000 + tv.tv_usec / 1000;
}
- Date_t jsTime() {
- timeval tv;
- gettimeofday(&tv, NULL);
- unsigned long long t = tv.tv_usec / 1000;
- return ((unsigned long long) tv.tv_sec * 1000) + t + getJSTimeVirtualSkew() + getJSTimeVirtualThreadSkew();
- }
+
unsigned long long curTimeMicros64() {
timeval tv;
gettimeofday(&tv, NULL);
diff --git a/src/mongo/util/time_support.h b/src/mongo/util/time_support.h
index 81db17cbd76..d8f04c293c3 100644
--- a/src/mongo/util/time_support.h
+++ b/src/mongo/util/time_support.h
@@ -37,30 +37,131 @@
#include <boost/version.hpp>
#include "mongo/base/status_with.h"
+#include "mongo/stdx/chrono.h"
namespace mongo {
- typedef boost::posix_time::milliseconds Milliseconds;
- typedef boost::posix_time::seconds Seconds;
+ template <typename Allocator> class StringBuilderImpl;
+
+ using Microseconds = stdx::chrono::microseconds;
+ using Milliseconds = stdx::chrono::milliseconds;
+ using Seconds = stdx::chrono::seconds;
+ using Minutes = stdx::chrono::minutes;
+ using stdx::chrono::duration_cast;
void time_t_to_Struct(time_t t, struct tm * buf , bool local = false );
std::string time_t_to_String(time_t t);
std::string time_t_to_String_short(time_t t);
- struct Date_t {
- // TODO: make signed (and look for related TODO's)
- unsigned long long millis;
+ //
+ // Operators for putting durations to streams.
+ //
+
+ std::ostream& operator<<(std::ostream& os, Microseconds us);
+ std::ostream& operator<<(std::ostream& os, Milliseconds ms);
+ std::ostream& operator<<(std::ostream& os, Seconds s);
+
+ template <typename Allocator>
+ StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Microseconds us);
+
+ template <typename Allocator>
+ StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Milliseconds ms);
+
+ template <typename Allocator>
+ StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Seconds s);
+
+ /**
+ * Convenience method for reading the count of a duration with specified units.
+ *
+ * Use when logging or comparing to integers, to ensure that you're using
+ * the units you intend.
+ *
+ * E.g., log() << durationCount<Seconds>(some duration) << " seconds";
+ */
+ template <typename DOut, typename DIn> long long durationCount(DIn d) {
+ return duration_cast<DOut>(d).count();
+ }
+
+ class Date_t {
+ public:
+ static Date_t max();
+ static Date_t now();
+
+ static Date_t fromMillisSinceEpoch(long long m) {
+ return Date_t(m);
+ }
+
+ template <typename Duration>
+ static Date_t fromDurationSinceEpoch(Duration d) {
+ return fromMillisSinceEpoch(durationCount<Milliseconds>(d));
+ }
+
Date_t(): millis(0) {}
- Date_t(unsigned long long m): millis(m) {}
- operator unsigned long long&() { return millis; }
- operator const unsigned long long&() const { return millis; }
+
void toTm (tm *buf);
std::string toString() const;
time_t toTimeT() const;
int64_t asInt64() const {
- return static_cast<int64_t>(millis);
+ return toMillisSinceEpoch();
}
+ unsigned long long toULL() const { return static_cast<unsigned long long>(asInt64()); }
+ Milliseconds toDurationSinceEpoch() const { return Milliseconds(toMillisSinceEpoch()); }
+ long long toMillisSinceEpoch() const { return static_cast<long long>(millis); }
bool isFormatable() const;
+
+ template <typename Duration>
+ Date_t& operator+=(Duration d) {
+ millis += duration_cast<Milliseconds>(d).count();
+ return *this;
+ }
+
+ template <typename Duration>
+ Date_t& operator-=(Duration d) {
+ return *this += (-d);
+ }
+
+ template <typename Duration>
+ Date_t operator+(Duration d) const {
+ Date_t result = *this;
+ result += d;
+ return result;
+ }
+
+ template <typename Duration>
+ Date_t operator-(Duration d) const {
+ Date_t result = *this;
+ result -= d;
+ return result;
+ }
+
+ Milliseconds operator-(Date_t other) const { return Milliseconds(millis - other.millis); }
+
+ bool operator==(Date_t other) const {
+ return toDurationSinceEpoch() == other.toDurationSinceEpoch();
+ }
+
+ bool operator!=(Date_t other) const { return !(*this == other); }
+
+ bool operator<(Date_t other) const {
+ return toDurationSinceEpoch() < other.toDurationSinceEpoch();
+ }
+
+ bool operator>(Date_t other) const {
+ return toDurationSinceEpoch() > other.toDurationSinceEpoch();
+ }
+
+ bool operator<=(Date_t other) const {
+ return !(*this > other);
+ }
+
+ bool operator>=(Date_t other) const {
+ return !(*this < other);
+ }
+
+ private:
+ Date_t(long long m): millis(m) {}
+
+ long long millis;
};
// uses ISO 8601 dates without trailing Z
diff --git a/src/mongo/util/time_support_test.cpp b/src/mongo/util/time_support_test.cpp
index 0580584c62e..91fd9d2e8a9 100644
--- a/src/mongo/util/time_support_test.cpp
+++ b/src/mongo/util/time_support_test.cpp
@@ -68,37 +68,37 @@ namespace {
TEST(TimeFormatting, DateAsISO8601UTCString) {
ASSERT_EQUALS(std::string("1970-01-01T00:00:00.000Z"),
- dateToISOStringUTC(Date_t(0)));
+ dateToISOStringUTC(Date_t()));
ASSERT_EQUALS(std::string("1970-06-30T01:06:40.981Z"),
- dateToISOStringUTC(Date_t(15556000981ULL)));
+ dateToISOStringUTC(Date_t::fromMillisSinceEpoch(15556000981LL)));
if (!isTimeTSmall)
ASSERT_EQUALS(std::string("2058-02-20T18:29:11.100Z"),
- dateToISOStringUTC(Date_t(2781455351100ULL)));
+ dateToISOStringUTC(Date_t::fromMillisSinceEpoch(2781455351100LL)));
ASSERT_EQUALS(std::string("2013-02-20T18:29:11.100Z"),
- dateToISOStringUTC(Date_t(1361384951100ULL)));
+ dateToISOStringUTC(Date_t::fromMillisSinceEpoch(1361384951100LL)));
}
TEST(TimeFormatting, DateAsISO8601LocalString) {
ASSERT_EQUALS(std::string("1969-12-31T19:00:00.000-0500"),
- dateToISOStringLocal(Date_t(0)));
+ dateToISOStringLocal(Date_t()));
ASSERT_EQUALS(std::string("1970-06-29T21:06:40.981-0400"),
- dateToISOStringLocal(Date_t(15556000981ULL)));
+ dateToISOStringLocal(Date_t::fromMillisSinceEpoch(15556000981LL)));
if (!isTimeTSmall)
ASSERT_EQUALS(std::string("2058-02-20T13:29:11.100-0500"),
- dateToISOStringLocal(Date_t(2781455351100ULL)));
+ dateToISOStringLocal(Date_t::fromMillisSinceEpoch(2781455351100LL)));
ASSERT_EQUALS(std::string("2013-02-20T13:29:11.100-0500"),
- dateToISOStringLocal(Date_t(1361384951100ULL)));
+ dateToISOStringLocal(Date_t::fromMillisSinceEpoch(1361384951100LL)));
}
TEST(TimeFormatting, DateAsCtimeString) {
- ASSERT_EQUALS(std::string("Wed Dec 31 19:00:00.000"), dateToCtimeString(Date_t(0)));
+ ASSERT_EQUALS(std::string("Wed Dec 31 19:00:00.000"), dateToCtimeString(Date_t()));
ASSERT_EQUALS(std::string("Mon Jun 29 21:06:40.981"),
- dateToCtimeString(Date_t(15556000981ULL)));
+ dateToCtimeString(Date_t::fromMillisSinceEpoch(15556000981LL)));
if (!isTimeTSmall)
ASSERT_EQUALS(std::string("Wed Feb 20 13:29:11.100"),
- dateToCtimeString(Date_t(2781455351100ULL)));
+ dateToCtimeString(Date_t::fromMillisSinceEpoch(2781455351100LL)));
ASSERT_EQUALS(std::string("Wed Feb 20 13:29:11.100"),
- dateToCtimeString(Date_t(1361384951100ULL)));
+ dateToCtimeString(Date_t::fromMillisSinceEpoch(1361384951100LL)));
}
static std::string stringstreamDate(void (*formatter)(std::ostream&, Date_t), Date_t date) {
@@ -109,38 +109,48 @@ namespace {
TEST(TimeFormatting, DateAsISO8601UTCStream) {
ASSERT_EQUALS(std::string("1970-01-01T00:00:00.000Z"),
- stringstreamDate(outputDateAsISOStringUTC, Date_t(0)));
+ stringstreamDate(outputDateAsISOStringUTC, Date_t()));
ASSERT_EQUALS(std::string("1970-06-30T01:06:40.981Z"),
- stringstreamDate(outputDateAsISOStringUTC, Date_t(15556000981ULL)));
+ stringstreamDate(outputDateAsISOStringUTC,
+ Date_t::fromMillisSinceEpoch(15556000981LL)));
if (!isTimeTSmall)
ASSERT_EQUALS(std::string("2058-02-20T18:29:11.100Z"),
- stringstreamDate(outputDateAsISOStringUTC, Date_t(2781455351100ULL)));
+ stringstreamDate(outputDateAsISOStringUTC,
+ Date_t::fromMillisSinceEpoch(2781455351100LL)));
ASSERT_EQUALS(std::string("2013-02-20T18:29:11.100Z"),
- stringstreamDate(outputDateAsISOStringUTC, Date_t(1361384951100ULL)));
+ stringstreamDate(outputDateAsISOStringUTC,
+ Date_t::fromMillisSinceEpoch(1361384951100LL)));
}
TEST(TimeFormatting, DateAsISO8601LocalStream) {
ASSERT_EQUALS(std::string("1969-12-31T19:00:00.000-0500"),
- stringstreamDate(outputDateAsISOStringLocal, Date_t(0)));
+ stringstreamDate(outputDateAsISOStringLocal, Date_t()));
ASSERT_EQUALS(std::string("1970-06-29T21:06:40.981-0400"),
- stringstreamDate(outputDateAsISOStringLocal, Date_t(15556000981ULL)));
+ stringstreamDate(outputDateAsISOStringLocal,
+ Date_t::fromMillisSinceEpoch(15556000981LL)));
if (!isTimeTSmall)
ASSERT_EQUALS(std::string("2058-02-20T13:29:11.100-0500"),
- stringstreamDate(outputDateAsISOStringLocal, Date_t(2781455351100ULL)));
+ stringstreamDate(outputDateAsISOStringLocal,
+ Date_t::fromMillisSinceEpoch(2781455351100LL)));
ASSERT_EQUALS(std::string("2013-02-20T13:29:11.100-0500"),
- stringstreamDate(outputDateAsISOStringLocal, Date_t(1361384951100ULL)));
+ stringstreamDate(outputDateAsISOStringLocal,
+ Date_t::fromMillisSinceEpoch(1361384951100LL)));
}
TEST(TimeFormatting, DateAsCtimeStream) {
ASSERT_EQUALS(std::string("Wed Dec 31 19:00:00.000"),
- stringstreamDate(outputDateAsCtime, Date_t(0)));
+ stringstreamDate(outputDateAsCtime,
+ Date_t::fromMillisSinceEpoch(0)));
ASSERT_EQUALS(std::string("Mon Jun 29 21:06:40.981"),
- stringstreamDate(outputDateAsCtime, Date_t(15556000981ULL)));
+ stringstreamDate(outputDateAsCtime,
+ Date_t::fromMillisSinceEpoch(15556000981LL)));
if (!isTimeTSmall)
ASSERT_EQUALS(std::string("Wed Feb 20 13:29:11.100"),
- stringstreamDate(outputDateAsCtime, Date_t(2781455351100ULL)));
+ stringstreamDate(outputDateAsCtime,
+ Date_t::fromMillisSinceEpoch(2781455351100LL)));
ASSERT_EQUALS(std::string("Wed Feb 20 13:29:11.100"),
- stringstreamDate(outputDateAsCtime, Date_t(1361384951100ULL)));
+ stringstreamDate(outputDateAsCtime,
+ Date_t::fromMillisSinceEpoch(1361384951100LL)));
}
TEST(TimeParsing, DateAsISO8601UTC) {
@@ -151,45 +161,45 @@ namespace {
StatusWith<Date_t> swull = dateFromISOString("1971-02-03T04:05:06.789Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906789ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906789LL);
swull = dateFromISOString("1971-02-03T04:05:06.78Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906780ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906780LL);
swull = dateFromISOString("1971-02-03T04:05:06.7Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906700ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906700LL);
swull = dateFromISOString("1971-02-03T04:05:06Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906000LL);
swull = dateFromISOString("1971-02-03T04:05Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401900000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401900000LL);
swull = dateFromISOString("1970-01-01T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 0ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 0LL);
swull = dateFromISOString("1970-06-30T01:06:40.981Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 15556000981ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 15556000981LL);
if (!isTimeTSmall) {
swull = dateFromISOString("2058-02-20T18:29:11.100Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2781455351100ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2781455351100LL);
swull = dateFromISOString("3001-01-01T08:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 32535244800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 32535244800000LL);
}
swull = dateFromISOString("2013-02-20T18:29:11.100Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1361384951100ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1361384951100LL);
}
TEST(TimeParsing, DateAsISO8601Local) {
@@ -200,79 +210,79 @@ namespace {
StatusWith<Date_t> swull = dateFromISOString("1971-02-03T09:16:06.789+0511");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906789ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906789LL);
swull = dateFromISOString("1971-02-03T09:16:06.78+0511");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906780ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906780LL);
swull = dateFromISOString("1971-02-03T09:16:06.7+0511");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906700ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906700LL);
swull = dateFromISOString("1971-02-03T09:16:06+0511");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401906000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401906000LL);
swull = dateFromISOString("1971-02-03T09:16+0511");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 34401900000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 34401900000LL);
swull = dateFromISOString("1970-01-01T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 0ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 0LL);
swull = dateFromISOString("1970-06-30T01:06:40.981Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 15556000981ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 15556000981LL);
// Local times not supported
//swull = dateFromISOString("1970-01-01T00:00:00.001");
//ASSERT_OK(swull.getStatus());
- //ASSERT_EQUALS(swull.getValue(), 18000001ULL);
+ //ASSERT_EQUALS(swull.getValue().asInt64(), 18000001LL);
//swull = dateFromISOString("1970-01-01T00:00:00.01");
//ASSERT_OK(swull.getStatus());
- //ASSERT_EQUALS(swull.getValue(), 18000010ULL);
+ //ASSERT_EQUALS(swull.getValue().asInt64(), 18000010LL);
//swull = dateFromISOString("1970-01-01T00:00:00.1");
//ASSERT_OK(swull.getStatus());
- //ASSERT_EQUALS(swull.getValue(), 18000100ULL);
+ //ASSERT_EQUALS(swull.getValue().asInt64(), 18000100LL);
//swull = dateFromISOString("1970-01-01T00:00:01");
//ASSERT_OK(swull.getStatus());
- //ASSERT_EQUALS(swull.getValue(), 18001000ULL);
+ //ASSERT_EQUALS(swull.getValue().asInt64(), 18001000LL);
//swull = dateFromISOString("1970-01-01T00:01");
//ASSERT_OK(swull.getStatus());
- //ASSERT_EQUALS(swull.getValue(), 18060000ULL);
+ //ASSERT_EQUALS(swull.getValue().asInt64(), 18060000LL);
swull = dateFromISOString("1970-06-29T21:06:40.981-0400");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 15556000981ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 15556000981LL);
if (!isTimeTSmall) {
swull = dateFromISOString("2058-02-20T13:29:11.100-0500");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2781455351100ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2781455351100LL);
swull = dateFromISOString("3000-12-31T23:59:59Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 32535215999000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 32535215999000LL);
}
else {
swull = dateFromISOString("2038-01-19T03:14:07Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2147483647000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2147483647000LL);
}
swull = dateFromISOString("2013-02-20T13:29:11.100-0500");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1361384951100ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1361384951100LL);
swull = dateFromISOString("2013-02-20T13:29:11.100-0501");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1361385011100ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1361385011100LL);
}
TEST(TimeParsing, InvalidDates) {
@@ -392,426 +402,436 @@ namespace {
TEST(TimeParsing, LeapYears) {
StatusWith<Date_t> swull = dateFromISOString("1972-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 68169600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 68169600000LL);
swull = dateFromISOString("1976-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 194400000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 194400000000LL);
swull = dateFromISOString("1980-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 320630400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 320630400000LL);
swull = dateFromISOString("1984-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 446860800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 446860800000LL);
swull = dateFromISOString("1988-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 573091200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 573091200000LL);
swull = dateFromISOString("1992-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 699321600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 699321600000LL);
swull = dateFromISOString("1996-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 825552000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 825552000000LL);
swull = dateFromISOString("2000-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 951782400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 951782400000LL);
swull = dateFromISOString("2004-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1078012800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1078012800000LL);
swull = dateFromISOString("2008-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1204243200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1204243200000LL);
swull = dateFromISOString("2012-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1330473600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1330473600000LL);
swull = dateFromISOString("2016-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1456704000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1456704000000LL);
swull = dateFromISOString("2020-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1582934400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1582934400000LL);
swull = dateFromISOString("2024-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1709164800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1709164800000LL);
swull = dateFromISOString("2028-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1835395200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1835395200000LL);
swull = dateFromISOString("2032-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 1961625600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 1961625600000LL);
swull = dateFromISOString("2036-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2087856000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2087856000000LL);
if (!isTimeTSmall) {
swull = dateFromISOString("2040-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2214086400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2214086400000LL);
swull = dateFromISOString("2044-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2340316800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2340316800000LL);
swull = dateFromISOString("2048-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2466547200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2466547200000LL);
swull = dateFromISOString("2052-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2592777600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2592777600000LL);
swull = dateFromISOString("2056-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2719008000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2719008000000LL);
swull = dateFromISOString("2060-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2845238400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2845238400000LL);
swull = dateFromISOString("2064-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 2971468800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 2971468800000LL);
swull = dateFromISOString("2068-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3097699200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3097699200000LL);
swull = dateFromISOString("2072-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3223929600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3223929600000LL);
swull = dateFromISOString("2076-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3350160000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3350160000000LL);
swull = dateFromISOString("2080-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3476390400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3476390400000LL);
swull = dateFromISOString("2084-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3602620800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3602620800000LL);
swull = dateFromISOString("2088-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3728851200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3728851200000LL);
swull = dateFromISOString("2092-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3855081600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3855081600000LL);
swull = dateFromISOString("2096-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 3981312000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 3981312000000LL);
swull = dateFromISOString("2104-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 4233686400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 4233686400000LL);
swull = dateFromISOString("2108-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 4359916800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 4359916800000LL);
swull = dateFromISOString("2112-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 4486147200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 4486147200000LL);
swull = dateFromISOString("2116-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 4612377600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 4612377600000LL);
swull = dateFromISOString("2120-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 4738608000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 4738608000000LL);
swull = dateFromISOString("2124-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 4864838400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 4864838400000LL);
swull = dateFromISOString("2128-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 4991068800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 4991068800000LL);
swull = dateFromISOString("2132-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 5117299200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 5117299200000LL);
swull = dateFromISOString("2136-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 5243529600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 5243529600000LL);
swull = dateFromISOString("2140-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 5369760000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 5369760000000LL);
swull = dateFromISOString("2144-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 5495990400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 5495990400000LL);
swull = dateFromISOString("2148-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 5622220800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 5622220800000LL);
swull = dateFromISOString("2152-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 5748451200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 5748451200000LL);
swull = dateFromISOString("2156-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 5874681600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 5874681600000LL);
swull = dateFromISOString("2160-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6000912000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6000912000000LL);
swull = dateFromISOString("2164-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6127142400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6127142400000LL);
swull = dateFromISOString("2168-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6253372800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6253372800000LL);
swull = dateFromISOString("2172-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6379603200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6379603200000LL);
swull = dateFromISOString("2176-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6505833600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6505833600000LL);
swull = dateFromISOString("2180-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6632064000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6632064000000LL);
swull = dateFromISOString("2184-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6758294400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6758294400000LL);
swull = dateFromISOString("2188-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 6884524800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 6884524800000LL);
swull = dateFromISOString("2192-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 7010755200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 7010755200000LL);
swull = dateFromISOString("2196-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 7136985600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 7136985600000LL);
swull = dateFromISOString("2204-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 7389360000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 7389360000000LL);
swull = dateFromISOString("2208-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 7515590400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 7515590400000LL);
swull = dateFromISOString("2212-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 7641820800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 7641820800000LL);
swull = dateFromISOString("2216-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 7768051200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 7768051200000LL);
swull = dateFromISOString("2220-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 7894281600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 7894281600000LL);
swull = dateFromISOString("2224-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8020512000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8020512000000LL);
swull = dateFromISOString("2228-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8146742400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8146742400000LL);
swull = dateFromISOString("2232-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8272972800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8272972800000LL);
swull = dateFromISOString("2236-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8399203200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8399203200000LL);
swull = dateFromISOString("2240-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8525433600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8525433600000LL);
swull = dateFromISOString("2244-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8651664000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8651664000000LL);
swull = dateFromISOString("2248-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8777894400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8777894400000LL);
swull = dateFromISOString("2252-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 8904124800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 8904124800000LL);
swull = dateFromISOString("2256-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9030355200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9030355200000LL);
swull = dateFromISOString("2260-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9156585600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9156585600000LL);
swull = dateFromISOString("2264-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9282816000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9282816000000LL);
swull = dateFromISOString("2268-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9409046400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9409046400000LL);
swull = dateFromISOString("2272-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9535276800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9535276800000LL);
swull = dateFromISOString("2276-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9661507200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9661507200000LL);
swull = dateFromISOString("2280-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9787737600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9787737600000LL);
swull = dateFromISOString("2284-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 9913968000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 9913968000000LL);
swull = dateFromISOString("2288-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 10040198400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 10040198400000LL);
swull = dateFromISOString("2292-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 10166428800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 10166428800000LL);
swull = dateFromISOString("2296-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 10292659200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 10292659200000LL);
swull = dateFromISOString("2304-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 10545033600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 10545033600000LL);
swull = dateFromISOString("2308-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 10671264000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 10671264000000LL);
swull = dateFromISOString("2312-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 10797494400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 10797494400000LL);
swull = dateFromISOString("2316-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 10923724800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 10923724800000LL);
swull = dateFromISOString("2320-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11049955200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11049955200000LL);
swull = dateFromISOString("2324-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11176185600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11176185600000LL);
swull = dateFromISOString("2328-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11302416000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11302416000000LL);
swull = dateFromISOString("2332-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11428646400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11428646400000LL);
swull = dateFromISOString("2336-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11554876800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11554876800000LL);
swull = dateFromISOString("2340-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11681107200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11681107200000LL);
swull = dateFromISOString("2344-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11807337600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11807337600000LL);
swull = dateFromISOString("2348-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 11933568000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 11933568000000LL);
swull = dateFromISOString("2352-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12059798400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12059798400000LL);
swull = dateFromISOString("2356-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12186028800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12186028800000LL);
swull = dateFromISOString("2360-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12312259200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12312259200000LL);
swull = dateFromISOString("2364-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12438489600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12438489600000LL);
swull = dateFromISOString("2368-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12564720000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12564720000000LL);
swull = dateFromISOString("2372-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12690950400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12690950400000LL);
swull = dateFromISOString("2376-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12817180800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12817180800000LL);
swull = dateFromISOString("2380-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 12943411200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 12943411200000LL);
swull = dateFromISOString("2384-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 13069641600000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 13069641600000LL);
swull = dateFromISOString("2388-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 13195872000000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 13195872000000LL);
swull = dateFromISOString("2392-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 13322102400000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 13322102400000LL);
swull = dateFromISOString("2396-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 13448332800000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 13448332800000LL);
swull = dateFromISOString("2400-02-29T00:00:00.000Z");
ASSERT_OK(swull.getStatus());
- ASSERT_EQUALS(swull.getValue(), 13574563200000ULL);
+ ASSERT_EQUALS(swull.getValue().asInt64(), 13574563200000LL);
}
}
+ TEST(TimeFormatting, DurationFormatting) {
+ ASSERT_EQUALS("52\xce\xbcs", static_cast<std::string>(str::stream() << Microseconds(52)));
+ ASSERT_EQUALS("52ms", static_cast<std::string>(str::stream() << Milliseconds(52)));
+ ASSERT_EQUALS("52s", static_cast<std::string>(str::stream() << Seconds(52)));
+
+ std::ostringstream os;
+ os << Milliseconds(52) << Microseconds(52) << Seconds(52);
+ ASSERT_EQUALS("52ms52\xce\xbcs52s", os.str());
+ }
+
} // namespace
} // namespace mongo