00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <ctime>
00023
00024 namespace mongo {
00025
00026 using namespace std;
00027
00028 inline void time_t_to_String(time_t t, char *buf) {
00029 #if defined(_WIN32)
00030 ctime_s(buf, 32, &t);
00031 #else
00032 ctime_r(&t, buf);
00033 #endif
00034 buf[24] = 0;
00035 }
00036
00037 inline string time_t_to_String(time_t t = time(0) ) {
00038 char buf[64];
00039 #if defined(_WIN32)
00040 ctime_s(buf, sizeof(buf), &t);
00041 #else
00042 ctime_r(&t, buf);
00043 #endif
00044 buf[24] = 0;
00045 return buf;
00046 }
00047
00048 inline string time_t_to_String_no_year(time_t t) {
00049 char buf[64];
00050 #if defined(_WIN32)
00051 ctime_s(buf, sizeof(buf), &t);
00052 #else
00053 ctime_r(&t, buf);
00054 #endif
00055 buf[19] = 0;
00056 return buf;
00057 }
00058
00059 inline string time_t_to_String_short(time_t t) {
00060 char buf[64];
00061 #if defined(_WIN32)
00062 ctime_s(buf, sizeof(buf), &t);
00063 #else
00064 ctime_r(&t, buf);
00065 #endif
00066 buf[19] = 0;
00067 if( buf[0] && buf[1] && buf[2] && buf[3] )
00068 return buf + 4;
00069 return buf;
00070 }
00071
00072 struct Date_t {
00073
00074 unsigned long long millis;
00075 Date_t(): millis(0) {}
00076 Date_t(unsigned long long m): millis(m) {}
00077 operator unsigned long long&() { return millis; }
00078 operator const unsigned long long&() const { return millis; }
00079 string toString() const {
00080 char buf[64];
00081 time_t_to_String(millis/1000, buf);
00082 return buf;
00083 }
00084 };
00085
00086
00087
00088 inline int strnlen( const char *s, int n ) {
00089 for( int i = 0; i < n; ++i )
00090 if ( !s[ i ] )
00091 return i;
00092 return -1;
00093 }
00094 }