-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
date.h
33 lines (27 loc) · 1.13 KB
/
date.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
#ifndef OAK_DATE_H_AIWA64W2
#define OAK_DATE_H_AIWA64W2
#include <oak/misc.h>
namespace oak
{
// the ‘at’ value is seconds relative to Jan 1 2001 00:00:00 GMT
struct PUBLIC date_t
{
date_t (time_t unixTime);
date_t (std::string const& str);
date_t (CFAbsoluteTime at = 0) : at(at) { }
explicit operator bool () const { return at != 0; }
bool operator== (date_t const& rhs) const { return at == rhs.at; }
bool operator!= (date_t const& rhs) const { return at != rhs.at; }
bool operator< (date_t const& rhs) const { return at < rhs.at; }
double operator- (date_t const& rhs) const { return at - rhs.at; }
date_t operator+ (double rhs) const { return date_t(at + rhs); }
date_t operator- (double rhs) const { return date_t(at - rhs); }
double value () const { return at; }
time_t time_value () const { return 978307200 + round(at); }
static date_t now ();
private:
CFAbsoluteTime at;
};
PUBLIC std::string to_s (date_t const& date, std::string const& dateFormat = "%F %T +0000");
} /* oak */
#endif /* end of include guard: OAK_DATE_H_AIWA64W2 */