00001 #ifndef PSTIME_DURATION_H
00002 #define PSTIME_DURATION_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <iostream>
00017 #include <string>
00018
00019
00020
00021
00022
00023
00024 namespace PSTime {
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class Duration {
00042 public:
00043
00044 enum ParseStatus {
00045 PARSE_IS_OK,
00046 DURATION_STRING_TOO_SHORT,
00047 DURATION_STRING_TOO_LONG,
00048 DURATION_STRING_WRONG_FORMAT_MISSING_P,
00049 DURATION_TOO_LONG_FIELD_FOR_YEARS,
00050 DURATION_TOO_LONG_FIELD_FOR_MONTHS,
00051 DURATION_TOO_LONG_FIELD_FOR_DAYS,
00052 DURATION_TOO_LONG_FIELD_FOR_HOURS,
00053 DURATION_TOO_LONG_FIELD_FOR_MINUTES,
00054 DURATION_TOO_LONG_FIELD_FOR_SECONDS,
00055 DURATION_TOO_LONG_FIELD_FOR_SECOND_FRACTION
00056 };
00057
00058
00059 Duration () ;
00060
00061
00062 Duration( const Duration & d );
00063
00064
00065 Duration( time_t sec, time_t nsec = 0 );
00066
00067
00068
00069
00070
00071
00072
00073 Duration( time_t Years,
00074 time_t Days,
00075 time_t Hours,
00076 time_t Mins = 0,
00077 time_t Secs = 0,
00078 time_t Nsecs = 0 );
00079
00080
00081 virtual ~Duration () {};
00082
00083
00084 Duration operator - ( const Duration & d1 ) const;
00085
00086 Duration operator + ( const Duration & d1 ) const;
00087
00088 Duration & operator = ( const Duration & d1 );
00089
00090 Duration & operator += ( const Duration & d1 );
00091
00092 bool operator == ( const Duration & d ) const
00093 {
00094 return ( m_sec == d.m_sec && m_nsec == d.m_nsec );
00095 }
00096
00097 bool operator != ( const Duration & d ) const
00098 {
00099 return !( *this == d );
00100 }
00101
00102 bool operator < ( const Duration & d ) const
00103 {
00104 return ( m_sec < d.m_sec ) || ( m_sec == d.m_sec && m_nsec < d.m_nsec );
00105 }
00106
00107 bool operator > ( const Duration & d ) const
00108 {
00109 return ( m_sec > d.m_sec ) || ( m_sec == d.m_sec && m_nsec > d.m_nsec );
00110 }
00111
00112 bool operator <= ( const Duration & d ) const
00113 {
00114 return !( *this > d );
00115 }
00116
00117 bool operator >= ( const Duration & d ) const
00118 {
00119 return !( *this < d );
00120 }
00121
00122
00123 time_t getSec ( ) const { return m_sec; }
00124 time_t getNsec( ) const { return m_nsec; }
00125
00126
00127 void Print() const;
00128
00129
00130
00131
00132
00133 std::string strDurationBasic() const;
00134
00135
00136
00137
00138
00139
00140
00141 void splitDurationSecsForYDHMS(time_t &Years,
00142 time_t &DaysAfterY,
00143 time_t &HoursAfterD,
00144 time_t &MinsAfterH,
00145 time_t &SecsAfterM) const;
00146
00147
00148 friend std::ostream & operator << ( std::ostream & os, const Duration & d );
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 static int parseStringToDuration( const std::string & str_dur, Duration & d );
00161
00162 private:
00163
00164
00165 time_t m_sec;
00166 time_t m_nsec;
00167
00168 };
00169 }
00170
00171 #endif // PSTIME_DURATION_H