home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / DATECL.ZIP / DATEDEMO.CPP < prev    next >
Text File  |  1994-01-26  |  11KB  |  277 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. // TML
  134.     cout << "Set to 08/31/93 => " << v4.Set(8,31,1993) << "\n";
  135.     cout << "Add  6 Months => " << v4.AddMonths(6)  << "\n";
  136.  
  137.     cout << "---------- Misc Stuff -----------\n";
  138.     cout << "The date aboves' day of the month is => " << v4.Day() << "\n";
  139.     cout << "There are " << v4.DaysInMonth() << " days in this month.\n";
  140.     cout << "The first day of this month lands on " << v4.FirstDOM() << "\n";
  141.     cout << "This day happens to be " << v4.CDOW() << "\n";
  142.     cout << "the " << v4.NDOW() << " day of the week," << "\n";
  143.     cout << "on the " << v4.WOY() << " week of the year," << "\n";
  144.     cout << "on the " << v4.WOM() << " week of the month, " << "\n";
  145.     cout << "(which is " << v4.CMonth() << ")\n";
  146.     cout << "the "<< v4.NMonth() << "nth month in the year.\n";
  147.     cout << "The year alone is " << v4.NYear4() << "\n";
  148.  
  149.     cout << "---------- First and Last Stuff -----------\n";
  150.     v4.Set();
  151.     cout << "The first date of this month is " << v4.BOM() << "\n";
  152.     cout << "The last date of this month is " << v4.EOM() << "\n";
  153.     cout << "The first date of this year is " << v4.BOY() << "\n";
  154.     cout << "The last date of this year is " << v4.EOY() << "\n";
  155.     cout << "\n";
  156.  
  157.     cout << "\n=============== Version 4.2 Enhancement Test =================\n";
  158.     // TML - Memory test
  159.     #ifdef _MSC
  160.         cout << "*** Starting Memory " << (unsigned long) _memavl() << "\n";
  161.     #else
  162.         cout << "*** Starting Memory " << (unsigned long) farcoreleft() << "\n";
  163.     #endif
  164.  
  165.     Date *d1 = new Date("04/13/1967");
  166.     cout << "*d1  = " << d1->formatDate(Date::FULL) << "\n\n";
  167.  
  168.     cout << "---------- Postfix '++' test -----------\n";
  169.     cout << "(*d1)++ + 1= " << ((*d1)++ + 1).formatDate(Date::FULL) << "\n";
  170.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  171.     cout << "(*d1)++    = " << ((*d1)++).formatDate(Date::FULL) << "\n";
  172.     cout << "(*d1) should now be (04/15/1967): " << (*d1) << "\n";
  173.  
  174.     cout << "---------- Postfix '--' test -----------\n";
  175.     cout << "(*d1)-- + 1= " << ((*d1)-- + 1).formatDate(Date::FULL) << "\n";
  176.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  177.     cout << "(*d1)--    = " << ((*d1)--).formatDate(Date::FULL) << "\n";
  178.     cout << "(*d1) should now be (04/13/1967): " << (*d1) << "\n";
  179.  
  180.     cout << "---------- Prefix '++' test -----------\n";
  181.     cout << "++(*d1) + 1= " << (++(*d1) + 1).formatDate(Date::FULL) << "\n";
  182.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  183.     cout << "++(*d1)    = " << ++(*d1) << "\n";
  184.     cout << "(*d1) should now be (04/15/1967): " << (*d1) << "\n";
  185.  
  186.     cout << "---------- Prefix '--' test -----------\n";
  187.     cout << "--(*d1) + 1= " << (--(*d1) + 1).formatDate(Date::FULL) << "\n";
  188.     cout << "(*d1) should now be (04/14/1967): " << (*d1) << "\n";
  189.     cout << "--(*d1)    = " << --(*d1) << "\n";
  190.     cout << "(*d1) should now be (04/13/1967): " << (*d1) << "\n";
  191.  
  192.     cout << "---------- Testing the () operator -----------\n";
  193.     Date *d2=new Date;
  194.     cout << "d2's initial value: " << *d2 << "\n";
  195.     cout << "d1's current's buf: " << *d1 << "\n";
  196.  
  197.     d2->Set();
  198.     cout << "d2's value after 'Set()': " << *d2 << "\n";
  199.  
  200.     delete d2;
  201.     delete d1;
  202.  
  203.     cout << "\n=============== Version 4.3 Enhancement Test =================\n";
  204.     cout << "-------------- Testing BCE dates -------------\n";
  205.     Date d4="1/1/0";
  206.  
  207.     cout << "D4 (1/1/0)       = " << d4 << "\n";
  208.     cout << "D4 - 150 years   = " << d4.AddYears(-150) << "\n";
  209.     cout << "D4 + 150 years   = " << d4.AddYears(150) << "\n";
  210.  
  211.     cout << "--------- Testing String Assignment ----------\n";
  212.  
  213.     d4 = "23 March 1993";
  214.     d4.setFormat(Date::EUROPEAN);
  215.     cout << "EUROPEAN         : " << d4 << "\n";
  216.  
  217.     d4 = "3/23/1993";
  218.     d4.setFormat(Date::MDY);
  219.     cout << "MDY              : " << d4 << "\n";
  220.  
  221.     d4 = "Tuesday, March 23, 1993";
  222.     d4.setFormat(Date::FULL);
  223.     cout << "FULL             : " << d4 << "\n";
  224.  
  225.     d4 = "Tue, Mar 23, 1993";
  226.     d4.setOption(Date::DATE_ABBR);
  227.     cout << "FULL,ABBR.       : " << d4 << "\n";
  228.     cout << "\n";
  229.     d4.setOption(Date::DATE_ABBR, Date::OFF);
  230.  
  231.     d4 = "23 March 1993 B.C.E.";
  232.     d4.setFormat(Date::EUROPEAN);
  233.     cout << "EUROPEAN   B.C.E.: " << d4 << "\n";
  234.  
  235.     d4 = "Tuesday, March 23, 1993 B.C.E.";
  236.     d4.setFormat(Date::FULL);
  237.     cout << "FULL       B.C.E.: " << d4 << "\n";
  238.  
  239.     d4 = "Tue, Mar 23, 1993 B.C.E.";
  240.     d4.setOption(Date::DATE_ABBR);
  241.     cout << "FULL,ABBR. B.C.E.: " << d4 << "\n";
  242.     cout << "\n\n";
  243.  
  244.     #ifdef _MSC
  245.         cout << "*** Ending Memory " << (unsigned long) _memavl() << "\n\n";
  246.     #else
  247.         cout << "*** Ending Memory " << (unsigned long) coreleft() << "\n\n";
  248.     #endif
  249. }
  250.  
  251.  
  252. void main()
  253. {
  254.     unsigned long t1, t2;
  255.  
  256.     for (int i = 1; i < 2; i++)
  257.     {
  258.         cout << "*** Starting Program Memory " ;
  259.         #ifdef _MSC
  260.             cout << (t1=(unsigned long) _memavl()) << "\n";
  261.         #else
  262.             cout << (t1=(unsigned long) coreleft()) << "\n";
  263.         #endif
  264.  
  265.         test();
  266.  
  267.         cout << "*** Ending Program Memory ";
  268.         #ifdef _MSC
  269.             cout << (t2=(unsigned long) _memavl()) << "\n";
  270.         #else
  271.             cout << (t2=(unsigned long) coreleft()) << "\n";
  272.         #endif
  273.  
  274.         cout << "\nProgram Memory Difference: " << (long)(t2 - t1) << "\n\n\n\n";
  275.     }
  276. };
  277.