mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Initial check in of misc utilities.
This commit is contained in:
22
src/utils.cpp
Normal file
22
src/utils.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
boost::posix_time::ptime ptEpoch()
|
||||||
|
{
|
||||||
|
return boost::posix_time::ptime(boost::gregorian::date(2000, boost::gregorian::Jan, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
int iToSeconds(boost::posix_time::ptime ptWhen)
|
||||||
|
{
|
||||||
|
return ptWhen.is_not_a_date_time()
|
||||||
|
? -1
|
||||||
|
: (ptWhen-ptEpoch()).total_seconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::posix_time::ptime ptFromSeconds(int iSeconds)
|
||||||
|
{
|
||||||
|
return iSeconds < 0
|
||||||
|
? boost::posix_time::ptime(boost::posix_time::not_a_date_time)
|
||||||
|
: ptEpoch() + boost::posix_time::seconds(iSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// vim:ts=4
|
||||||
12
src/utils.h
Normal file
12
src/utils.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef __UTILS__
|
||||||
|
#define __UTILS__
|
||||||
|
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
|
#define nothing() do {} while (0)
|
||||||
|
|
||||||
|
boost::posix_time::ptime ptEpoch();
|
||||||
|
int iToSeconds(boost::posix_time::ptime ptWhen);
|
||||||
|
boost::posix_time::ptime ptFromSeconds(int iSeconds);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user