From 1e980dae29f556d664dec39aec760bc6d3754a01 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 14 Apr 2012 19:10:18 -0700 Subject: [PATCH] Initial check in of misc utilities. --- src/utils.cpp | 22 ++++++++++++++++++++++ src/utils.h | 12 ++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/utils.cpp create mode 100644 src/utils.h diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000000..9e65a31019 --- /dev/null +++ b/src/utils.cpp @@ -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 diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000000..d02f232ab6 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,12 @@ +#ifndef __UTILS__ +#define __UTILS__ + +#include + +#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