21 #ifndef UTP_TIMEVALUE_H
22 #define UTP_TIMEVALUE_H
24 #include <ktorrent_export.h>
25 #include <util/constants.h>
32 class KTORRENT_EXPORT TimeValue
37 TimeValue(bt::Uint64 secs, bt::Uint64 usecs);
38 TimeValue(
const TimeValue & tv);
40 TimeValue & operator = (
const TimeValue & tv);
42 bt::Uint32 timestampMicroSeconds()
const
44 bt::Uint64 microsecs = seconds * 1000000 + microseconds;
49 void addMilliSeconds(bt::Uint32 ms)
51 microseconds += ms * 1000;
52 if (microseconds > 1000000)
54 seconds += microseconds / 1000000;
55 microseconds = microseconds % 1000000;
60 bt::TimeStamp toTimeStamp()
const {
return seconds * 1000 + (bt::Uint64)microseconds * 0.001;}
64 bt::Uint64 microseconds;
69 inline bt::Int64 operator - (
const TimeValue & a,
const TimeValue & b)
71 bt::Int64 seconds = a.seconds - b.seconds;
72 bt::Int64 microseconds = a.microseconds - b.microseconds;
74 while (microseconds < 0)
76 microseconds += 1000000;
80 return (1000000LL * seconds + microseconds) / 1000;
83 inline bool operator < (
const TimeValue & a,
const TimeValue & b)
85 if (a.seconds < b.seconds)
87 else if (a.seconds == b.seconds)
88 return a.microseconds < b.microseconds;
93 inline bool operator <= (
const TimeValue & a,
const TimeValue & b)
95 if (a.seconds < b.seconds)
97 else if (a.seconds == b.seconds)
98 return a.microseconds <= b.microseconds;
105 if (a.seconds > b.seconds)
107 else if (a.seconds == b.seconds)
108 return a.microseconds > b.microseconds;
113 inline bool operator >= (
const TimeValue & a,
const TimeValue & b)
115 if (a.seconds > b.seconds)
117 else if (a.seconds == b.seconds)
118 return a.microseconds >= b.microseconds;
125 #endif // UTP_TIMEVALUE_H