ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Stamp.hpp
Revision: 32
Committed: 2004-07-20T00:40:43-07:00 (20 years, 11 months ago) by douglas
File size: 1207 byte(s)
Log Message:
w00t!

File Contents

# User Rev Content
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     int seconds;
19     public:
20     Period(int period) : seconds(period * Seconds) {}
21     operator int() const { return seconds; }
22     };
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 25 operator ext::String() const;
38 douglas 31 Stamp operator+(int seconds) const { return when + seconds; }
39     Stamp operator-(int seconds) const { return when - seconds; }
40     bool operator <(const Stamp& stamp) const { return when < stamp.when; }
41 douglas 21 };
42    
43 douglas 30 inline ext::String operator+(const Stamp& stamp, const ext::String& string)
44     {
45     return ext::String(stamp) + string;
46     }
47    
48     inline ext::String operator+(const ext::String& string, const Stamp& stamp)
49     {
50     return string + ext::String(stamp);
51     }
52    
53 douglas 32 inline std::ostream& operator<<(std::ostream& sout, const Stamp& stamp)
54     {
55     return sout << ext::String(stamp);
56     }
57    
58 douglas 21 #endif // _Stamp_hpp_

Properties

Name Value
svn:eol-style native
svn:keywords Id