TimeSpan.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_TimeSpan_hxx
00024 #define __ccxx_TimeSpan_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/String.h++>
00028
00029 namespace ccxx {
00030
00036 class COMMONCPP_API TimeSpan
00037 {
00038 public:
00039
00044 TimeSpan(int64_t span = INT64_CONST(0)) throw();
00045
00049 TimeSpan(int days, int hours, int minutes, int seconds, int msec = 0)
00050 throw();
00051
00053 TimeSpan(const TimeSpan& other) throw();
00054
00056 ~TimeSpan() throw();
00057
00059 void setSpan(int days, int hours, int minutes, int seconds, int msec = 0)
00060 throw();
00061
00063 void setSpan(int64_t seconds) throw();
00064
00066 inline int64_t getSpan() const throw()
00067 { return(_span); }
00068
00070 void setDays(int days) throw();
00071
00073 void addDays(int days) throw();
00074
00076 void subtractDays(int days) throw();
00077
00079 inline int getDays() const throw()
00080 { return(_days); }
00081
00083 void setHours(int hours) throw();
00084
00086 void addHours(int hours) throw();
00087
00089 void subtractHours(int hours) throw();
00090
00092 inline int getHours() const throw()
00093 { return(_hours); }
00094
00096 void setMinutes(int minutes) throw();
00097
00099 void addMinutes(int minutes) throw();
00100
00102 void subtractMinutes(int minutes) throw();
00103
00105 inline int getMinutes() const throw()
00106 { return(_minutes); }
00107
00109 void setSeconds(int seconds) throw();
00110
00112 void addSeconds(int seconds) throw();
00113
00115 void subtractSeconds(int seconds) throw();
00116
00118 inline int getSeconds() const throw()
00119 { return(_seconds); }
00120
00122 void setMilliseconds(int msec) throw();
00123
00125 void addMilliseconds(int msec) throw();
00126
00128 void subtractMilliseconds(int msec) throw();
00129
00131 inline int getMilliseconds() const throw()
00132 { return(_msec); }
00133
00134 TimeSpan& operator=(const TimeSpan& other) throw();
00135
00136 inline bool operator==(const TimeSpan& other) const throw()
00137 { return(_span == other._span); }
00138
00139 inline bool operator<(const TimeSpan& other) const throw()
00140 { return(_span < other._span); }
00141
00142 inline bool operator<=(const TimeSpan& other) const throw()
00143 { return(_span <= other._span); }
00144
00145 inline bool operator!=(const TimeSpan& other) const throw()
00146 { return(_span != other._span); }
00147
00148 inline bool operator>(const TimeSpan& other) const throw()
00149 { return(_span > other._span); }
00150
00151 inline bool operator>=(const TimeSpan& other) const throw()
00152 { return(_span >= other._span); }
00153
00154 TimeSpan& operator+=(const TimeSpan& span) throw();
00155 TimeSpan& operator+=(int seconds) throw();
00156 TimeSpan& operator-=(const TimeSpan& span) throw();
00157 TimeSpan& operator-=(int seconds) throw();
00158
00159 TimeSpan operator-() const throw();
00160
00162 inline int64_t toSeconds() const throw()
00163 { return(_span / msInSecond); }
00164
00166 inline operator int64_t() const throw()
00167 { return(_span); }
00168
00170 inline int64_t toMilliseconds() const throw()
00171 { return(_span); }
00172
00174 String toString() const;
00175
00177 static const int msInSecond;
00178
00180 static const int msInMinute;
00181
00183 static const int msInHour;
00184
00186 static const int msInDay;
00187
00188 private:
00189
00190 void _computeFields(int days, int hours, int minutes, int seconds,
00191 int msec) throw();
00192 void _computeFields(int64_t span) throw();
00193
00194 int _days;
00195 int _hours;
00196 int _minutes;
00197 int _seconds;
00198 int _msec;
00199 int64_t _span;
00200 };
00201
00202 };
00203
00204 #endif // __ccxx_TimeSpan_hxx
00205
00206