00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __GZ_TIME_H__
00023 #define __GZ_TIME_H__
00024
00029 #include "gzBase.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00051 class GZ_BASE_EXPORT gzTime
00052 {
00053 public:
00054
00055 gzTime();
00056
00057 gzTime( gzDouble seconds );
00058
00059 gzTime( gzULong year , gzUByte month , gzUByte day , gzDouble dayseconds=0 );
00060
00061 gzTime( gzULong year , gzUByte month , gzUByte day , gzDouble hour , gzDouble minute , gzDouble second);
00062
00063 gzDouble seconds() const;
00064
00065 gzULong year() const;
00066
00067 gzUByte month() const;
00068
00069 gzUByte day() const;
00070
00071 gzDouble daySeconds() const;
00072
00073 gzUByte hour() const;
00074
00075 gzUByte minute() const;
00076
00077 gzDouble hourSeconds() const;
00078
00079 gzString asString(const gzString &format="%4d-%02d-%02d %02d:%02d:%02d") const;
00080
00082 static gzTime now(gzBool localTime=FALSE);
00083
00084 static gzVoid setTime(gzDouble time,gzBool localTime=FALSE);
00085
00086 static gzDouble systemSeconds(gzULong threadID=0);
00087
00088 static gzDouble getLocalTimeOffset();
00089
00090 static gzUShort daysPerYear(gzULong year);
00091
00092 static gzUByte daysPerMonth(gzUByte month,gzULong year);
00093
00094 static gzVoid useCPUSpeedCheck(gzBool on=FALSE,gzULong threadID=0);
00095 static gzVoid useHighSpeedClock(gzBool on=FALSE,gzULong threadID=0);
00096
00097 static gzVoid clearThreadData(gzULong threadID=0);
00098
00099 gzDouble operator -(const gzTime &time) const;
00100 gzDouble operator +(const gzTime &time) const;
00101 gzDouble operator -(const gzDouble &sec) const;
00102 gzDouble operator +(const gzDouble &sec) const;
00103
00104 gzBool operator<(const gzTime &time) const;
00105 gzBool operator<=(const gzTime &time) const;
00106 gzBool operator>(const gzTime &time) const;
00107 gzBool operator>=(const gzTime &time) const;
00108 gzBool operator!=(const gzTime &time) const;
00109 gzBool operator==(const gzTime &time) const;
00110
00111 private:
00112
00113 gzDouble m_seconds;
00114 gzBool m_hasDayseconds;
00115 gzDouble m_daySeconds;
00116
00117 static gzDouble s_systemTimeOffset;
00118 };
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00136 class gzTimer : public gzNameInterface
00137 {
00138 public:
00139
00140 GZ_BASE_EXPORT gzTimer(const gzString &name=GZ_EMPTY_STRING):gzNameInterface(name)
00141 {
00142 m_resetTime=gzTime::systemSeconds();
00143 }
00144
00145 GZ_BASE_EXPORT gzVoid reset()
00146 {
00147 m_resetTime=gzTime::systemSeconds();
00148 }
00149
00150 GZ_BASE_EXPORT gzDouble getTime()
00151 {
00152 return gzTime::systemSeconds()-m_resetTime;
00153 }
00154
00155 GZ_BASE_EXPORT gzVoid notifyTime(const gzDouble &minTime=0.0)
00156 {
00157 gzDouble diff(gzTime::systemSeconds()-m_resetTime);
00158
00159 if(diff>=minTime)
00160 GZMESSAGE(GZ_MESSAGE_DEBUG,"--- GZ_TIMER '%s' Time: %g Freq: %g ---",(const char *)getName(),diff,1.0/(diff));
00161 }
00162
00163 private:
00164 gzDouble m_resetTime;
00165 };
00166 #endif // __GZ_TIME_H__
00167