0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00
mongodb/bson/util/misc.h
2010-05-14 17:08:03 -04:00

63 lines
1.6 KiB
C++

/* @file util.h
*/
/*
* Copyright 2009 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <ctime>
namespace mongo {
using namespace std;
inline void time_t_to_String(time_t t, char *buf) {
#if defined(_WIN32)
ctime_s(buf, 64, &t);
#else
ctime_r(&t, buf);
#endif
buf[24] = 0; // don't want the \n
}
inline string time_t_to_String(time_t t = time(0) ){
char buf[32];
#if defined(_WIN32)
ctime_s(buf, 64, &t);
#else
ctime_r(&t, buf);
#endif
buf[24] = 0; // don't want the \n
return buf;
}
struct Date_t {
// TODO: make signed (and look for related TODO's)
unsigned long long millis;
Date_t(): millis(0) {}
Date_t(unsigned long long m): millis(m) {}
operator unsigned long long&() { return millis; }
operator const unsigned long long&() const { return millis; }
string toString() const {
char buf[64];
time_t_to_String(millis, buf);
return buf;
}
};
}