From c6a4f25e169c017317c55f336d7c92f8406e20bc Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Sat, 28 Feb 2009 18:44:31 -0500 Subject: [PATCH] some timestamp helpers --- db/jsobj.cpp | 4 ++++ db/jsobj.h | 8 ++++++++ shell/MongoJS.cpp | 12 +++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 2c5a7b1c804..c39d17f30ea 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -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; diff --git a/db/jsobj.h b/db/jsobj.h index 188ea775c32..e9f8568eab0 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -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) { diff --git a/shell/MongoJS.cpp b/shell/MongoJS.cpp index d261c02dd7e..e4176805e6d 100644 --- a/shell/MongoJS.cpp +++ b/shell/MongoJS.cpp @@ -159,10 +159,20 @@ Local 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 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: ";