SpinParser  1.0
Timestamp.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 #include <boost/date_time.hpp>
11 
12 namespace Timestamp
13 {
17  typedef boost::posix_time::ptime Time;
18  typedef boost::posix_time::time_duration Duration;
19 
25  inline Time time()
26  {
27  return boost::posix_time::second_clock::local_time();
28  }
29 
36  inline Time time(const int offset)
37  {
38  return boost::posix_time::second_clock::local_time() + boost::posix_time::time_duration(0, 0, offset, 0);
39  }
40 
47  inline Time time(const std::string &timestamp)
48  {
49  return boost::posix_time::time_from_string(timestamp);
50  }
51 
59  inline bool isOlder(const Time &time, const int offset)
60  {
61  return (Timestamp::time() - time).total_seconds() > offset;
62  }
63 
70  inline std::string timestamp(const Time &time)
71  {
72  return boost::posix_time::to_simple_string(time);
73  }
74 
80  inline std::string timestamp()
81  {
82  return timestamp(time());
83  }
84 }
Timestamp::isOlder
bool isOlder(const Time &time, const int offset)
Check whether the time object is older than a given number of seconds.
Definition: Timestamp.hpp:59
Timestamp::timestamp
std::string timestamp(const Time &time)
Retrieve a timestamp string for the specified time.
Definition: Timestamp.hpp:70
Timestamp::time
Time time(const std::string &timestamp)
Get a time object from a formatted timestamp string.
Definition: Timestamp.hpp:47
Timestamp::time
Time time()
Get the current time.
Definition: Timestamp.hpp:25
Timestamp::Time
boost::posix_time::ptime Time
Data structure to jold time and date information.
Definition: Timestamp.hpp:17