-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcron_boost.h
53 lines (34 loc) · 1.57 KB
/
cron_boost.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef __CRON_CRON_BOOST_H__
#define __CRON_CRON_BOOST_H__
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/chrono/process_cpu_clocks.hpp"
#include <boost/asio.hpp>
namespace Cron {
typedef boost::posix_time::ptime TimePoint;
typedef boost::asio::io_service IOService;
typedef boost::asio::deadline_timer Timer;
typedef boost::asio::basic_waitable_timer<boost::chrono::process_real_cpu_clock> CpuTimer;
typedef boost::asio::deadline_timer Timer;
typedef boost::posix_time::time_duration Duration;
inline TimePoint getTime(const std::string & value){
return TimePoint(boost::posix_time::time_from_string(value));
}
inline TimePoint Now() {
return boost::posix_time::second_clock::local_time();
}
}
#define CRON_HOURS(x) ( boost::posix_time::hours((x)) )
#define CRON_DAY(x) CRON_HOURS( 24 * (x) )
#define CRON_MINUTES(x) ( boost::posix_time::minutes((x)) )
#define CRON_SECONDS(x) ( boost::posix_time::seconds((x)) )
#define CRON_CHRONO_SECONDS(x) ( boost::chrono::seconds((x)) )
#define CRON_NAOSECONDS(x) ( boost::posix_time::nanoseconds((x)) )
// TimePoint to std::tm
#define CRON_TO_TM(x) ( boost::posix_time::to_tm(x) )
// timestamp to TimePoint
#define CRON_FROM_TIME_T(x) ( boost::posix_time::from_time_t(x) )
// std::tm to TimePoint
#define CRON_FROM_TM(x) ( boost::posix_time::ptime_from_tm(x) )
#define INVALID_TIMEPOINT CRON_FROM_TIME_T(std::time_t(0))
#define TIMEPOINT_TO_STRING(x) (boost::posix_time::to_iso_string(x))
#endif // __CRON_CRON_BOOST_H__