diff options
author | Shaun Verch <shaun.verch@mongodb.com> | 2014-05-13 17:01:04 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@mongodb.com> | 2014-05-21 12:38:12 -0400 |
commit | 3b97c0870427f676cf3ffbddabc5df8b1fa44fa5 (patch) | |
tree | f27234c3f882e1d3c1fc17f2edc16476ac0460bb /src/mongo/util | |
parent | 024fb8af552171a22407594babb0f324d971b380 (diff) | |
download | mongo-3b97c0870427f676cf3ffbddabc5df8b1fa44fa5.tar.gz |
SERVER-13760 Do not call dateToISOString if date is not formatable
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/time_support.cpp | 9 | ||||
-rw-r--r-- | src/mongo/util/time_support.h | 2 | ||||
-rw-r--r-- | src/mongo/util/time_support_test.cpp | 13 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/util/time_support.cpp b/src/mongo/util/time_support.cpp index a21a2a4ad6f..3b3900c55b7 100644 --- a/src/mongo/util/time_support.cpp +++ b/src/mongo/util/time_support.cpp @@ -54,6 +54,14 @@ namespace mongo { +namespace { + const bool isTimeTSmall = (sizeof(time_t) == sizeof(int32_t)); +} // namespace + + const Date_t Date_t::maxFormatableDate = isTimeTSmall ? + 2147483647000ULL : // "2038-01-19T03:14:07Z" + 32535215999000ULL; // "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; @@ -130,6 +138,7 @@ namespace { }; void _dateToISOString(Date_t date, bool local, DateStringBuffer* result) { + invariant(date.millis <= Date_t::maxFormatableDate); static const int bufSize = DateStringBuffer::dataCapacity; char* const buf = result->data; struct tm t; diff --git a/src/mongo/util/time_support.h b/src/mongo/util/time_support.h index 284aa7a811e..590ed77a2ef 100644 --- a/src/mongo/util/time_support.h +++ b/src/mongo/util/time_support.h @@ -57,6 +57,8 @@ namespace mongo { int64_t asInt64() const { return static_cast<int64_t>(millis); } + + static const Date_t maxFormatableDate; }; // 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 d8ea2235291..e1e76072b6a 100644 --- a/src/mongo/util/time_support_test.cpp +++ b/src/mongo/util/time_support_test.cpp @@ -180,6 +180,10 @@ namespace { swull = dateFromISOString("2058-02-20T18:29:11.100Z"); ASSERT_OK(swull.getStatus()); ASSERT_EQUALS(swull.getValue(), 2781455351100ULL); + + swull = dateFromISOString("3001-01-01T08:00:00.000Z"); + ASSERT_OK(swull.getStatus()); + ASSERT_EQUALS(swull.getValue(), 32535244800000ULL); } swull = dateFromISOString("2013-02-20T18:29:11.100Z"); @@ -250,6 +254,15 @@ namespace { swull = dateFromISOString("2058-02-20T13:29:11.100-0500"); ASSERT_OK(swull.getStatus()); ASSERT_EQUALS(swull.getValue(), 2781455351100ULL); + + swull = dateFromISOString("3000-12-31T23:59:59Z"); + ASSERT_OK(swull.getStatus()); + ASSERT_EQUALS(swull.getValue(), 32535215999000ULL); + } + else { + swull = dateFromISOString("2038-01-19T03:14:07Z"); + ASSERT_OK(swull.getStatus()); + ASSERT_EQUALS(swull.getValue(), 2147483647000ULL); } swull = dateFromISOString("2013-02-20T13:29:11.100-0500"); |