1 |
douglas |
21 |
// Zoe AIM Away Message RSS Feed Generator |
2 |
|
|
// |
3 |
|
|
// Seth King and Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#ifndef _Stamp_hpp_ |
8 |
|
|
#define _Stamp_hpp_ |
9 |
|
|
|
10 |
|
|
#include "Zoe.hpp" |
11 |
|
|
|
12 |
|
|
#include <ctime> |
13 |
|
|
|
14 |
douglas |
31 |
template<int Seconds> |
15 |
|
|
class Period |
16 |
|
|
{ |
17 |
|
|
private: |
18 |
douglas |
37 |
std::time_t seconds; |
19 |
douglas |
31 |
public: |
20 |
douglas |
37 |
Period(std::time_t period) : seconds(period * Seconds) {} |
21 |
|
|
operator std::time_t() const { return seconds; } |
22 |
douglas |
31 |
}; |
23 |
|
|
|
24 |
|
|
typedef Period<60> Minute; |
25 |
|
|
typedef Period<3600> Hour; |
26 |
|
|
typedef Period<86400> Day; |
27 |
|
|
|
28 |
douglas |
21 |
class Stamp |
29 |
|
|
{ |
30 |
|
|
private: |
31 |
douglas |
31 |
std::time_t when; |
32 |
douglas |
21 |
std::tm stamp; |
33 |
|
|
public: |
34 |
douglas |
31 |
Stamp(std::time_t when = std::time(NULL)) : when(when) { gmtime_r(&when, |
35 |
|
|
&stamp); } |
36 |
douglas |
21 |
Stamp(const ext::String& when); |
37 |
douglas |
36 |
ext::String get822() const; |
38 |
|
|
ext::String getW3() const; |
39 |
douglas |
37 |
void setSeconds(int seconds); |
40 |
|
|
void setMinutes(int minutes); |
41 |
|
|
operator ext::String() const; |
42 |
douglas |
34 |
Stamp operator+(std::time_t seconds) const { return when + seconds; } |
43 |
|
|
Stamp operator-(std::time_t seconds) const { return when - seconds; } |
44 |
douglas |
33 |
bool operator<(const Stamp& stamp) const { return when < stamp.when; } |
45 |
douglas |
21 |
}; |
46 |
|
|
|
47 |
douglas |
37 |
inline std::ostream& operator<<(std::ostream& sout, const Stamp& stamp) |
48 |
|
|
{ |
49 |
|
|
return sout << ext::String(stamp); |
50 |
|
|
} |
51 |
douglas |
30 |
|
52 |
douglas |
21 |
#endif // _Stamp_hpp_ |