mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
some timestamp helpers
This commit is contained in:
parent
9d792eb0c5
commit
c6a4f25e16
@ -122,6 +122,9 @@ namespace mongo {
|
||||
case BinData:
|
||||
s << fieldName() << " : BinData";
|
||||
break;
|
||||
case Timestamp:
|
||||
s << fieldName() << " : Timestamp " << timestampTime() << "|" << timestampInc();
|
||||
break;
|
||||
default:
|
||||
s << fieldName() << ": ?type=" << type();
|
||||
break;
|
||||
@ -442,6 +445,7 @@ namespace mongo {
|
||||
return f==0 ? 0 : 1;
|
||||
case Bool:
|
||||
return *l.value() - *r.value();
|
||||
case Timestamp:
|
||||
case Date:
|
||||
if ( l.date() < r.date() )
|
||||
return -1;
|
||||
|
@ -379,6 +379,14 @@ namespace mongo {
|
||||
type() == CodeWScope;
|
||||
}
|
||||
|
||||
unsigned long long timestampTime() const{
|
||||
unsigned long long t = ((unsigned int*)(value() + 4 ))[0];
|
||||
return t * 1000;
|
||||
}
|
||||
unsigned int timestampInc() const{
|
||||
return ((unsigned int*)(value() ))[0];
|
||||
}
|
||||
|
||||
protected:
|
||||
// If maxLen is specified, don't scan more than maxLen bytes.
|
||||
BSONElement(const char *d, int maxLen = -1) : data(d) {
|
||||
|
@ -159,10 +159,20 @@ Local<v8::Object> mongoToV8( BSONObj & m , bool array ){
|
||||
|
||||
b->Set( v8::String::New( "subtype" ) , v8::Number::New( f.binDataType() ) );
|
||||
b->Set( v8::String::New( "length" ) , v8::Number::New( len ) );
|
||||
|
||||
|
||||
o->Set( v8::String::New( f.fieldName() ) , b );
|
||||
break;
|
||||
};
|
||||
|
||||
case mongo::Timestamp: {
|
||||
Local<v8::Object> sub = v8::Object::New();
|
||||
|
||||
sub->Set( v8::String::New( "time" ) , v8::Date::New( f.timestampTime() ) );
|
||||
sub->Set( v8::String::New( "i" ) , v8::Number::New( f.timestampInc() ) );
|
||||
|
||||
o->Set( v8::String::New( f.fieldName() ) , sub );
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
cout << "can't handle type: ";
|
||||
|
Loading…
Reference in New Issue
Block a user