ARC SDK
DateTime.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef ARCLIB_TIME
4 #define ARCLIB_TIME
5 
6 #include <stdint.h>
7 #include <sigc++/slot.h>
8 
9 #include <ctime>
10 #include <iostream>
11 #include <string>
12 
13 namespace Arc {
14 
18 
19  enum TimeFormat {
27  };
28 
30  enum PeriodBase {
39  };
40 
42 
46  class Period {
47  public:
49  Period();
50 
52  Period(time_t);
53 
55  Period(time_t seconds, uint32_t nanoseconds);
56 
58  Period(const std::string&, PeriodBase base = PeriodSeconds);
59 
61  Period& operator=(time_t);
62 
64  Period& operator=(const Period&);
65 
67  void SetPeriod(time_t sec);
69  void SetPeriod(time_t sec, uint32_t nanosec);
70 
72  time_t GetPeriod() const;
74  time_t GetPeriodNanoseconds() const;
75 
77  const sigc::slot<const char*>* istr() const;
78 
80  operator std::string() const;
81 
83  bool operator<(const Period&) const;
84 
86  bool operator>(const Period&) const;
87 
89  bool operator<=(const Period&) const;
90 
92  bool operator>=(const Period&) const;
93 
95  bool operator==(const Period&) const;
96 
98  bool operator!=(const Period&) const;
99 
100  Period& operator+=(const Period&);
101 
102  private:
104  time_t seconds;
105  uint32_t nanoseconds;
106 
108  const char* IStr() const;
109  sigc::slot<const char*> slot;
110  std::string is;
111  };
112 
114  std::ostream& operator<<(std::ostream&, const Period&);
115 
116 
117 
119 
123  class Time {
124  public:
126  Time();
127 
129  Time(time_t);
130 
132  Time(time_t time, uint32_t nanosec);
133 
135  Time(const std::string&);
136 
138  Time& operator=(time_t);
139 
141  Time& operator=(const Time&);
142 
144  Time& operator=(const char*);
145 
147  Time& operator=(const std::string&);
148 
150  void SetTime(time_t);
151 
153  void SetTime(time_t time, uint32_t nanosec);
154 
156  time_t GetTime() const;
158  time_t GetTimeNanoseconds() const;
159 
161  operator std::string() const;
162 
164  std::string str(const TimeFormat& = time_format) const;
165 
167  static void SetFormat(const TimeFormat&);
168 
170  static TimeFormat GetFormat();
171 
173  bool operator<(const Time&) const;
174 
176  bool operator>(const Time&) const;
177 
179  bool operator<=(const Time&) const;
180 
182  bool operator>=(const Time&) const;
183 
185  bool operator==(const Time&) const;
186 
188  bool operator!=(const Time&) const;
189 
191  Time operator+(const Period&) const;
192 
194  Time operator-(const Period&) const;
195 
197  Period operator-(const Time&) const;
198 
200  static const int YEAR = 31536000;
202  static const int MONTH = 2592000;
204  static const int WEEK = 604800;
206  static const int DAY = 86400;
208  static const int HOUR = 3600;
210  static const time_t UNDEFINED = (time_t)(-1);
211 
212  private:
214  time_t gtime;
215 
217  uint32_t gnano;
218 
220  static TimeFormat time_format;
221  };
222 
224  std::ostream& operator<<(std::ostream&, const Time&);
225 
227  std::string TimeStamp(const TimeFormat& = Time::GetFormat());
228 
230  std::string TimeStamp(Time, const TimeFormat& = Time::GetFormat());
231 
233 } // namespace Arc
234 
235 #endif // ARCLIB_TIME