0
0
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:
Eliot Horowitz 2009-02-28 18:44:31 -05:00
parent 9d792eb0c5
commit c6a4f25e16
3 changed files with 23 additions and 1 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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: ";