1
// @file time_support.h
3
/* Copyright 2010 10gen Inc.
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
22
#include <boost/thread/xtime.hpp>
23
#include <boost/date_time/posix_time/posix_time.hpp>
25
#include "mongo/bson/util/misc.h" // Date_t
29
void time_t_to_Struct(time_t t, struct tm * buf , bool local = false );
32
* Gets the current time string (in fixed width) in UTC. Sample format:
34
* Wed Oct 31 13:34:47.996
36
* @param timeStr pointer to the buffer to set the string - should at least be
39
void curTimeString(char* timeStr);
41
// uses ISO 8601 dates without trailing Z
42
// colonsOk should be false when creating filenames
43
std::string terseCurrentTime(bool colonsOk=true);
45
std::string timeToISOString(time_t time);
47
boost::gregorian::date currentDate();
49
// parses time of day in "hh:mm" format assuming 'hh' is 00-23
50
bool toPointInTime( const std::string& str , boost::posix_time::ptime* timeOfDay );
52
void sleepsecs(int s);
53
void sleepmillis(long long ms);
54
void sleepmicros(long long micros);
59
Backoff( int maxSleepMillis, int resetAfter ) :
60
_maxSleepMillis( maxSleepMillis ),
61
_resetAfterMillis( maxSleepMillis + resetAfter ), // Don't reset < the max sleep
62
_lastSleepMillis( 0 ),
63
_lastErrorTimeMillis( 0 )
66
void nextSleepMillis();
72
int _resetAfterMillis;
74
// Last sleep information
76
unsigned long long _lastErrorTimeMillis;
79
// DO NOT TOUCH except for testing
80
void jsTimeVirtualSkew( long long skew );
82
void jsTimeVirtualThreadSkew( long long skew );
83
long long getJSTimeVirtualThreadSkew();
85
/** Date_t is milliseconds since epoch */
88
/** warning this will wrap */
89
unsigned curTimeMicros();
90
unsigned long long curTimeMicros64();
91
unsigned long long curTimeMillis64();
93
// these are so that if you use one of them compilation will fail
94
char *asctime(const struct tm *tm);
95
char *ctime(const time_t *timep);
96
struct tm *gmtime(const time_t *timep);
97
struct tm *localtime(const time_t *timep);
99
#if defined(MONGO_BOOST_TIME_UTC_HACK) || (BOOST_VERSION >= 105000)
100
#define MONGO_BOOST_TIME_UTC boost::TIME_UTC_
102
#define MONGO_BOOST_TIME_UTC boost::TIME_UTC