mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
support appending time_t to BSONObjBuilder
This commit is contained in:
parent
4f16017dc4
commit
f84a1f2429
@ -1196,6 +1196,15 @@ namespace mongo {
|
||||
void append( const char *fieldName, OID oid ) {
|
||||
appendOID( fieldName, &oid );
|
||||
}
|
||||
/** Append a time_t date.
|
||||
@param dt a C-style 32 bit date value, that is
|
||||
the number of seconds since January 1, 1970, 00:00:00 GMT
|
||||
*/
|
||||
void append(const char *fieldName, time_t dt) {
|
||||
b.append((char) Date);
|
||||
b.append(fieldName);
|
||||
b.append(static_cast<unsigned long long>(dt) * 1000);
|
||||
}
|
||||
/** Append a date.
|
||||
@param dt a Java-style 64 bit date value, that is
|
||||
the number of milliseconds since January 1, 1970, 00:00:00 GMT
|
||||
|
@ -724,6 +724,24 @@ namespace JsobjTests {
|
||||
}
|
||||
};
|
||||
|
||||
class TimeTBuilder {
|
||||
public:
|
||||
void run() {
|
||||
unsigned long long before = jsTime();
|
||||
time_t now = time(NULL);
|
||||
BSONObj o = BSON("now" << now);
|
||||
unsigned long long after = jsTime();
|
||||
|
||||
|
||||
ASSERT( o.valid() );
|
||||
|
||||
BSONElement e = o["now"];
|
||||
ASSERT( e.type() == Date );
|
||||
ASSERT( e.date()/1000 >= before/1000 );
|
||||
ASSERT( e.date()/1000 <= after/1000 );
|
||||
}
|
||||
};
|
||||
|
||||
class MinMaxElementTest {
|
||||
public:
|
||||
|
||||
@ -1095,6 +1113,7 @@ namespace JsobjTests {
|
||||
add< ValueStreamTests::ElementAppend >();
|
||||
add< SubObjectBuilder >();
|
||||
add< DateNowBuilder >();
|
||||
add< TimeTBuilder >();
|
||||
add< MinMaxElementTest >();
|
||||
add< ComparatorTest >();
|
||||
add< ExtractFieldsTest >();
|
||||
|
Loading…
Reference in New Issue
Block a user