00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __DATE_TIME_H__
00021 #define __DATE_TIME_H__
00022
00023 #include <time.h>
00024 #include <limits.h>
00025 #include <sys/time.h>
00026 #include <iostream>
00027 #include <string>
00028
00029 #define DIG_COUNT 1e6
00030
00031 typedef double StampType;
00032
00033 class DateTime
00034 {
00035 public:
00036 DateTime( time_t seconds = 0, suseconds_t micros = 0 );
00037 DateTime( const DateTime& right );
00038 DateTime( const StampType& right );
00039
00040 StampType Stamp() const;
00041 unsigned Seconds() const;
00042 unsigned MicroSeconds() const;
00043
00044 DateTime& operator=( const DateTime& );
00045 DateTime& operator=( const StampType& );
00046
00047 static DateTime Now();
00048 static DateTime MinValue();
00049 static DateTime MaxValue();
00050
00051 static StampType RoundStamp( const StampType& stmp );
00052
00053 friend std::ostream& operator<<( std::ostream& output, const DateTime& date );
00054 friend std::istream& operator>>( std::istream& input, DateTime& date );
00055
00056 private:
00057 time_t m_seconds;
00058 suseconds_t m_ms;
00059 };
00060
00061 bool operator==( const DateTime& lhs, const DateTime& rhs );
00062 bool operator!=( const DateTime& lhs, const DateTime& rhs );
00063 bool operator<( const DateTime& lhs, const DateTime& rhs );
00064 bool operator>( const DateTime& lhs, const DateTime& rhs );
00065 bool operator<=( const DateTime& lhs, const DateTime& rhs );
00066 bool operator>=( const DateTime& lhs, const DateTime& rhs );
00067 StampType operator-( const DateTime& lhs, const DateTime& rhs );
00068 DateTime operator+( const DateTime& lhs, const StampType& rhs );
00069
00070 #endif
00071