0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Convert OID to datetimes SERVER-857

This commit is contained in:
Mathias Stearn 2010-04-14 15:31:00 -04:00
parent 1153865ebf
commit 0cae84589e
3 changed files with 38 additions and 0 deletions

View File

@ -1474,6 +1474,16 @@ namespace mongo {
}
}
time_t OID::asTimeT(){
int time;
char* T = (char *) &time;
T[0] = data[3];
T[1] = data[2];
T[2] = data[1];
T[3] = data[0];
return time;
}
Labeler::Label GT( "$gt" );
Labeler::Label GTE( "$gte" );
Labeler::Label LT( "$lt" );

View File

@ -172,6 +172,9 @@ namespace mongo {
/** Set to the hex string value specified. */
void init( string s );
time_t asTimeT();
Date_t asDateT() { return asTimeT() * (long long)1000; }
};
ostream& operator<<( ostream &s, const OID &o );

View File

@ -729,6 +729,30 @@ namespace JsobjTests {
ASSERT( a.woCompare( c ) < 0 );
}
};
class time {
public:
void run(){
OID oid;
{
time_t before = ::time(0);
oid.init();
time_t after = ::time(0);
ASSERT( oid.asTimeT() >= before );
ASSERT( oid.asTimeT() <= after );
}
{
Date_t before = jsTime();
sleepsecs(1);
oid.init();
Date_t after = jsTime();
ASSERT( oid.asDateT() >= before );
ASSERT( oid.asDateT() <= after );
}
}
};
} // namespace OIDTests
namespace ValueStreamTests {
@ -1497,6 +1521,7 @@ namespace JsobjTests {
add< OIDTests::initParse1 >();
add< OIDTests::append >();
add< OIDTests::increasing >();
add< OIDTests::time >();
add< ValueStreamTests::LabelBasic >();
add< ValueStreamTests::LabelShares >();
add< ValueStreamTests::LabelDouble >();