home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snpd9707.zip / DATEDEMO.CPP < prev    next >
Text File  |  1997-07-05  |  8KB  |  215 lines

  1. .I 0 1
  2. // +++Date last modified: 05-Jul-1997
  3. .D 1 1
  4. .I 19 12
  5.       switch( phase ){
  6.             case zDate::new_moon: stream << "new"; break;
  7.             case zDate::waxing_crescent: stream << "waxing crescent"; break;
  8.             case zDate::first_quater: stream << "first quater"; break;
  9.             case zDate::waxing_gibbous: stream << "waxing gibbous"; break;
  10.             case zDate::full_moon: stream << "full"; break;
  11.             case zDate::waning_gibbous: stream << "waning gibbous"; break;
  12.             case zDate::third_quater: stream << "third quater"; break;
  13.             case zDate::waning_crescent: stream << "waning crescent"; break;
  14.             default: stream << "--error--"; break;
  15.       }
  16.       return stream;
  17. .D 20 12
  18. .I 35 2
  19.       stream << date.Day() << "-" << (int)date.Month() << "-" << date.Year();
  20.       return stream;
  21. .D 36 2
  22. .I 41 191
  23.       switch( day ){
  24.             case zDate::sun: stream << "Sunday"; break;
  25.             case zDate::mon: stream << "Monday"; break;
  26.             case zDate::tue: stream << "Tuesday"; break;
  27.             case zDate::wed: stream << "Wednesday"; break;
  28.             case zDate::thu: stream << "Thursday"; break;
  29.             case zDate::fri: stream << "Friday"; break;
  30.             case zDate::sat: stream << "Saturday"; break;
  31.             default        : stream << "--error--"; break;
  32.       }
  33.       return stream;
  34. }
  35.  
  36. void test()
  37. {
  38.       cout << " zDate Class Demo \n\n";
  39.  
  40.       // default constructor, Jan 1 0000
  41.       zDate a;
  42.       cout << a << endl;
  43.       // Various versions of the constructors
  44.       zDate x(zDate::oct,20,1962);
  45.       cout << x << endl;
  46.       // constructor with a julian
  47.       zDate z( 2450000L );
  48.       cout << z << endl;
  49.       // make a date with system date (tests copy constructor)
  50.       zDate s(zDate::Today());
  51.       cout << s << endl;
  52.       // init with the day of year
  53.       zDate y(33, 1996);
  54.       cout << y << endl;
  55.       // init from current system time
  56.       time_t secs_now = time(NULL);
  57.       zDate n(localtime(&secs_now));
  58.       cout << n << endl;
  59.  
  60.       // using date addition and subtraction
  61.       zDate adder = x + 10;
  62.       cout << adder << endl;
  63.       adder = adder - 25;
  64.       cout << adder << endl;
  65.  
  66.       //using subtraction of two date objects
  67.       zDate a1(zDate::Today());
  68.       zDate a2 = a1 + 14;
  69.       cout << (a1 - a2) << endl;
  70.       cout << (a2 += 10) << endl;
  71.  
  72.       a1++;
  73.       cout << "Tommorrow= " << a1 << endl;
  74.  
  75.       a1 = zDate(zDate::jul, 14, 1991);
  76.       cout << "a1 (7-14-91) < a2 (" << a2
  77.              << ")? ==> " << ((a1 < a2) ? "TRUE" : "FALSE") << endl;
  78.       cout << "a1 (7-14-91) > a2 ("<< a2
  79.              << ")? ==> " << ((a1 > a2) ? "TRUE" : "FALSE") << endl;
  80.       cout << "a1 (7-14-91) < 8-01-91 ? ==> "
  81.              << ((a1 < zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl;
  82.       cout << "a1 (7-14-91) > 8-01-91 ? ==> "
  83.              << ((a1 > zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl;
  84.       cout << "a1 (7-14-91) == 7-14-91 ? ==> "
  85.              << ((a1==zDate(zDate::jul, 14, 1991)) ? "TRUE" : "FALSE") << endl;
  86.       zDate a3 = a1;
  87.  
  88.       cout << "a1 (" << a1 << ") == a3 (" << a3
  89.              << ") ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << endl;
  90.       zDate a4 = a1;
  91.       ++a4;
  92.       cout << "a1 ("<< a1 <<") == a4 (" << a4
  93.              << ") ? ==> " << ((a1==a4) ? "TRUE" : "FALSE") << endl;
  94.  
  95.       zDate a5(zDate::Today());
  96.       cout << "Today is: " << a5 << endl;
  97.       a4 = zDate::Today();
  98.       cout << "Today (a4) is: " << a4 << endl;
  99.  
  100.       cout << "Today + 4 is: " << (a4 += 4) << endl;
  101.       a4 = zDate::Today();
  102.       cout << "Today - 4 is: " << (a4 -= 4) << endl;
  103.       cout << "=========== Leap Year Test ===========\n";
  104.       a1 = zDate(zDate::jan, 15, 1992);
  105.       cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
  106.       cout << "\t" << "day of year:  " << a1.DayOfYear() << endl;
  107.  
  108.       a1 = zDate(zDate::feb, 16, 1993);
  109.       cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap");
  110.       cout << "\t" << "day of year:  " << a1.DayOfYear() << endl;
  111.  
  112.       zDate v4(zDate::Today());
  113.       cout << "---------- Add Stuff -----------\n";
  114.       cout << "Start => " << v4 << endl;
  115.       cout << "Add  4 Weeks  => " << v4.AddWeeks(4) << endl;
  116.       cout << "Sub 52 Weeks  => " << v4.AddWeeks(-52)  << endl;
  117.       cout << "Add  2 Years  => " << v4.AddYears(2)    << endl;
  118.  
  119.       cout << flush;
  120.  
  121.       cout << "---------- Misc Stuff -----------\n";
  122.       cout << "The date aboves' day of the month is => " << v4.Day() << endl;
  123.       cout << "There are " << v4.DaysInMonth() << " days in this month.\n";
  124.       cout << "This day happens to be " << v4.DayOfWeek() << " day of week" << endl;
  125.       cout << "on the " << v4.WeekOfYear() << " week of the year," << endl;
  126.       cout << "on the " << v4.WeekOfMonth() << " week of the month, " << endl;
  127.       cout << "which is the "<< (int)v4.Month() << "nth month in the year.\n";
  128.       cout << "The year alone is " << v4.Year() << endl;
  129.       cout << "And this is the " << v4.DayOfYear() << " day of year" << endl;
  130.       cout << "of a year with " << v4.DaysInYear() << " days in it" << endl;
  131.       cout << "which makes exatcly " << v4.WeeksInYear() << " weeks" << endl;
  132.  
  133.       zDate birthday(zDate::jul, 16, 1973);
  134.       cout << "The age test: i was born on " << birthday
  135.              << " which makes me " << v4.Age(birthday) << " years old" << endl;
  136.  
  137.       zDate       D2(zDate::jul, 4, 1776);
  138.       int         I1 = 4;
  139.  
  140.       cout << "Before: I1 = " << I1 << ",  D2 = " << D2 << endl;
  141.       cout << "---------- Postfix '++' test -----------\n";
  142.       cout << "Test : I1++ = " << I1++ << ",  D2++ = " << D2++ << endl;
  143.       cout << "After: I1   = " << I1 << ",  D2   = " << D2 << endl;
  144.  
  145.       cout << "---------- Prefix '++' test -----------\n";
  146.       cout << "Test : ++I1 = " << ++I1 << ",  ++D2 = " << ++D2 << endl;
  147.       cout << "After:   I1 = " << I1 << ",    D2 = " << D2 << endl;
  148.  
  149.       cout << "---------- Postfix '--' test -----------\n";
  150.       cout << "Test : I1-- = " << I1-- << ",  D2-- = " << D2-- << endl;
  151.       cout << "After: I1   = " << I1 << ",  D2   = " << D2 << endl;
  152.  
  153.       cout << "---------- Prefix '--' test -----------\n";
  154.       cout << "Test : --I1 = " << --I1 << ",  --D2 = " << --D2 << endl;
  155.       cout << "After:   I1 = " << I1 << ",    D2 = " << D2 << endl;
  156.  
  157.       cout << "Last day of this year is dayno "
  158.              << zDate(zDate::dec, 31, 1996).DayOfYear() << endl;
  159.       cout << "Last day of prev year is dayno "
  160.              << zDate(zDate::dec, 31, 1995).DayOfYear() << endl;
  161.  
  162.       cout << "Today the moon is " << zDate::Today().MoonPhase() << endl;
  163.  
  164.       zDate today = zDate::Today();
  165.  
  166.       cout << "DST for " << today.Year() << " starts on " << today.BeginDST()
  167.              << " and ends on " << today.EndDST() << endl;
  168.       cout << "Today, " << today << ", DST is "
  169.              << (today.IsDST() ? "" : "not") << "in effect" << endl;
  170.  
  171.       zDate date1(zDate::aug, 31, 1996);
  172.       cout << "Adding 6 months to " << date1 << " results in "
  173.              << date1.AddMonths(6) << endl;
  174.  
  175.       zDate date2(zDate::mar, 31, 1996);
  176.       cout << "Subtracting 1 month from " << date2 << " results in "
  177.              << date2.AddMonths(-1) << endl;
  178.  
  179.       zDate date3(zDate::jul, 4, 1776);
  180.       cout << "Adding 2400 months to " << date3 << " results in "
  181.              << date3.AddMonths(2400) << endl;
  182.  
  183.       cout << "Today's day number is " << zDate::Today().DayNumber() << endl;
  184.  
  185.       zDate date4(zDate::feb, 29, 1996);
  186.       cout << date4 << " subtract two years = " << date4.AddYears(-2) << endl;
  187.  
  188.       cout << "In 1996, DST began on " << zDate::BeginDST(1996) << endl;
  189.  
  190.       zDate date5(zDate::sep, 26, 1996);
  191.       cout << "Moon phase on " << date5 << " was " << date5.MoonPhase() << endl;
  192.  
  193.       zDate date6(zDate::oct, 3, 1996);
  194.       cout << date6 << " + 55 days is " << (date6 + 55) << endl;
  195.  
  196.       zDate date7(zDate::oct, 4, 1996);
  197.       cout << date7 << " + 217 days is ";
  198.       date7 += 217;
  199.       cout << date7 << endl;
  200.       date7 = zDate(zDate::oct, 4, 1996);
  201.       cout << "Same date - (-217) days is ";
  202.       date7 -= -217;
  203.       cout << date7 << endl;
  204.  
  205.       cout << "For 1996, Easter is on " << zDate::Easter(1996) << endl;
  206. }
  207.  
  208.  
  209. void
  210. main()
  211. {
  212.       test();
  213. };
  214. .D 42 191
  215.