00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020 #ifndef flc_timestamp_H
00021 #define flc_timestamp_H
00022
00023 #include <falcon/setup.h>
00024 #include <falcon/types.h>
00025 #include <falcon/falcondata.h>
00026 #include <falcon/time_sys.h>
00027 #include <falcon/string.h>
00028
00029 namespace Falcon {
00030
00031 class String;
00032
00038 class FALCON_DYN_CLASS TimeStamp: public FalconData
00039 {
00040 private:
00041 void rollOver( bool onlyDays = false);
00042 int16 getDaysOfMonth( int16 month = -1 ) const;
00043
00044 public:
00045
00046 int16 m_year;
00047 int16 m_month;
00048 int16 m_day;
00049 int16 m_hour;
00050 int16 m_minute;
00051 int16 m_second;
00052 int16 m_msec;
00053 TimeZone m_timezone;
00054
00055 public:
00056 TimeStamp( int16 y=0, int16 M=0, int16 d=0, int16 h=0, int16 m=0,
00057 int16 s=0, int16 ms = 0, TimeZone tz=tz_NONE ):
00058 m_year( y ),
00059 m_month( M ),
00060 m_day( d ),
00061 m_hour( h ),
00062 m_minute( m ),
00063 m_second( s ),
00064 m_msec( ms ),
00065 m_timezone( tz )
00066 {}
00067
00068 TimeStamp( const TimeStamp &ts )
00069 {
00070 copy( ts );
00071 }
00072
00073 TimeStamp( int64 lfmt )
00074 {
00075 fromLongFormat( lfmt );
00076 }
00077
00078 ~TimeStamp() {}
00079
00080 virtual void gcMark( uint32 mark ) {}
00081
00082 TimeStamp &operator = ( const TimeStamp &ts );
00083 TimeStamp &operator += ( const TimeStamp &ts )
00084 {
00085 add( ts );
00086 return *this;
00087 }
00088
00089 TimeStamp &operator -= ( const TimeStamp &ts )
00090 {
00091 distance(ts);
00092 return *this;
00093 }
00094
00101 static const char *getRFC2822_ZoneName( TimeZone tz, bool bSemantic=false, bool bDst=false );
00102
00107 static TimeZone getRFC2822_Zone( const char *csZoneName );
00108
00114 static void getTZDisplacement( TimeZone tz, int16 &hours, int16 &minutes );
00115
00119 static const char *getRFC2822_WeekDayName( int16 wd );
00120
00124 static const char *getRFC2822_MonthName( int16 wd );
00125
00129 static int16 getRFC2822_WeekDay( const char *name );
00130
00134 static int16 getRFC2822_Month( const char *name );
00135
00142 bool toRFC2822( String &target, bool bSemantic=false, bool bDst=false ) const;
00143
00149 String toRFC2822( bool bSemantic=false, bool bDst=false ) const
00150 {
00151 String temp(32);
00152 toRFC2822( temp, bSemantic, bDst );
00153 return temp;
00154 }
00155
00157 static bool fromRFC2822( TimeStamp &target, const String &source );
00159 static bool fromRFC2822( TimeStamp &target, const char *source );
00160
00162 void changeTimezone( TimeZone tz );
00163
00164 void copy( const TimeStamp &ts );
00165 void currentTime();
00166 bool isValid() const;
00167 bool isLeapYear() const;
00168 int16 dayOfYear() const;
00171 int16 dayOfWeek() const;
00172 int64 toLongFormat() const;
00173 void fromLongFormat( int64 lf );
00174 void fromSystemTime( const SystemTime &st )
00175 {
00176 Sys::Time::timestampFromSystemTime( st, *this );
00177 }
00178
00179
00180 void add( const TimeStamp &ts );
00181 void add( int32 days, int32 hours=0, int32 mins=0, int32 secs=0, int32 msecs=0 );
00182 void distance( const TimeStamp &ts );
00183 int32 compare( const TimeStamp &ts ) const;
00184 void toString( String &target ) const;
00185
00186 bool toString( String &target, const String &fmt ) const;
00187
00188 void getTZDisplacement( int16 &hours, int16 &minutes ) const;
00189
00190 bool operator ==( const TimeStamp &ts ) const { return this->compare( ts ) == 0; }
00191 bool operator !=( const TimeStamp &ts ) const { return this->compare( ts ) != 0; }
00192 bool operator <( const TimeStamp &ts ) const { return this->compare( ts ) < 0; }
00193 bool operator >( const TimeStamp &ts ) const { return this->compare( ts ) > 0; }
00194 bool operator <=( const TimeStamp &ts ) const { return this->compare( ts ) <= 0; }
00195 bool operator >=( const TimeStamp &ts ) const { return this->compare( ts ) >= 0; }
00196
00197 friend void Sys::Time::timestampFromSystemTime( const SystemTime &sys_time, TimeStamp &ts );
00198
00199 virtual FalconData *clone() const;
00200 };
00201
00202 inline TimeStamp operator + ( const TimeStamp &ts1, const TimeStamp &ts2 )
00203 {
00204 TimeStamp ts3(ts1);
00205 ts3.add( ts2 );
00206 return ts3;
00207 }
00208
00209 inline TimeStamp operator - ( const TimeStamp &ts1, const TimeStamp &ts2 )
00210 {
00211 TimeStamp ts3(ts1);
00212 ts3.distance( ts2 );
00213 return ts3;
00214 }
00215
00216 }
00217
00218 #endif
00219
00220