home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / tfield / tdate.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-24  |  20.5 KB  |  945 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       tdate.cpp                                 */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TDate  member functions                   */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision Extensions -- Version 1.1.1                */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Portions Copyright (c) 1991 by Borland International    */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*    TV Extensions are Copyright (c) 1992 by Michael Bonner  */
  17. /*    These extensions may be freely used by any programmer   */
  18. /*    including royalty free inclusion in any commercial      */
  19. /*    application, but any commercial rights to the source    */
  20. /*    code or object files of the Extensions are reserved.    */
  21. /*                                                            */
  22. /*    This class is derived from the DATECL.ZIP from the C++    
  23.       library of compuserves BPROGB forum.                   
  24.       Author.......: Chris Hill & Eric Simon
  25.       Copyright....: None. Use freely.
  26.       Version......: 3.10
  27.       Usage........: General purpose date conversion, arithmetic, comparison,
  28.       .............:         and formatting class
  29.   
  30.       Acknowledgements:
  31.   
  32.       Originally inspired by Steve Marcus (CIS 72007,1233) 6/16/91
  33.       Enhanced by Eric Simon (CIS 70540,1522) 6/29/91
  34.       Further Enhanced by Chris Hill (CIS 72030,2606) 7/11/91
  35.       Still Further Enhanced by Hill & Simon 8/05/91
  36. --------------------------------------------------------------*/
  37.  
  38. #define Uses_TDate
  39. #include "tfield.h"
  40.  
  41. const char *dayname[] = {"Sunday","Monday","Tuesday","Wednesday",
  42.         "Thursday","Friday","Saturday"} ;
  43.  
  44. const char *mname[] = {"January","February","March","April","May",
  45.         "June","July","August","September","October","November","December"};
  46.  
  47. ////////////////////////////////////////////////////////////
  48. // TParser Routines
  49. ////////////////////////////////////////////////////////////
  50. // extract words from string and insert them in collection
  51. //
  52. // TODO: Optimize this routine!
  53. //
  54. void TParser::parse( char *line )
  55.     {
  56.     char *curr;
  57.     char *first;
  58.  
  59.     char temp[2];
  60.  
  61.     char wstr[maxLine];
  62.     char ch = EOS;
  63.     Boolean inword;
  64.  
  65.     curr = first = line;
  66.     inword = False;
  67.  
  68.     while( (ch = *curr) != EOS )
  69.         {
  70.         if( inword )
  71.             {
  72.             if ( isgraph( ch ) )
  73.                 {
  74.                 if (strchr( "/-.", ch))
  75.                     {
  76.                     inword = False;
  77.                     strncpy( wstr, first, size_t(curr - first + 1) );
  78.                     wstr[size_t(curr-first + 1)]=EOS;
  79.                     insert( newStr( wstr ) );
  80.                     };
  81.                 }
  82.             else
  83.                 {
  84.                 inword = False;
  85.                 strncpy( wstr, first, size_t(curr - first) );
  86.                 wstr[size_t(curr-first)]=EOS;
  87.                 insert( newStr( wstr ) );
  88.                 };
  89.             }
  90.         else
  91.             {
  92.             if ( isgraph( ch ) )
  93.                 {
  94.                 inword = True;
  95.                 first = curr;
  96.                 };
  97.             }
  98.         curr++;
  99.         }
  100.  
  101.     if( inword )
  102.         // grab last word if final char before null is alfa-num
  103.         {
  104.         strncpy( wstr, first, size_t(curr - first) );
  105.         wstr[size_t(curr-first)]=EOS;
  106.         insert( newStr( wstr ));
  107.         }
  108.     }
  109.  
  110.  
  111. ////////////////////////////////////////////////////////////
  112. // TDate Constructors
  113. ////////////////////////////////////////////////////////////
  114.  
  115. int TDate::displayFormat=MDY;
  116. unsigned char TDate::displayOptions='\0';
  117.  
  118. TDate::TDate()
  119.     {
  120.     tdate_month = tdate_day = tdate_year = julian = day_of_week = 0;
  121.     }
  122.  
  123. TDate::TDate (const long aJulDate, const long offset) :
  124.     julian(aJulDate + offset)
  125.     {
  126.     if (julian != 0)
  127.         julian_to_mdy ();
  128.     else
  129.         tdate_month = tdate_day = tdate_year = day_of_week = 0;
  130.     }
  131.  
  132. TDate::TDate (const int m, const int d, const int y) :
  133.     tdate_month(m),
  134.     tdate_day(d),
  135.     tdate_year(y)
  136.     {
  137.     mdy_to_julian ();
  138.     }
  139.  
  140. TDate::TDate (char *dat)
  141.     {
  142.     setDate( dat );
  143.     }
  144.  
  145. TDate::TDate (const date &ds)
  146.     {
  147.     tdate_month = ds.da_mon;
  148.     tdate_day   = ds.da_day;
  149.     tdate_year  = ds.da_year;
  150.     mdy_to_julian ();
  151.     }
  152.  
  153. TDate::TDate (const TDate &dt)
  154.     {
  155.     tdate_month = dt.tdate_month;
  156.     tdate_day = dt.tdate_day;
  157.     tdate_year  = dt.tdate_year;
  158.     mdy_to_julian ();
  159.     displayFormat = dt.displayFormat;
  160.     displayOptions = dt.displayOptions;
  161.     }
  162.  
  163. //////////////////////////////////////////////////////////////
  164. // TDate Arithmetic
  165. //////////////////////////////////////////////////////////////
  166.  
  167. TDate TDate::operator + (const long i)
  168.     {
  169.     return TDate(julian + i);
  170.     }
  171.  
  172. TDate TDate::operator - (const long i)
  173.     {
  174.     return TDate(julian - i);
  175.     }
  176.  
  177. long TDate::operator - (const TDate &dt)
  178.     {
  179.     return ( julian - dt.julian );
  180.     }
  181.  
  182. TDate &TDate::operator += (const long i)
  183.     {
  184.     julian += i;
  185.     julian_to_mdy();
  186.     return *this;
  187.     }
  188.  
  189. TDate &TDate::operator -= (const long i)
  190.     {
  191.     julian -= i;
  192.     julian_to_mdy();
  193.     return *this;
  194.     }
  195.  
  196. TDate &TDate::operator ++ ( void ) // pre increment
  197.     {
  198.     julian++;
  199.     julian_to_mdy();
  200.     return *this;
  201.     }
  202.  
  203. #pragma argsused
  204. TDate &TDate::operator ++ ( int aDummyNumber ) // post increment
  205.     {
  206.     julian++;
  207.     julian_to_mdy();
  208.     return *this;
  209.     }
  210.  
  211. TDate &TDate::operator -- ( void ) // pre decrement
  212.     {
  213.     julian--;
  214.     julian_to_mdy();
  215.     return *this;
  216.     }
  217.  
  218. #pragma argsused
  219. TDate &TDate::operator -- ( int aDummyNumber ) // post decrement
  220.     {
  221.     julian--;
  222.     julian_to_mdy();
  223.     return *this;
  224.     }
  225.  
  226. //////////////////////////////////////////////////////////////
  227. // TDate comparison
  228. //////////////////////////////////////////////////////////////
  229.  
  230. int operator <  (const TDate &dt1, const TDate &dt2)
  231.     {
  232.     return ( dt1.julian < dt2.julian );
  233.     }
  234.  
  235. int operator <= (const TDate &dt1, const TDate &dt2)
  236.     {
  237.     return ( (dt1.julian == dt2.julian) || (dt1.julian < dt2.julian) );
  238.     }
  239.  
  240. int operator >  (const TDate &dt1, const TDate &dt2)
  241.     {
  242.     return ( dt1.julian > dt2.julian );
  243.     }
  244.  
  245. int operator >= (const TDate &dt1, const TDate &dt2)
  246.     {
  247.     return ( (dt1.julian == dt2.julian) || (dt1.julian > dt2.julian) );
  248.     }
  249.  
  250. int operator == (const TDate &dt1, const TDate &dt2)
  251.     {
  252.     return ( dt1.julian == dt2.julian );
  253.     }
  254.  
  255. int operator != (const TDate &dt1, const TDate &dt2)
  256.     {
  257.     return ( dt1.julian != dt2.julian );
  258.     }
  259.  
  260. ////////////////////////////////////////////////////////////////
  261. // Ostream operations
  262. ////////////////////////////////////////////////////////////////
  263.  
  264. ostream &operator << (ostream &os, const TDate &dt)
  265.     {
  266.     return os << dt.formatDate(MDY);
  267.     }
  268.  
  269. ostream &operator << (ostream &os, const date &dt)
  270.     {
  271.     return os << (int)dt.da_mon << "/" << (int)dt.da_day << "/" << dt.da_year;
  272.     }
  273.  
  274. //////////////////////////////////////////////////////////////
  275. // Conversion routines
  276. //////////////////////////////////////////////////////////////
  277.  
  278. int TDate::char_to_month ( const char *charMonth )
  279.     {
  280.     // Convert charMonth to a numeric month value
  281.     // Checks only first 2 or 3 characters for a match
  282.     // JA FE MAR AP MAY JUN JUL AU SE OC NO DE
  283.  
  284.     int retMonth = 0;    // 0 returned for invalid month name
  285.  
  286.     if (strlen(charMonth) > 0 )
  287.         {
  288.         char *upperMonth = strupr( strdup(charMonth) );
  289.  
  290.         switch (upperMonth[0])
  291.             {
  292.  
  293.             case 'A':
  294.                 if (upperMonth[1] == 'P')
  295.                     retMonth = 4;
  296.                 if (upperMonth[1] == 'U')
  297.                     retMonth = 8;
  298.                 break;
  299.  
  300.             case 'D':
  301.                 if (upperMonth[1] == 'E')
  302.                     retMonth = 12;
  303.                 break;
  304.  
  305.             case 'F':
  306.                 if (upperMonth[1] == 'E')
  307.                     retMonth = 2;
  308.                 break;
  309.  
  310.             case 'J':
  311.                 if (upperMonth[1] == 'A')
  312.                     retMonth = 1;
  313.                 else {
  314.                     if ( upperMonth[1] == 'U' ) {
  315.                         if (upperMonth[2] == 'N')
  316.                             retMonth = 6;
  317.                         if (upperMonth[2] == 'L')
  318.                             retMonth = 7;
  319.                     };
  320.                 };
  321.                 break;
  322.  
  323.             case 'M':
  324.                 if (upperMonth[1] == 'A')
  325.                     {
  326.                     if (upperMonth[2] == 'R')
  327.                         retMonth = 3;
  328.                     if (upperMonth[2] == 'Y')
  329.                         retMonth = 5;
  330.                     };
  331.                 break;
  332.  
  333.             case 'N':
  334.                 if (upperMonth[1] == 'O')
  335.                     retMonth = 11;
  336.                 break;
  337.  
  338.             case 'O':
  339.                 if (upperMonth[1] == 'C')
  340.                     retMonth = 10;
  341.                 break;
  342.  
  343.             case 'S':
  344.                 if (upperMonth[1] == 'E')
  345.                     retMonth = 9;
  346.                 break;
  347.  
  348.             };
  349.         };
  350.  
  351.     return retMonth;    // 1 - 12 for valid month name, otherwise 0
  352.  
  353.     }
  354.  
  355. void TDate::julian_to_wday (void)
  356.     {
  357.     day_of_week = (int) ((julian + 2) % 7 + 1);
  358.     }
  359.  
  360. void TDate::julian_to_mdy (void)
  361.     {
  362.     long a,b,c,d,e,z,alpha;
  363.     z = julian+1;
  364.     // dealing with Gregorian calendar reform
  365.     if (z < 2299161L)
  366.          a = z;
  367.     else
  368.         {
  369.         alpha = (long) ((z-1867216.25) / 36524.25);
  370.         a = z + 1 + alpha - alpha/4;
  371.         }
  372.     b = ( a > 1721423 ? a + 1524 : a + 1158 );
  373.     c = (long) ((b - 122.1) / 365.25);
  374.     d = (long) (365.25 * c);
  375.     e = (long) ((b - d) / 30.6001);
  376.     tdate_day = (int) b - d - (long)(30.6001 * e);
  377.     tdate_month = (int) (e < 13.5) ? e - 1 : e - 13;
  378.     tdate_year = (int) (tdate_month > 2.5 ) ? (c - 4716) : c - 4715;
  379.     julian_to_wday ();
  380.     }
  381.  
  382. void TDate::mdy_to_julian (void)
  383.     {
  384.     int a,b=0;
  385.     int work_month=tdate_month, work_day=tdate_day, work_year=tdate_year;
  386.     // correct for negative year
  387.     if (work_year < 0)
  388.         work_year++;
  389.     if (work_month <= 2)
  390.         { work_year--; work_month +=12; }
  391.  
  392.     // deal with Gregorian calendar
  393.     if (work_year*10000. + work_month*100. + work_day >= 15821015.)
  394.         {
  395.         a = work_year/100.;
  396.         b = 2 - a + a/4;
  397.         }
  398.     julian = (long) (365.25*work_year) +
  399.              (long) (30.6001 * (work_month+1))  +  work_day + 1720994L + b;
  400.     julian_to_wday ();
  401.     }
  402.  
  403. ////////////////////////////////////////////////////////////////
  404. // Format routine
  405. ////////////////////////////////////////////////////////////////
  406.  
  407. char *TDate::formatDate (int type) const
  408.     {
  409.     char buf[40];
  410.     strnset( buf, '\0', sizeof(buf) );
  411.  
  412.     if ( type == -1 )
  413.         type = displayFormat;
  414.  
  415.     switch ( type )
  416.         {
  417.         case DAY:
  418.             if ( (day_of_week < 1) || (day_of_week > 7) )
  419.                 strcpy(buf,"invalid day");
  420.             else
  421.                 strncpy( buf, dayname[day_of_week-1],
  422.                     (displayOptions & DATE_ABBR) ? ABBR_LENGTH : 9);
  423.             break;
  424.  
  425.         case MONTH:
  426.             if ( (tdate_month < 1) || (tdate_month > 12) )
  427.                 strcpy(buf,"invalid month");
  428.             else
  429.                 strncpy( buf, mname[tdate_month-1],
  430.                     (displayOptions & DATE_ABBR) ? ABBR_LENGTH : 9);
  431.             break;
  432.  
  433.         case FULL:
  434.             if ( (tdate_month < 1) || (tdate_month > 12) || (day_of_week < 0) ||
  435.                  (day_of_week > 7) )
  436.                 {
  437.                 strcpy(buf,"invalid date");
  438.                 }
  439.             else
  440.                 {
  441.                 strncpy( buf, dayname[day_of_week-1],
  442.                     (displayOptions & DATE_ABBR) ? ABBR_LENGTH : 9);
  443.                 strcat( buf, ", ");
  444.                 strncat( buf, mname[tdate_month-1],
  445.                     (displayOptions & DATE_ABBR) ? ABBR_LENGTH : 9);
  446.                 strcat( buf, " ");
  447.                 sprintf( buf+strlen(buf), "%d, %d", tdate_day, abs(tdate_year) );
  448.                 if (tdate_year < 0)
  449.                     strcat(buf," B.C.E.");
  450.                 }
  451.             break;
  452.  
  453.         case EUROPEAN:
  454.             if ( (tdate_month < 1) || (tdate_month > 12) || (day_of_week < 0) ||
  455.                  (day_of_week > 7) )
  456.                 {
  457.                 strcpy(buf,"invalid date");
  458.                 }
  459.             else
  460.                 {
  461.                 sprintf(buf,"%d ",    tdate_day);
  462.                 strncat(buf, mname[tdate_month-1],
  463.                     (displayOptions & DATE_ABBR) ? ABBR_LENGTH : 9);
  464.                 sprintf( buf+strlen(buf), " %d", abs(tdate_year) );
  465.                 if (tdate_year < 0)
  466.                     strcat(buf," B.C.E.");
  467.                 }
  468.             break;
  469.  
  470.         case MDY:
  471.         default:
  472.             if (tdate_day==0 || tdate_month==0 || tdate_year==0)
  473.                 strcpy(buf,"invalid date");
  474.             else
  475.                 sprintf( buf+strlen(buf), "%d/%d/%d", tdate_month, tdate_day,
  476.                     (displayOptions & NO_CENTURY) && (abs(tdate_year) > 1899)
  477.                     ? (abs(tdate_year) - (abs(tdate_year) / 100 * 100))
  478.                     : (abs(tdate_year))  );
  479.             break;
  480.         }
  481.  
  482.     return newStr(buf);
  483.     }
  484.  
  485.  
  486. void TDate::setFormat( const int format )
  487.     {
  488.     displayFormat = format;
  489.     }
  490.  
  491. int TDate::setOption( const int option, const int action )
  492.     {
  493.     int retval = 0; // holds the return value
  494.  
  495.     switch ( option )
  496.         {
  497.         case NO_CENTURY:
  498.             if ( action )
  499.                 displayOptions |= NO_CENTURY;
  500.             else
  501.                 {
  502.                 displayOptions &= (~NO_CENTURY);
  503.                 }
  504.             retval = 1;
  505.             break;
  506.         case DATE_ABBR:
  507.             if ( action )
  508.                 displayOptions |= DATE_ABBR;
  509.             else
  510.                 {
  511.                 displayOptions &= (~DATE_ABBR);
  512.                 }
  513.             retval = 1;
  514.             break;
  515.         default:
  516.             retval = 0;
  517.             break;
  518.         }
  519.     return retval;
  520.     }
  521.  
  522. ////////////////////////////////////////////////////////////////
  523. // Date Setting Routines
  524. ////////////////////////////////////////////////////////////////
  525. //
  526. // TODO: Optimize this routine!
  527. //
  528. int TDate::setDate( const char *charDate )
  529.     {
  530.     int success = 0;
  531.     char workDate[maxLine];
  532.     strncpy( workDate, charDate, maxLine );
  533.  
  534.     char *temp;
  535.  
  536.     int tempvalue;
  537.     tempvalue = 0;
  538.  
  539.     struct date temp_date;
  540.  
  541.     // Handle the "TODAY" option
  542.     if (     (!stricmp(charDate, "TODAY")) ||
  543.             ((strlen(charDate) == 1) && (charDate[0] == '*'))    )
  544.         {
  545.         getdate(&temp_date);
  546.  
  547.         tdate_month = temp_date.da_mon;
  548.         tdate_day   = temp_date.da_day;
  549.         tdate_year  = temp_date.da_year;
  550.  
  551.         success = 1;
  552.         };
  553.  
  554.     // Handle the empty string possibility
  555.     if ( charDate[0] == '\0' )
  556.         {
  557.         tdate_month = tdate_day = tdate_year = julian = day_of_week = 0;
  558.  
  559.         success = 1; // not really, but we don't want the parse routine to get this
  560.         };
  561.  
  562.     if (success == 0)
  563.         {
  564.         tdate_month = tdate_day = tdate_year = 0;
  565.  
  566.         TParser *datetokens = new TParser( 5, 5 );
  567.         // in production code, check lowMemory here
  568.  
  569.         // parse the date
  570.         datetokens->parse( workDate );
  571.  
  572.         if( datetokens->getCount() > 0 )
  573.             {
  574.             // check for alpha tokens
  575.             for ( int i = 0; i < datetokens->getCount(); i++ )
  576.                 {
  577.                 temp = (char *) datetokens->at( i );
  578.                 if ( isalpha(temp[0]) )
  579.                     {
  580.                     if (tdate_month == 0)
  581.                         tdate_month = char_to_month( temp );
  582.                     if (tdate_month > 0)
  583.                         {
  584.                         datetokens->atFree( i );
  585.                         break;
  586.                         };
  587.                     };
  588.                 };
  589.  
  590.             // check for numeric tokens
  591.             for ( i = 0; i < datetokens->getCount(); i++ )
  592.                 {
  593.                 temp = (char *) datetokens->at( i );
  594.                 if ( !isalpha(temp[0]) )
  595.                     {
  596.                     tempvalue = atoi(temp);
  597.                     switch (temp[strlen(temp) - 1])
  598.                         {
  599.                         case ',':
  600.                             if (     (tdate_day == 0) &&
  601.                                     (tempvalue > 0) &&
  602.                                     (tempvalue < 32) )
  603.                                 {
  604.                                 tdate_day = tempvalue;
  605.                                 }
  606.                             else
  607.                                 if (    (tdate_month == 0) &&
  608.                                         (tempvalue > 0) &&
  609.                                         (tempvalue < 13) )
  610.                                     {
  611.                                     tdate_month = tempvalue;
  612.                                     }
  613.                                 else
  614.                                     if (tdate_year == 0)
  615.                                         {
  616.                                         if (temp[0] == '0')
  617.                                             {
  618.                                             tdate_year = tempvalue;
  619.                                             }
  620.                                         else
  621.                                             {
  622.                                             if (    (tempvalue > 0) &&
  623.                                                     (tempvalue < 100) )
  624.                                                 {
  625.                                                 getdate(&temp_date);
  626.                                                 tdate_year = temp_date.da_year - (temp_date.da_year % 100) + tempvalue;
  627.                                                 }
  628.                                             else
  629.                                                 {
  630.                                                 tdate_year = tempvalue;
  631.                                                 };
  632.                                             };
  633.                                         };
  634.  
  635.                             break;
  636.  
  637.                         case '/':
  638.                         case '.':
  639.                         case '-':
  640.                             if (    (tdate_month == 0) &&
  641.                                     (tempvalue > 0) &&
  642.                                     (tempvalue < 13) )
  643.                                 {
  644.                                 tdate_month = tempvalue;
  645.                                 }
  646.                             else
  647.                                 if (    (tdate_day == 0) &&
  648.                                         (tempvalue > 0 ) &&
  649.                                         (tempvalue < 32) )
  650.                                     {
  651.                                     tdate_day = tempvalue;
  652.                                     }
  653.                                 else
  654.                                     if (tdate_year == 0)
  655.                                         {
  656.                                         if (temp[0] == '0')
  657.                                             {
  658.                                             tdate_year = tempvalue;
  659.                                             }
  660.                                         else
  661.                                             {
  662.                                             if (    (tempvalue > 0) &&
  663.                                                     (tempvalue < 100) )
  664.                                                 {
  665.                                                 getdate(&temp_date);
  666.                                                 tdate_year = temp_date.da_year - (temp_date.da_year % 100) + tempvalue;
  667.                                                 }
  668.                                             else
  669.                                                 {
  670.                                                 tdate_year = tempvalue;
  671.                                                 };
  672.                                             };
  673.                                         };
  674.                             break;
  675.  
  676.                         default:
  677.                             if (    (tdate_month == 0) &&
  678.                                     (tempvalue > 0) &&
  679.                                     (tempvalue < 13) )
  680.                                 {
  681.                                 tdate_month = tempvalue;
  682.                                 }
  683.                             else
  684.                                 if (    (tdate_day == 0) &&
  685.                                         (tempvalue > 0) &&
  686.                                         (tempvalue < 32) )
  687.                                     {
  688.                                     tdate_day = tempvalue;
  689.                                     }
  690.                                 else
  691.                                     if (tdate_year == 0)
  692.                                         {
  693.                                         if (temp[0] == '0')
  694.                                             {
  695.                                             tdate_year = tempvalue;
  696.                                             }
  697.                                         else
  698.                                             {
  699.                                             if (    (tempvalue > 0) &&
  700.                                                     (tempvalue < 100) )
  701.                                                 {
  702.                                                 getdate(&temp_date);
  703.                                                 tdate_year = temp_date.da_year - (temp_date.da_year % 100) + tempvalue;
  704.                                                 }
  705.                                             else
  706.                                                 {
  707.                                                 tdate_year = tempvalue;
  708.                                                 };
  709.                                             };
  710.                                         };
  711.  
  712.                             break;
  713.                         };
  714.                     };
  715.                 };
  716.             datetokens->freeAll();
  717.             TParser::destroy(datetokens);
  718.             };
  719.  
  720.         if (    (tdate_month > 0) &&
  721.                 (tdate_day > 0 ) &&
  722.                 (tdate_year == 0) )
  723.             {
  724.             getdate(&temp_date);
  725.             tdate_year = temp_date.da_year;
  726.             };
  727.  
  728.         if (    (tdate_month > 0) &&
  729.                 (tdate_day == 0) &&
  730.                 (tdate_year > 0) )
  731.             {
  732.             tdate_day = 1;
  733.             };
  734.  
  735.         if (    (tdate_month > 0) &&
  736.                 (tdate_day > 0) &&
  737.                 (tdate_year != 0) )
  738.             success = 1;
  739.         };
  740.  
  741.     // validate the date
  742.     if (tdate_day > 0)
  743.         switch (tdate_month)
  744.         {
  745.             case 1:
  746.             case 3:
  747.             case 5:
  748.             case 7:
  749.             case 8:
  750.             case 10:
  751.             case 12:
  752.                 if (tdate_day > 31)
  753.                     success = tdate_month = tdate_day = tdate_year = 0;
  754.                 break;
  755.  
  756.             case 4:
  757.             case 6:
  758.             case 9:
  759.             case 11:
  760.                 if (tdate_day > 30)
  761.                     success = tdate_month = tdate_day = tdate_year = 0;
  762.                 break;
  763.  
  764.             case 2:
  765.                 if ( tdate_day > (isLeapYear() ? 29 : 28) )
  766.                     success = tdate_month = tdate_day = tdate_year = 0;
  767.                 break;
  768.  
  769.             default:
  770.                 success = tdate_month = tdate_day = tdate_year = 0;
  771.                 break;
  772.         }
  773.     else
  774.         success = tdate_month = tdate_day = tdate_year = 0;
  775.  
  776.     if (success != 0)
  777.         mdy_to_julian ();
  778.  
  779.     return success;
  780.     }
  781.  
  782. int TDate::setDate( const long aJulDate, const long offset)
  783.     {
  784.     julian = aJulDate + offset;
  785.     julian_to_mdy();
  786.  
  787.     return 1;
  788.     }
  789.  
  790. void TDate::incrMonth(void)
  791.     {
  792.     if (tdate_month < 12)
  793.         tdate_month++;
  794.     else
  795.         {
  796.         tdate_month = 1;
  797.         tdate_year++;
  798.         };
  799.  
  800.     // validate the date
  801.     switch (tdate_month)
  802.         {
  803.         case 4:
  804.         case 6:
  805.         case 9:
  806.         case 11:
  807.             if (tdate_day > 30)
  808.                 tdate_day = 30;
  809.             break;
  810.         case 2:
  811.             if ( tdate_day > (isLeapYear() ? 29 : 28) )
  812.                 tdate_day = (isLeapYear() ? 29: 28);
  813.             break;
  814.         };
  815.  
  816.     mdy_to_julian ();
  817.  
  818.     }
  819.  
  820. void TDate::decrMonth(void)
  821.     {
  822.     if (tdate_month > 1)
  823.         tdate_month--;
  824.     else
  825.         {
  826.         tdate_month = 12;
  827.         tdate_year--;
  828.         };
  829.  
  830.     // validate the date
  831.     switch (tdate_month)
  832.         {
  833.         case 4:
  834.         case 6:
  835.         case 9:
  836.         case 11:
  837.             if (tdate_day > 30)
  838.                 tdate_day = 30;
  839.             break;
  840.         case 2:
  841.             if ( tdate_day > (isLeapYear() ? 29 : 28) )
  842.                 tdate_day = (isLeapYear() ? 29: 28);
  843.             break;
  844.         };
  845.  
  846.     mdy_to_julian ();
  847.  
  848.     }
  849.  
  850. void TDate::incrYear(void)
  851.     {
  852.     tdate_year++;
  853.  
  854.     // validate the date
  855.     if (tdate_month == 2)
  856.         if ( tdate_day > (isLeapYear() ? 29 : 28) )
  857.             tdate_day = (isLeapYear() ? 29: 28);
  858.  
  859.     mdy_to_julian ();
  860.     }
  861.  
  862. void TDate::decrYear(void)
  863.     {
  864.     tdate_year--;
  865.  
  866.     // validate the date
  867.     if (tdate_month == 2)
  868.         if ( tdate_day > (isLeapYear() ? 29 : 28) )
  869.             tdate_day = (isLeapYear() ? 29: 28);
  870.  
  871.     mdy_to_julian ();
  872.     }
  873.  
  874. ///////////////////////////////////////////////////////////////
  875. //  Miscellaneous Routines
  876. ///////////////////////////////////////////////////////////////
  877.  
  878. long TDate::julDate( void ) const
  879.     {
  880.     return julian;
  881.     }
  882.  
  883. long TDate::PXDate( void ) const
  884.     {
  885.     return julian - PXOffset;
  886.     }
  887.  
  888. int TDate::day( void ) const
  889.     {
  890.     return tdate_day;
  891.     }
  892.  
  893. int TDate::dow( void ) const
  894.     {
  895.     return day_of_week;
  896.     }
  897.  
  898. int TDate::month( void ) const
  899.     {
  900.     return tdate_month;
  901.     }
  902.  
  903. int TDate::year( void ) const
  904.     {
  905.     return tdate_year;
  906.     }
  907.  
  908. int TDate::dayOfYear( void ) const
  909.     {
  910.     TDate temp( 1, 1, tdate_year );
  911.  
  912.     return (int) (julian - temp.julian + 1);
  913.     }
  914.  
  915.  
  916. int TDate::isLeapYear( void ) const
  917.     {
  918.     return  ( (tdate_year >= 1582) ?
  919.               (tdate_year % 4 == 0  &&  tdate_year % 100 != 0  ||  tdate_year % 400 == 0 ):
  920.               (tdate_year % 4 == 0) );
  921.     }
  922.  
  923. date TDate::eom( void ) const
  924.     {
  925.     date eom_temp;
  926.     TDate tempdate( (tdate_month % 12) + 1, 1, tdate_year);
  927.     if (tdate_month == 12)
  928.         tempdate.tdate_year++;
  929.     --tempdate;
  930.  
  931.     eom_temp.da_year  = tempdate.tdate_year;
  932.     eom_temp.da_mon   = tempdate.tdate_month;
  933.     eom_temp.da_day   = tempdate.tdate_day;
  934.  
  935.     return eom_temp;
  936.     }
  937.  
  938. date TDate::getDate( void ) const
  939.     {
  940.     date getDate_temp;
  941.     getDate_temp.da_year  = tdate_year;
  942.     getDate_temp.da_mon   = tdate_month;
  943.     getDate_temp.da_day   = tdate_day;
  944.     return getDate_temp;
  945.     }