home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / KDC46.ZIP / DATEDEMO.CPP < prev    next >
Text File  |  1993-08-04  |  10KB  |  273 lines

  1. #include "datecl.h"
  2. #include <malloc.h>
  3. #include <iostream.h>
  4.  
  5. ////////////////////////////////////////////////////////////
  6. //    main for testing purposes only...
  7. ////////////////////////////////////////////////////////////
  8.  
  9. void test()
  10. {
  11.     cout << " Date Class v4.0 Demo \n\n";
  12.  
  13.     // Various versions of the constructors
  14.     // and various output
  15.  
  16.     Date x(10,20,1962);
  17.     cout << x.formatDate(Date::FULL) << "\n";
  18.  
  19.     // constuctor with a string, just printing the day of the week
  20.     Date y="8/8/1988";
  21.     cout << y.formatDate(Date::DAY) << "\n";
  22.  
  23.     // constructor with a julian
  24.     Date z( 2450000L );
  25.     cout << z.formatDate(Date::FULL) << '\n';
  26.  
  27.     // using date addition and subtraction
  28.     Date a = x + 10;
  29.     cout << a.formatDate(Date::FULL) << '\n';
  30.     a = a - 25;
  31.     cout << a.formatDate(Date::EUROPEAN) << '\n';
  32.  
  33.     //using subtraction of two date objects
  34.     Date a1 = "7/13/1991";
  35.     Date a2 = a1 + 14;
  36.     cout << (a1-a2) << "\n";
  37.     cout << (a2+=10) << "\n";
  38.  
  39.     a1++;
  40.     cout << "Tommorrow= " << a1.formatDate(Date::FULL) << "\n";
  41.  
  42.     cout << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < (Date)"08/01/1991") ? "TRUE" : "FALSE") << "\n";
  43.     cout << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > (Date)"08/01/1991") ? "TRUE" : "FALSE") << "\n";
  44.     cout << "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1==(Date)"07/14/1991") ? "TRUE" : "FALSE") << "\n";
  45.     Date a3 = a1;
  46.     cout << "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << "\n";
  47.     Date a4 = a1;
  48.     cout << "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1==++a4) ? "TRUE" : "FALSE") << "\n";
  49.  
  50.     Date a5 = "today";
  51.     cout << "Today is: " << a5 << "\n";
  52.     a4 = "Today";
  53.     cout << "Today (a4) is: " << a4 << "\n";
  54.  
  55.     cout << "Today + 4 is: " << (a4+=4) << "\n";
  56.     a4 = "Today";
  57.     cout << "Today - 4 is: " << (a4-=4) << "\n";
  58.  
  59.     cout << "=========== Leap Year Test ===========\n";
  60.     a1 = "1/15/1992";
  61.     cout << a1.formatDate(Date::FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
  62.     cout << "\t" << "day of year:  " << a1.DOY() << "\n";
  63.  
  64.     a1 = "2/16/1993";
  65.     cout << a1.formatDate(Date::FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
  66.     cout << "\t" << "day of year:  " << a1.DOY() << "\n";
  67.  
  68.     DOSDATE_T b0 = {15,02,1991,1};
  69.     Date b1 = b0;
  70.     cout << "=========== eom test ==============\n";
  71.     cout << "b1.eom() (s/b 2/28/91) ==> " << b1.eom() << "\n";
  72.  
  73.     cout << "================== getDate test =====================\n";
  74.     DOSDATE_T ds = a1.getDate();
  75.     cout << "a1.getDate()  (s/b 2/16/1993) ==> " << ds << "\n";
  76.  
  77.     cout << "================== string assignment test ====================\n";
  78.     char *date_string=a1;
  79.     cout << "a1 as a string (s/b 2/16/1993) ==> " << date_string << "\n";
  80.  
  81.     cout << "================== setFormat test ============================\n";
  82.     Date::setFormat(Date::FULL);
  83.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  84.     Date::setFormat(Date::EUROPEAN);
  85.     cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
  86.  
  87.     cout << "================== setOption test ============================\n";
  88.     cout << "Date abbreviation ON\n";
  89.     Date::setOption(Date::DATE_ABBR);
  90.     Date::setFormat(Date::MONTH);
  91.     cout << "a1 (s/b MONTH format) ==> " << a1 << "\n";
  92.     Date::setFormat(Date::DAY);
  93.     cout << "a1 (s/b DAY format) ==> " << a1 << "\n";
  94.     Date::setFormat(Date::FULL);
  95.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  96.     Date::setFormat(Date::EUROPEAN);
  97.     cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
  98.     cout << "Century suppression ON\n";
  99.     Date::setOption(Date::NO_CENTURY);
  100.     Date::setFormat(Date::MDY);
  101.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  102.     cout << "Century suppression OFF\n";
  103.     Date::setOption(Date::NO_CENTURY,Date::OFF);
  104.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  105.     cout << "Century suppression ON\n";
  106.     Date::setOption(Date::NO_CENTURY);
  107.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  108.     Date::setFormat(Date::FULL);
  109.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  110.     Date::setOption(Date::DATE_ABBR,Date::OFF);
  111.  
  112.     cout << "\n=============== Version 4.0 Enhancement Test =================\n";
  113.     
  114.     Date v4("11/26/1966");
  115.     cout << "\n---------- Set Stuff -----------\n";
  116.     cout << "First, 'Set' to today..." << "\n";
  117.     cout << "Before 'Set' => " << v4 << "\n";
  118.     cout << "After  'Set' => " << v4.Set() << "\n\n";
  119.  
  120.     cout << "Set to 11/26/66 => " << v4.Set(11,26,1966) << "\n";
  121.     cout << "Current Julian  => " << v4.julDate() << "\n";
  122.     cout << "Set to Julian 2450000L => " << v4.Set(2450000L) << "\n";
  123.     cout << "See! => " << v4.julDate() << "\n";
  124.  
  125.     cout << "---------- Add Stuff -----------\n";
  126.     cout << "Start => " << v4.Set() << "\n";
  127.     cout << "Add  4 Weeks  => " << v4.AddWeeks(4)    << "\n";
  128.     cout << "Sub 52 Weeks  => " << v4.AddWeeks(-52)  << "\n";
  129.     cout << "Add 21 Months => " << v4.AddMonths(21)  << "\n";
  130.     cout << "Sub 15 Months => " << v4.AddMonths(-15) << "\n";
  131.     cout << "Add  2 Years  => " << v4.AddYears(2)    << "\n";
  132.  
  133.     cout << "---------- Misc Stuff -----------\n";
  134.     cout << "The date aboves' day of the month is => " << v4.Day() << "\n";
  135.     cout << "There are " << v4.DaysInMonth() << " days in this month.\n";
  136.     cout << "The first day of this month lands on " << v4.FirstDOM() << "\n";
  137.     cout << "This day happens to be " << v4.CDOW() << "\n";
  138.     cout << "the " << v4.NDOW() << " day of the week," << "\n";
  139.     cout << "on the " << v4.WOY() << " week of the year," << "\n";
  140.     cout << "on the " << v4.WOM() << " week of the month, " << "\n";
  141.     cout << "(which is " << v4.CMonth() << ")\n";
  142.     cout << "the "<< v4.NMonth() << "nth month in the year.\n";
  143.     cout << "The year alone is " << v4.NYear4() << "\n";
  144.  
  145.     cout << "---------- First and Last Stuff -----------\n";
  146.     v4.Set();
  147.     cout << "The first date of this month is " << v4.BOM() << "\n";
  148.     cout << "The last date of this month is " << v4.EOM() << "\n";
  149.     cout << "The first date of this year is " << v4.BOY() << "\n";
  150.     cout << "The last date of this year is " << v4.EOY() << "\n";
  151.     cout << "\n";
  152.  
  153.     cout << "\n=============== Version 4.2 Enhancement Test =================\n";
  154.     // TML - Memory test
  155.     #ifdef _MSC
  156.         cout << "*** Starting Memory " << (unsigned long) _memavl() << "\n";
  157.     #else
  158.         cout << "*** Starting Memory " << (unsigned long) farcoreleft() << "\n";
  159.     #endif
  160.  
  161.     Date *d1 = new Date("04/13/1967");
  162.     cout << "*d1  = " << d1->formatDate(Date::FULL) << "\n\n";
  163.  
  164.     cout << "---------- Postfix '++' test -----------\n";
  165.     cout << "(*d1)++ + 1= " << ((*d1)++ + 1).formatDate(Date::FULL) << "\n";
  166.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  167.     cout << "(*d1)++    = " << ((*d1)++).formatDate(Date::FULL) << "\n";
  168.     cout << "(*d1) should now be (04/15/1967): " << (*d1) << "\n";
  169.  
  170.     cout << "---------- Postfix '--' test -----------\n";
  171.     cout << "(*d1)-- + 1= " << ((*d1)-- + 1).formatDate(Date::FULL) << "\n";
  172.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  173.     cout << "(*d1)--    = " << ((*d1)--).formatDate(Date::FULL) << "\n";
  174.     cout << "(*d1) should now be (04/13/1967): " << (*d1) << "\n";
  175.  
  176.     cout << "---------- Prefix '++' test -----------\n";
  177.     cout << "++(*d1) + 1= " << (++(*d1) + 1).formatDate(Date::FULL) << "\n";
  178.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  179.     cout << "++(*d1)    = " << ++(*d1) << "\n";
  180.     cout << "(*d1) should now be (04/15/1967): " << (*d1) << "\n";
  181.  
  182.     cout << "---------- Prefix '--' test -----------\n";
  183.     cout << "--(*d1) + 1= " << (--(*d1) + 1).formatDate(Date::FULL) << "\n";
  184.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  185.     cout << "--(*d1)    = " << --(*d1) << "\n";
  186.     cout << "(*d1) should now be (04/13/1967): " << (*d1) << "\n";
  187.  
  188.     cout << "---------- Testing the () operator -----------\n";
  189.     Date *d2=new Date;
  190.     cout << "d2's initial value: " << *d2 << "\n";
  191.     cout << "d1's current's buf: " << *d1 << "\n";
  192.  
  193.     d2->Set();
  194.     cout << "d2's value after 'Set()': " << *d2 << "\n";
  195.  
  196.     delete d2;
  197.     delete d1;
  198.  
  199.     cout << "\n=============== Version 4.3 Enhancement Test =================\n";
  200.     cout << "-------------- Testing BCE dates -------------\n";
  201.     Date d4="1/1/0";
  202.  
  203.     cout << "D4 (1/1/0)       = " << d4 << "\n";
  204.     cout << "D4 - 150 years   = " << d4.AddYears(-150) << "\n";
  205.     cout << "D4 + 150 years   = " << d4.AddYears(150) << "\n";
  206.  
  207.     cout << "--------- Testing String Assignment ----------\n";
  208.  
  209.     d4 = "23 March 1993";
  210.     d4.setFormat(Date::EUROPEAN);
  211.     cout << "EUROPEAN         : " << d4 << "\n";
  212.  
  213.     d4 = "3/23/1993";
  214.     d4.setFormat(Date::MDY);
  215.     cout << "MDY              : " << d4 << "\n";
  216.  
  217.     d4 = "Tuesday, March 23, 1993";
  218.     d4.setFormat(Date::FULL);
  219.     cout << "FULL             : " << d4 << "\n";
  220.  
  221.     d4 = "Tue, Mar 23, 1993";
  222.     d4.setOption(Date::DATE_ABBR);
  223.     cout << "FULL,ABBR.       : " << d4 << "\n";
  224.     cout << "\n";
  225.     d4.setOption(Date::DATE_ABBR, Date::OFF);
  226.  
  227.     d4 = "23 March 1993 B.C.E.";
  228.     d4.setFormat(Date::EUROPEAN);
  229.     cout << "EUROPEAN   B.C.E.: " << d4 << "\n";
  230.  
  231.     d4 = "Tuesday, March 23, 1993 B.C.E.";
  232.     d4.setFormat(Date::FULL);
  233.     cout << "FULL       B.C.E.: " << d4 << "\n";
  234.  
  235.     d4 = "Tue, Mar 23, 1993 B.C.E.";
  236.     d4.setOption(Date::DATE_ABBR);
  237.     cout << "FULL,ABBR. B.C.E.: " << d4 << "\n";
  238.     cout << "\n\n";
  239.  
  240.     #ifdef _MSC
  241.         cout << "*** Ending Memory " << (unsigned long) _memavl() << "\n\n";
  242.     #else
  243.         cout << "*** Ending Memory " << (unsigned long) coreleft() << "\n\n";
  244.     #endif
  245. }
  246.  
  247.  
  248. void main()
  249. {
  250.     unsigned long t1, t2;
  251.  
  252.     for (int i = 1; i < 2; i++)
  253.     {
  254.         cout << "*** Starting Program Memory " ;
  255.         #ifdef _MSC
  256.             cout << (t1=(unsigned long) _memavl()) << "\n";
  257.         #else
  258.             cout << (t1=(unsigned long) coreleft()) << "\n";
  259.         #endif
  260.  
  261.         test();
  262.  
  263.         cout << "*** Ending Program Memory ";
  264.         #ifdef _MSC
  265.             cout << (t2=(unsigned long) _memavl()) << "\n";
  266.         #else
  267.             cout << (t2=(unsigned long) coreleft()) << "\n";
  268.         #endif
  269.  
  270.         cout << "\nProgram Memory Difference: " << (long)(t2 - t1) << "\n\n\n\n";
  271.     }
  272. };
  273.