summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonelement.cpp
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2015-05-07 16:45:29 -0400
committerAndy Schwerin <schwerin@mongodb.com>2015-05-12 09:57:33 -0400
commit9aac625685811873ffbc2d3e8d09531eff1ce10e (patch)
treeecd8dd9fc9d148b196c6ab2aa5e38e5f9e327c54 /src/mongo/bson/bsonelement.cpp
parent21a16d229bdba571f1118a419898b666c666b869 (diff)
downloadmongo-9aac625685811873ffbc2d3e8d09531eff1ce10e.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/bson/bsonelement.cpp')
-rw-r--r--src/mongo/bson/bsonelement.cpp20
1 files changed, 12 insertions, 8 deletions
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<long long>(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<Seconds>(timestampTime().toDurationSinceEpoch())
+ << ", " << timestampInc() << " )";
}
else {
- s << "{ \"$timestamp\" : { \"t\" : " << ( timestampTime() / 1000 ) << ", \"i\" : " << timestampInc() << " } }";
+ s << "{ \"$timestamp\" : { \"t\" : "
+ << durationCount<Seconds>(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;