From 9aac625685811873ffbc2d3e8d09531eff1ce10e Mon Sep 17 00:00:00 2001 From: Andy Schwerin Date: Thu, 7 May 2015 16:45:29 -0400 Subject: 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. --- src/mongo/bson/bsonelement.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/mongo/bson/bsonelement.cpp') diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index 49f45c44a12..86efd0f7e27 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -201,7 +201,7 @@ namespace mongo { s << "\"" << dateToISOStringLocal(date()) << "\""; } else { - s << "{ \"$numberLong\" : \"" << static_cast(d.millis) << "\" }"; + s << "{ \"$numberLong\" : \"" << d.toMillisSinceEpoch() << "\" }"; } s << " }"; } @@ -221,7 +221,7 @@ namespace mongo { else { // FIXME: This is not parseable by the shell, since it may not fit in a // float - s << d.millis; + s << d.toMillisSinceEpoch(); } } else { @@ -266,10 +266,14 @@ namespace mongo { case bsonTimestamp: if ( format == TenGen ) { - s << "Timestamp( " << ( timestampTime() / 1000 ) << ", " << timestampInc() << " )"; + s << "Timestamp( " + << durationCount(timestampTime().toDurationSinceEpoch()) + << ", " << timestampInc() << " )"; } else { - s << "{ \"$timestamp\" : { \"t\" : " << ( timestampTime() / 1000 ) << ", \"i\" : " << timestampInc() << " } }"; + s << "{ \"$timestamp\" : { \"t\" : " + << durationCount(timestampTime().toDurationSinceEpoch()) + << ", \"i\" : " << timestampInc() << " } }"; } break; @@ -616,7 +620,7 @@ namespace mongo { s << "EOO"; break; case mongo::Date: - s << "new Date(" << (long long) date() << ')'; + s << "new Date(" << date().toMillisSinceEpoch() << ')'; break; case RegEx: { s << "/" << regex() << '/'; @@ -701,7 +705,7 @@ namespace mongo { } break; case bsonTimestamp: - s << "Timestamp " << timestampTime() << "|" << timestampInc(); + s << "Timestamp " << timestampTime().toMillisSinceEpoch() << "|" << timestampInc(); break; default: s << "?type=" << type(); @@ -852,8 +856,8 @@ namespace mongo { case Date: // Signed comparisons for Dates. { - long long a = (long long) l.Date().millis; - long long b = (long long) r.Date().millis; + const Date_t a = l.Date(); + const Date_t b = r.Date(); if( a < b ) return -1; return a == b ? 0 : 1; -- cgit v1.2.1