00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef LIBLOOKDB_LKDATETIME_H
00019 #define LIBLOOKDB_LKDATETIME_H
00020
00021
00022
00023
00024
00025
00026 #include "looktypes.h"
00027 #include "lktypebase.h"
00028
00029 #include "lkstring.h"
00030
00031 namespace look {
00032
00033
00034
00035
00036
00038
00049 class LOOKTYPES_DLL LookDate : public LookTypeBase
00050 {
00051 public:
00052
00053
00054 LookDate( unsigned long julianDate = 0UL );
00055 LookDate( const LookDate& theOther );
00056
00057 LookDate( unsigned int theDay, unsigned int theMonth, unsigned int theYear );
00058 LookDate( unsigned int theDay, const LookString& theMonth, unsigned int theYear );
00059
00060 ~LookDate( void );
00061
00062
00063 LookTypeBase* GetNewCopy( void ) const;
00064
00065
00066 long GetTypeID( void ) const;
00067
00068
00069
00070 LookDate& operator++();
00071 LookDate operator++( int );
00072
00073 LookDate& operator--();
00074 LookDate operator--( int );
00075
00076 LookDate& operator+=( long theDays );
00077 LookDate operator+( long theDays ) const;
00078
00079 LookDate& operator-=( long theDays );
00080 LookDate operator-( long theDays ) const;
00081
00082 long operator-( const LookDate& theDate ) const;
00083
00084
00085
00086 void AddMonths( int theMonths );
00087
00088
00089 bool operator==( const LookDate& theOther ) const;
00090 bool operator!=( const LookDate& theOther ) const;
00091 bool operator<( const LookDate& theOther ) const;
00092 bool operator>( const LookDate& theOther ) const;
00093 bool operator<=( const LookDate& theOther ) const;
00094 bool operator>=( const LookDate& theOther ) const;
00095
00096
00097 bool IsSet( void ) const;
00098
00099
00100 unsigned int DayOfMonth( void ) const;
00101 unsigned int Month( void ) const;
00102 unsigned int Year( void ) const;
00103
00104 unsigned int DayOfYear( void ) const;
00105
00106
00107
00108 unsigned int DayOfWeek( void ) const;
00109
00110
00111 LookString DayName( void ) const;
00112 LookString MonthName( void ) const;
00113
00114
00115
00116 LookDate Previous( unsigned int dayNumber ) const;
00117 LookDate Next( unsigned int dayNumber ) const;
00118
00119
00120
00121 bool IsLeap( void ) const;
00122
00123
00124 bool Set( LookString theDateString );
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 LookString GetString( const LookString& theSeparator = "/",
00141 const LookString& theOrder = "dmy",
00142 bool monthIsNumber = true,
00143 int yearDigits = 4 ) const;
00144
00145
00146
00147 static LookDate Now( void );
00148
00149
00150 static unsigned int DayFromName( LookString theDayName );
00151 static LookString NameFromDay( unsigned int theDayNumber );
00152 static LookString ShortNameFromDay( unsigned int theDayNumber );
00153
00154 static unsigned int MonthFromName( LookString theMonthName );
00155 static LookString NameFromMonth( unsigned int theMonthNumber );
00156 static LookString ShortNameFromMonth( unsigned int theMonthNumber );
00157
00158 static unsigned int DaysInMonth( unsigned int theMonthNumber,
00159 unsigned int theYear );
00160
00161 static bool IsLeap( unsigned int theYear );
00162
00163 static void ConvertFromJulian( unsigned long theJulianDate,
00164 unsigned int& year, unsigned int& month, unsigned int& day );
00165
00166 static unsigned long ConvertToJulian( unsigned int year,
00167 unsigned int month, unsigned int day );
00168
00169 static void SetCenturyBoundary( int theBoundary );
00170 static int GetCenturyBoundary( void );
00171
00172 protected:
00173
00175 unsigned long itsJulianDate;
00176
00178
00183 static unsigned int itsCenturyBoundary;
00184 };
00185
00186
00187
00188
00190
00195 class LOOKTYPES_DLL LookTime : public LookTypeBase
00196 {
00197 public:
00198
00199 LookTime( unsigned int theTime = 0 );
00200
00201 LookTime( unsigned int theHours, unsigned int theMinutes,
00202 unsigned int theSeconds = 0 );
00203
00204 LookTime( bool isPM, unsigned int theHours, unsigned int theMinutes = 0,
00205 unsigned int theSeconds = 0 );
00206
00207 LookTime( const LookTime& theOther );
00208
00209 ~LookTime();
00210
00211
00212 LookTypeBase* GetNewCopy( void ) const;
00213
00214
00215 long GetTypeID( void ) const;
00216
00217 LookTime& operator=( const LookTime& theOther );
00218
00219
00220 bool operator==( const LookTime& theOther ) const;
00221 bool operator!=( const LookTime& theOther ) const;
00222 bool operator<( const LookTime& theOther ) const;
00223 bool operator>( const LookTime& theOther ) const;
00224 bool operator<=( const LookTime& theOther ) const;
00225 bool operator>=( const LookTime& theOther ) const;
00226
00227
00228 LookTime& operator+=( int theChange );
00229 LookTime operator+( int theChange ) const;
00230
00231
00232 int operator-( LookTime& theOther ) const;
00233
00234
00235 LookTime operator-( int theChange ) const;
00236 LookTime& operator-=( int theChange );
00237
00238
00239
00240
00241
00242 int Normalise( void );
00243
00244 bool Set( LookString theTimeString );
00245
00246
00247 LookString GetString( const LookString& theSeparator = ":",
00248 int thePrecision = 3,
00249 bool hours24 = true ) const;
00250
00251
00252 unsigned int Hours( void ) const;
00253 unsigned int Hours12( void ) const;
00254 unsigned int Minutes( void ) const;
00255 unsigned int Seconds( void ) const;
00256 bool isPM( void ) const;
00257
00258 void SetTime( unsigned int theTime )
00259 {
00260 itsTime = theTime;
00261 }
00262
00263 unsigned int GetTime( void ) const
00264 {
00265 return itsTime;
00266 }
00267
00268
00269 static LookTime Now( void );
00270
00271 protected:
00272
00273
00275
00276 };
00277
00278
00279
00280
00282
00287 class LOOKTYPES_DLL LookDateTime : public LookTypeBase
00288 {
00289 public:
00290
00291 LookDateTime();
00292 LookDateTime( const LookDate& theDate, const LookTime& theTime = 0 );
00293
00294 LookDateTime( const LookDateTime& theOther );
00295
00296
00297 ~LookDateTime();
00298
00299
00300 LookTypeBase* GetNewCopy( void ) const;
00301
00302
00303 long GetTypeID( void ) const;
00304
00305 LookDateTime& operator=( const LookDateTime& theOther );
00306
00307
00308 bool operator==( const LookDateTime& theOther ) const;
00309 bool operator!=( const LookDateTime& theOther ) const;
00310 bool operator<( const LookDateTime& theOther ) const;
00311 bool operator>( const LookDateTime& theOther ) const;
00312 bool operator<=( const LookDateTime& theOther ) const;
00313 bool operator>=( const LookDateTime& theOther ) const;
00314
00315
00316 LookDateTime& operator+=( long theChange );
00317 LookDateTime operator+( long theChange ) const;
00318
00319
00320 long operator-( LookDateTime& theOther ) const;
00321
00322
00323 LookDateTime& operator-=( long theChange );
00324 LookDateTime operator-( long theChange ) const;
00325
00326
00327 void SetTime( const LookTime& theTime );
00328 void SetDate( const LookDate& theDate );
00329
00330 LookTime GetTime( void ) const;
00331 LookDate GetDate( void ) const;
00332
00333 bool Set( const LookString& theDateTimeString );
00334
00335
00336
00337 LookString GetString( const LookString& theDateSeparator = "/",
00338 const LookString& theOrder = "dmy",
00339 bool monthIsNumber = true,
00340 int yearDigits = 4,
00341 const LookString& theTimeSeparator = ":",
00342 int theTimePrecision = 3,
00343 bool hours24 = true ) const;
00344
00345
00346 static LookDateTime Now( void );
00347
00348 protected:
00349
00350 void Normalise( void );
00351
00353 LookDate itsDate;
00355 LookTime itsTime;
00356 };
00357
00358
00359 }
00360 #endif