#include "Date.hpp"
Public Methods | |
| Date () | |
| Default constructor. | |
| Date (const Date &Orig) | |
| Copy constructor. | |
| Date (const time_t tSysTime) | |
| time_t constructor. | |
| Date (const char *String) | |
| Constructs an object from a string. | |
| Date (const int iDay, const int iMonth, const int iYear) | |
| Year/month/day constructor. | |
| int | Year (void) const |
| Returns year of the date. | |
| int | Month (void) const |
| Returns month of the date. | |
| int | Day (void) const |
| Returns month of the date. | |
| int | DayOfYear (void) const |
| Returns day of the year. | |
| int | DayOfWeek (void) const |
| Returns day of the week, starting week on Sunday. | |
| int | DayOfWorkWeek (void) const |
| Returns day of the workweek, starting week on Monday. | |
| int | IsLeapYear (void) const |
| Is this date a leap year?. | |
| void | YMD (int *pY, int *pM, int *pD) |
| Get the year, month and day values in one go. | |
| Date & | operator+= (const long Right) |
| Additive operator. | |
| Date & | operator-= (const long Right) |
| Additive operator. | |
| long | operator- (const Date &Right) |
| Operator subtracting Dates. | |
| void | ToString (char *szBuffer) const |
| Formats the Date into an ASCII representation. | |
| Date & | operator= (const Date &Orig) |
| Assignment operator. | |
| time_t | ToSysTime (void) const |
| Converts the Date to a time_t value representing midnight of that date. | |
++ and -- operator, postfix forms | |
| Date & | operator++ () |
| Date & | operator-- () |
++ and -- operators, prefix forms. | |
| Date | operator++ (int) |
| Date | operator-- (int) |
Comparison operators | |
Several comparison operators, all with the same parameter and return value. | |
| int | operator== (const Date &Right) const |
| int | operator!= (const Date &Right) const |
| int | operator< (const Date &Right) const |
| int | operator<= (const Date &Right) const |
| int | operator> (const Date &Right) const |
| int | operator>= (const Date &Right) const |
Static Public Methods | |
| int | IsLeapYear (const int iYear) |
| Check if a year is a leapyear. | |
Friends | |
| Date | operator+ (const Date &Left, const long Right) |
| Additive operator. | |
| Date | operator+ (const long Left, const Date &Right) |
| Additive operator. | |
| Date | operator- (const Date &Left, const long Right) |
| Subtract operator. | |
| Date | operator- (const long Left, const Date &Right) |
| Subtract operator. | |
Date conversion routines by Eric bergman-Terrell, Computer Language, Dec 1990. Alternate method by David Burki, CUJ Feb 1993. Use #define JULDATE_USE_ALTERNATE_METHOD to select a method.
Adding two Dates is not defined.
Definition at line 14 of file Date.hpp.
|
|
Default constructor. Constructs a new object initialized to 1 Jan 4713BC
Definition at line 95 of file Date.hpp.
00095 { lJulianDay = 0L; }
|
|
|
Copy constructor.
Definition at line 104 of file Date.hpp. References lJulianDay.
00104 { lJulianDay = Orig.lJulianDay; }
|
|
|
time_t constructor. Constructs an object initialized to the date represented by a system time value.
Definition at line 115 of file Date.hpp.
00116 {
00117 struct tm *ptm;
00118 int y, m, d;
00119
00120 ptm = localtime( &tSysTime );
00121 y = ptm->tm_year + 1900;
00122 m = ptm->tm_mon + 1;
00123 d = ptm->tm_mday;
00124 lJulianDay = YmdToJd( y, m, d );
00125 }
|
|
|
Constructs an object from a string.
Definition at line 134 of file Date.hpp.
00135 {
00136 lJulianDay = atol( String );
00137 }
|
|
||||||||||||||||
|
Year/month/day constructor. Constructs a Date initialized by the arguments.
Definition at line 150 of file Date.hpp.
00151 {
00152 lJulianDay = YmdToJd( iYear, iMonth, iDay );
00153 }
|
|
|
Returns month of the date.
Definition at line 189 of file Date.hpp.
00190 {
00191 int y, m, d;
00192
00193 JdToYmd( lJulianDay, &y, &m, &d );
00194 return d;
00195 }
|
|
|
Returns day of the week, starting week on Sunday. matching localtime()'s convention
Definition at line 209 of file Date.hpp.
00210 {
00211 return ( ( ( (int) ( lJulianDay % 7L ) ) + 1 ) % 7 );
00212 }
|
|
|
Returns day of the workweek, starting week on Monday.
Definition at line 222 of file Date.hpp.
00223 {
00224 return ( (int) ( lJulianDay % 7L ) );
00225 }
|
|
|
Returns day of the year.
Definition at line 211 of file Date.cpp.
00212 {
00213 int y, m, d;
00214 long soy;
00215
00216 JdToYmd( lJulianDay, &y, &m, &d );
00217 soy = YmdToJd( y, 1, 1 );
00218 return (int) ( lJulianDay - soy + 1 );
00219 }
|
|
|
Is this date a leap year?.
Definition at line 234 of file Date.hpp.
00235 {
00236 int y, m, d;
00237 JdToYmd( lJulianDay, &y, &m, &d );
00238 return IsLeapYear( y );
00239 }
|
|
|
Check if a year is a leapyear.
Definition at line 80 of file Date.hpp.
00081 {
00082 long jd1, jd2;
00083 jd1 = YmdToJd( iYear, 2, 29 );
00084 jd2 = YmdToJd( iYear, 3, 1 );
00085 return (int) ( jd2 - jd1 );
00086 }
|
|
|
Returns month of the date.
Definition at line 175 of file Date.hpp.
00176 {
00177 int y, m, d;
00178
00179 JdToYmd( lJulianDay, &y, &m, &d );
00180 return m;
00181 }
|
|
|
Definition at line 394 of file Date.hpp.
00395 {
00396 Date Temp = *this;
00397 lJulianDay++;
00398 return Temp;
00399 }
|
|
|
Definition at line 374 of file Date.hpp.
00375 {
00376 lJulianDay++;
00377 return *this;
00378 }
|
|
|
Additive operator.
Definition at line 334 of file Date.hpp.
00335 {
00336 Add( Right );
00337 return *this;
00338 }
|
|
|
Operator subtracting Dates.
Definition at line 361 of file Date.hpp. References lJulianDay.
00362 {
00363 return lJulianDay - Right.lJulianDay;
00364 }
|
|
|
Additive operator.
Definition at line 347 of file Date.hpp.
00348 {
00349 Subtract( Right );
00350 return *this;
00351 }
|
|
|
Assignment operator.
Definition at line 418 of file Date.hpp. References lJulianDay.
00419 {
00420 lJulianDay = Orig.lJulianDay;
00421 return *this;
00422 }
|
|
|
Definition at line 435 of file Date.hpp. References lJulianDay.
00436 {
00437 return lJulianDay == Right.lJulianDay;
00438 }
|
|
|
Formats the Date into an ASCII representation. This is the ASCII form of the long Julian day number. The string is a fixed-length 12-character string, including the NUL terminator.
Definition at line 186 of file Date.cpp.
00187 {
00188 int i;
00189 long Temp;
00190
00191 Temp = lJulianDay;
00192 if ( Temp < 0L )
00193 szBuffer[0] = '-';
00194 else
00195 szBuffer[0] = '+';
00196 szBuffer[11] = '\0';
00197 for ( i = 10; i > 0; i-- )
00198 {
00199 szBuffer[i] = ( Temp % 10L ) + '0';
00200 Temp /= 10;
00201 }
00202
00203 return;
00204 }
|
|
|
Converts the Date to a time_t value representing midnight of that date.
Definition at line 226 of file Date.cpp.
00227 {
00228 struct tm tmRep;
00229 int y, m, d;
00230 time_t t;
00231
00232 JdToYmd( lJulianDay, &y, &m, &d );
00233 if ( y < 1970 )
00234 {
00235 y = 70;
00236 m = 1;
00237 d = 1;
00238 }
00239 tmRep.tm_year = y - 1900 ;
00240 tmRep.tm_mon = m-1;
00241 tmRep.tm_mday = d;
00242 tmRep.tm_hour = 0;
00243 tmRep.tm_min = 0;
00244 tmRep.tm_sec = 0;
00245 tmRep.tm_isdst = 0;
00246
00247 t = mktime( &tmRep );
00248 return t;
00249 }
|
|
|
Returns year of the date.
Definition at line 161 of file Date.hpp.
00162 {
00163 int y, m, d;
00164
00165 JdToYmd( lJulianDay, &y, &m, &d );
00166 return y;
00167 }
|
|
||||||||||||||||
|
Get the year, month and day values in one go. Puts the year, month and day values directly into three integer variables, for times when you need all three at the same time.
Definition at line 252 of file Date.hpp.
00253 {
00254 JdToYmd( lJulianDay, pY, pM, pD );
00255 return;
00256 }
|
|
||||||||||||
|
Additive operator.
Definition at line 285 of file Date.hpp.
|
|
||||||||||||
|
Additive operator.
Definition at line 268 of file Date.hpp.
|
|
||||||||||||
|
Subtract operator.
Definition at line 319 of file Date.hpp.
|
|
||||||||||||
|
Subtract operator.
Definition at line 302 of file Date.hpp.
|
1.3-rc2