ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Stamp.hpp
(Generate patch)

Comparing trunk/Stamp.hpp (file contents):
Revision 30 by douglas, 2004-07-19T21:24:52-07:00 vs.
Revision 39 by douglas, 2004-07-23T17:52:53-07:00

# Line 11 | Line 11
11  
12   #include <ctime>
13  
14 + template<int Seconds>
15 + class Period
16 + {
17 + private:
18 +        std::time_t seconds;
19 + public:
20 +        Period(std::time_t period) : seconds(period * Seconds) {}
21 +        operator std::time_t() const { return seconds; }
22 + };
23 +
24 + typedef Period<60> Minute;
25 + typedef Period<3600> Hour;
26 + typedef Period<86400> Day;
27 +
28   class Stamp
29   {
30   private:
31 +        std::time_t when;
32          std::tm stamp;
33   public:
34 <        Stamp(std::time_t now = std::time(NULL)) { gmtime_r(&now, &stamp); }
34 >        Stamp(std::time_t when = std::time(NULL)) : when(when) { gmtime_r(&when,
35 >                &stamp); }
36          Stamp(const ext::String& when);
37 +        ext::String get822() const;
38 +        ext::String getW3() const;
39 +        ext::String getDate() const;
40 +        ext::String getTime() const;
41 +        void setSeconds(int seconds);
42 +        void setMinutes(int minutes);
43          operator ext::String() const;
44 <        Stamp operator+(int days) const;
45 <        Stamp operator-(int days) const { return *this + -days; }
46 <        Stamp& operator++() { *this += 1; return *this; }
25 <        Stamp operator++(int) { Stamp stamp(*this); *this += 1; return stamp; }
26 <        Stamp& operator+=(int days) { *this = *this + days; return *this; }
27 <        Stamp& operator--() { *this -= 1; return *this; }
28 <        Stamp operator--(int) { Stamp stamp(*this); *this -= 1; return stamp; }
29 <        Stamp& operator-=(int days) { *this = *this - days; return *this; }
44 >        Stamp operator+(std::time_t seconds) const { return when + seconds; }
45 >        Stamp operator-(std::time_t seconds) const { return when - seconds; }
46 >        bool operator<(const Stamp& stamp) const { return when < stamp.when; }
47   };
48  
49 < inline ext::String operator+(const Stamp& stamp, const ext::String& string)
33 < {
34 <        return ext::String(stamp) + string;
35 < }
36 <
37 < inline ext::String operator+(const ext::String& string, const Stamp& stamp)
49 > inline std::ostream& operator<<(std::ostream& sout, const Stamp& stamp)
50   {
51 <        return string + ext::String(stamp);
51 >        return sout << ext::String(stamp);
52   }
53  
54   #endif // _Stamp_hpp_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines