summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r--src/mongo/db/pipeline/document_value_test.cpp26
-rw-r--r--src/mongo/db/pipeline/expression.cpp4
-rw-r--r--src/mongo/db/pipeline/value.cpp7
-rw-r--r--src/mongo/db/pipeline/value.h6
4 files changed, 23 insertions, 20 deletions
diff --git a/src/mongo/db/pipeline/document_value_test.cpp b/src/mongo/db/pipeline/document_value_test.cpp
index 0deb17f7341..0afffb5b639 100644
--- a/src/mongo/db/pipeline/document_value_test.cpp
+++ b/src/mongo/db/pipeline/document_value_test.cpp
@@ -525,7 +525,7 @@ namespace DocumentTests {
class Date {
public:
void run() {
- Value value = Value(Date_t(999));
+ Value value = Value(Date_t::fromMillisSinceEpoch(999));
ASSERT_EQUALS( 999, value.getDate() );
ASSERT_EQUALS( mongo::Date, value.getType() );
assertRoundTrips( value );
@@ -807,7 +807,7 @@ namespace DocumentTests {
/** Coerce Date(0) to bool. */
class DateToBool : public ToBoolTrue {
- Value value() { return Value(Date_t(0)); }
+ Value value() { return Value(Date_t{}); }
};
/** Coerce js literal regex to bool. */
@@ -1014,7 +1014,7 @@ namespace DocumentTests {
/** Coerce date to date. */
class DateToDate : public ToDateBase {
- Value value() { return Value(Date_t(888)); }
+ Value value() { return Value(Date_t::fromMillisSinceEpoch(888)); }
long long expected() { return 888; }
};
@@ -1083,7 +1083,7 @@ namespace DocumentTests {
/** Coerce date to string. */
class DateToString : public ToStringBase {
- Value value() { return Value(Date_t(1234567890LL*1000)); }
+ Value value() { return Value(Date_t::fromMillisSinceEpoch(1234567890LL*1000)); }
string expected() { return "2009-02-13T23:31:30"; } // from js
};
@@ -1120,7 +1120,7 @@ namespace DocumentTests {
class DateToTimestamp {
public:
void run() {
- ASSERT_THROWS( Value(Date_t(1010)).coerceToTimestamp(),
+ ASSERT_THROWS( Value(Date_t::fromMillisSinceEpoch(1010)).coerceToTimestamp(),
UserException );
}
};
@@ -1261,10 +1261,16 @@ namespace DocumentTests {
assertComparison( 1, true, false );
// Date.
- assertComparison( 0, Date_t( 555 ), Date_t( 555 ) );
- assertComparison( 1, Date_t( 555 ), Date_t( 554 ) );
+ assertComparison( 0,
+ Date_t::fromMillisSinceEpoch( 555 ),
+ Date_t::fromMillisSinceEpoch( 555 ) );
+ assertComparison( 1,
+ Date_t::fromMillisSinceEpoch( 555 ),
+ Date_t::fromMillisSinceEpoch( 554 ) );
// Negative date.
- assertComparison( 1, Date_t( 0 ), Date_t( -1 ) );
+ assertComparison( 1,
+ Date_t::fromMillisSinceEpoch( 0 ),
+ Date_t::fromMillisSinceEpoch( -1 ) );
// Regex.
assertComparison( 0, fromjson( "{'':/a/}" ), fromjson( "{'':/a/}" ) );
@@ -1290,8 +1296,8 @@ namespace DocumentTests {
assertComparison(-1, Value(vector<Value>()), Value(BSONBinData("", 0, MD5Type)));
assertComparison(-1, Value(BSONBinData("", 0, MD5Type)), Value(mongo::OID()));
assertComparison(-1, Value(mongo::OID()), Value(false));
- assertComparison(-1, Value(false), Value(Date_t(0)));
- assertComparison(-1, Value(Date_t(0)), Value(Timestamp()));
+ assertComparison(-1, Value(false), Value(Date_t()));
+ assertComparison(-1, Value(Date_t()), Value(Timestamp()));
assertComparison(-1, Value(Timestamp()), Value(BSONRegEx("")));
assertComparison(-1, Value(BSONRegEx("")), Value(BSONDBRef("", mongo::OID())));
assertComparison(-1, Value(BSONDBRef("", mongo::OID())), Value(BSONCode("")));
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index defc38d8c12..e8c121c2b04 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -422,7 +422,7 @@ namespace {
if (haveDate) {
if (totalType == NumberDouble)
longTotal = static_cast<long long>(doubleTotal);
- return Value(Date_t(longTotal));
+ return Value(Date_t::fromMillisSinceEpoch(longTotal));
}
else if (totalType == NumberLong) {
return Value(longTotal);
@@ -2548,7 +2548,7 @@ namespace {
}
else if (rhs.numeric()) {
long long millisSinceEpoch = lhs.getDate() - rhs.coerceToLong();
- return Value(Date_t(millisSinceEpoch));
+ return Value(Date_t::fromMillisSinceEpoch(millisSinceEpoch));
}
else {
uasserted(16613, str::stream() << "cant $subtract a "
diff --git a/src/mongo/db/pipeline/value.cpp b/src/mongo/db/pipeline/value.cpp
index b156d290613..c949601ac4d 100644
--- a/src/mongo/db/pipeline/value.cpp
+++ b/src/mongo/db/pipeline/value.cpp
@@ -186,8 +186,7 @@ namespace mongo {
break;
case Date:
- // this is really signed but typed as unsigned for historical reasons
- _storage.dateValue = static_cast<long long>(elem.date().millis);
+ _storage.dateValue = elem.date().toMillisSinceEpoch();
break;
case RegEx: {
@@ -288,7 +287,7 @@ namespace mongo {
case NumberDouble: return builder << val.getDouble();
case String: return builder << val.getStringData();
case Bool: return builder << val.getBool();
- case Date: return builder << Date_t(val.getDate());
+ case Date: return builder << Date_t::fromMillisSinceEpoch(val.getDate());
case bsonTimestamp: return builder << val.getTimestamp();
case Object: return builder << val.getDocument();
case Symbol: return builder << BSONSymbol(val.getStringData());
@@ -1018,7 +1017,7 @@ namespace mongo {
case NumberLong: return Value(buf.read<long long>());
case NumberDouble: return Value(buf.read<double>());
case Bool: return Value(bool(buf.read<char>()));
- case Date: return Value(Date_t(buf.read<long long>()));
+ case Date: return Value(Date_t::fromMillisSinceEpoch(buf.read<long long>()));
case bsonTimestamp: return Value(buf.read<Timestamp>());
// types that are like strings
diff --git a/src/mongo/db/pipeline/value.h b/src/mongo/db/pipeline/value.h
index 5324cc1b432..ecc66719d11 100644
--- a/src/mongo/db/pipeline/value.h
+++ b/src/mongo/db/pipeline/value.h
@@ -91,9 +91,7 @@ namespace mongo {
explicit Value(const UndefinedLabeler&) : _storage(Undefined) {} // BSONUndefined
explicit Value(const MinKeyLabeler&) : _storage(MinKey) {} // MINKEY
explicit Value(const MaxKeyLabeler&) : _storage(MaxKey) {} // MAXKEY
- explicit Value(const Date_t& date)
- : _storage(Date, static_cast<long long>(date.millis)) // millis really signed
- {}
+ explicit Value(const Date_t& date) : _storage(Date, date.toMillisSinceEpoch()) {}
// TODO: add an unsafe version that can share storage with the BSONElement
/// Deep-convert from BSONElement to Value
@@ -317,7 +315,7 @@ namespace mongo {
inline Timestamp Value::getTimestamp() const {
verify(getType() == bsonTimestamp);
- return Date_t(_storage.timestampValue);
+ return Timestamp(_storage.timestampValue);
}
inline const char* Value::getRegex() const {