00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __ZTime__
00026 #define __ZTime__ 1
00027 #include "zconfig.h"
00028
00029 #include "ZDebug.h"
00030 #include "ZTypes.h"
00031
00032 #include "ZCompat_operator_bool.h"
00033
00034 class ZMutex;
00035
00036
00037 #pragma mark -
00038 #pragma mark * ZTime
00039
00040 class ZTime
00041 {
00042 ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZTime, operator_bool_generator_type, operator_bool_type);
00043 public:
00044 ZTime();
00045
00046 ZTime(double iDouble) : fVal(iDouble) {}
00047
00048 ZTime& operator=(double iDouble) { fVal = iDouble; return *this; }
00049
00050 operator operator_bool_type() const;
00051
00052 bool operator<(const ZTime& iOther) const;
00053
00054 bool operator<=(const ZTime& iOther) const { return !(iOther < *this); }
00055
00056 bool operator>(const ZTime& iOther) const { return iOther < *this; }
00057
00058 bool operator>=(const ZTime& iOther) const { return !(*this < iOther); }
00059
00060 bool operator==(const ZTime& iOther) const;
00061
00062 bool operator!=(const ZTime& iOther) const { return !(*this == iOther); }
00063
00064 int Compare(const ZTime& iOther) const;
00065
00066 double operator-(const ZTime& iOther) const { return fVal - iOther.fVal; }
00067
00068 ZTime operator-(double iInterval)
00069 {
00070 ZTime result = *this;
00071 result.fVal -= iInterval;
00072 return result;
00073 }
00074
00075 ZTime& operator-=(double iInterval)
00076 { fVal -= iInterval; return *this; }
00077
00078 ZTime operator+(double iInterval) const
00079 {
00080 ZTime result = *this;
00081 result.fVal += iInterval;
00082 return result;
00083 }
00084
00085 ZTime& operator+=(double iInterval)
00086 { fVal += iInterval; return *this; }
00087
00088 static ZTime sNow();
00089 static ZTime sSystem();
00090
00091 double fVal;
00092
00093 static ZMutex sMutex;
00094
00095 static const uint32 kEpochDelta_1900_To_1904
00096 = 4U * 365 * 24 * 60 * 60;
00097
00098 static const uint32 kEpochDelta_1904_To_1970
00099 = ((66U * 365) + 17) * 24 * 60 * 60;
00100
00101 static const uint32 kEpochDelta_1900_To_1970
00102 = ((70U * 365) + 17) * 24 * 60 * 60;
00103
00104 static const uint64 kEpochDelta_1601_To_1970
00105 = ((369LLU * 365) + 89) * 24 * 60 * 60;
00106 };
00107
00108 namespace ZooLib {
00109 template <class T> int sCompare_T(const T& iL, const T& iR);
00110 template <> inline int sCompare_T(const ZTime& iL, const ZTime& iR)
00111 { return iL.Compare(iR); }
00112 }
00113
00114 #endif // __ZTime__