home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dtime / data.1 / Datetest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-08  |  44.2 KB  |  1,486 lines

  1. #include "stdafx.h"         // MFC core and standard components
  2. #include "dtime.h"          // DTime main include
  3.  
  4.  
  5.  
  6. //the test app        
  7. #if defined(_WINDOWS) || defined(_WIN32)
  8. class CApp : public CWinApp
  9. {
  10.   virtual BOOL InitInstance(); 
  11. };
  12.  
  13. //create the app
  14. CApp NEAR theApp;
  15.  
  16.  
  17. //test code goes in InitInstance under Windows or main on Dos
  18. BOOL CApp::InitInstance()
  19. {              
  20. #else
  21. int main()
  22. {
  23. #endif //defined(_WINDOWS) || defined(_WIN32)
  24.  
  25. #if defined(_WINDOWS) || defined(_WIN32)
  26.   DWORD StartTicks = GetTickCount();
  27. #else
  28.   time_t StartTime = time(NULL);  
  29. #endif  
  30.   
  31.   //initialise the DTime package
  32.   InitDTime();
  33.   InitDTimeSettings();
  34.  
  35.                     
  36.   //Set the title of the console Window
  37. #ifdef _WIN32
  38.   SetConsoleTitle(_T("Test program to exercise the DTime package"));
  39.  
  40.   //Uncomment the following line to try the german version of DTime
  41.   //SetThreadLocale(MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT));
  42.  
  43. #endif
  44.  
  45.   //Display some intro text
  46.   _tprintf(_T("This program is best used under a debugger so\n"));
  47.   _tprintf(_T("that code can be stepped into etc.\n"));
  48.   _tprintf(_T("Some calls to Dtime contained in this code is designed to cause ASSERTIONS\n"));
  49.   _tprintf(_T("<Hit Enter to continue>\n"));
  50.   int chr = getchar();
  51.  
  52.   //first some helpful information will be displayed
  53.   _tprintf(_T("\nTimezone Standard Name is currently \"%s\"\n"), CLDate::StandardName());
  54.   _tprintf(_T("Timezone Bias is currently %s\n"), (CLDate::TimezoneBias()).Format());
  55.   _tprintf(_T("Daylight Name is currently \"%s\"\n"), CLDate::DaylightName());
  56.   _tprintf(_T("Daylight Bias is currently %s\n"), (CLDate::DaylightBias()).Format());
  57.  
  58.   
  59.   //Test of the CDate class
  60.  
  61.   //first all the constructors
  62.   CDate x(1582, CDate::OCTOBER, 15);    //m_lDays = 0
  63.   x = CDate(1992, CDate::OCTOBER, 10);  //m_lDays = 149745
  64.   x = CDate(-4712, CDate::JANUARY, 1);  //m_lDays = -2299161
  65.   x = CDate(1582, CDate::OCTOBER, 4);   //m_lDays = -1;
  66.  
  67.  
  68.   //should be invalid dates, causing ASSERTs
  69.   /*
  70.   x = CDate(1582, CDate::OCTOBER, 8);
  71.   ASSERT(!x.IsValid());
  72.   x = CDate(1995, CDate::FEBRUARY, 29);
  73.   ASSERT(!x.IsValid());
  74.   x = CDate(1900, CDate::FEBRUARY, 29);
  75.   ASSERT(!x.IsValid());
  76.   x = CDate(1582, CDate::JANUARY, 32);
  77.   ASSERT(!x.IsValid());
  78.   x = CDate(1900, 13, 8);
  79.   ASSERT(!x.IsValid());
  80.   x = CDate(5879612L, 1, 1);
  81.   ASSERT(!x.IsValid());
  82.   x = CDate(5879611L, 8, 1);
  83.   ASSERT(!x.IsValid());
  84.   x = CDate(5879612L, 7, 12);
  85.   ASSERT(!x.IsValid());
  86.   */
  87.  
  88.  
  89.   //should be invalid dates and should ASSERT
  90.   /*
  91.   CDate::SetDoAsserts(TRUE);
  92.   x = CDate(1582, CDate::OCTOBER, 8);
  93.   x = CDate(1995, CDate::FEBRUARY, 29);
  94.   x = CDate(1900, CDate::FEBRUARY, 29);
  95.   x = CDate(1582, CDate::JANUARY, 32);
  96.   x = CDate(1900, 13, 8);
  97.   x = CDate(5879612L, 1, 1);
  98.   x = CDate(5879611L, 8, 1);
  99.   x = CDate(5879612L, 7, 12);
  100.   */
  101.  
  102.  
  103.   //construction using DateS structure
  104.   DateS ds;
  105.   ds.lYear = 1582;
  106.   ds.wMonth = CDate::OCTOBER;
  107.   ds.wDay = 15;
  108.   x = CDate(ds.lYear, ds.wMonth, ds.wDay);  //m_lDays = 0
  109.  
  110.  
  111.   //Construction using the Win32 SYSTEMTIME structure
  112.   SYSTEMTIME st;
  113.   st.wYear = 1582;
  114.   st.wMonth = 10;
  115.   st.wDay = 15;
  116.   x = CDate(st);
  117.  
  118.  
  119.   //Construction using the direct count of days
  120.   x = CDate(0, CDate::EPOCH_JD);    //m_lDays = -2299161
  121.   x = CDate(0, CDate::EPOCH_GREG);  //m_lDays = 0
  122.   x = CDate(0, CDate::EPOCH_MJD);   //m_lDays = 100839
  123.   x = CDate(0, CDate::EPOCH_1900);  //m_lDays = 115860
  124.   x = CDate(0, CDate::EPOCH_1950);  //m_lDays = 134122
  125.   x = CDate(0, CDate::EPOCH_CTIME); //m_lDays = 141427
  126.   x = CDate(0, CDate::EPOCH_2000);  //m_lDays = 152384
  127.   
  128.  
  129.  
  130.   //CTime Construction
  131.   CTime z(1970, 1, 2, 0, 0, 0);
  132.   x = CDate(z);  //m_lDays = 141428
  133.   CString& s = x.Format();
  134.       
  135.   //COleDateTime Construction
  136. #if defined(_WIN32)
  137.   COleDateTime dt(1992, CDate::OCTOBER, 10, 0, 0, 0);
  138.   x = CDate(dt);  //m_lDays = 149745
  139.   s = x.Format();
  140.   dt = COleDateTime(1970, 1, 2, 0, 0, 0);
  141.   x = CDate(dt);  //m_lDays = 141428
  142.   s = x.Format();
  143. #endif  
  144.  
  145.  
  146.   //Static Constructors
  147.   x = CDate::CurrentDate();
  148.   s = x.Format();
  149.   //_tprintf should be replaced by w_tprintf under _UNICODE
  150.   _tprintf(_T("The current date is %s\n"), s);
  151.   x = CDate::FirstCurrentMonth();
  152.   s = x.Format();
  153.   _tprintf(_T("The first of the current month is %s\n"), s);
  154.   x = CDate::FirstCurrentYear();
  155.   s = x.Format();
  156.   _tprintf(_T("The First of the current year is %s\n"), s);
  157.   x = CDate::LastCurrentYear();
  158.   s = x.Format();
  159.   _tprintf(_T("The last of the current year is %s\n"), s);
  160.   x = CDate::JDEpoch();
  161.   s = x.Format();
  162.   _tprintf(_T("The Julian Day Epoch is %s\n"), s);
  163.   x = CDate::MJDEpoch();
  164.   s = x.Format();
  165.   _tprintf(_T("The Modified Julian Day Epoch is %s\n"), s);
  166.   x = CDate::Epoch1900();
  167.   s = x.Format();
  168.   _tprintf(_T("The 1900 Epoch is %s\n"), s);
  169.   x = CDate::Epoch1950();
  170.   s = x.Format();
  171.   _tprintf(_T("The 1950 Epoch is %s\n"), s);
  172.   x = CDate::EpochCTime();
  173.   s = x.Format();
  174.   _tprintf(_T("The CTime Epoch is %s\n"), s);
  175.   x = CDate::Epoch2000();
  176.   s = x.Format();
  177.   _tprintf(_T("The 2000 Epoch is %s\n"), s);
  178.   x = CDate::GregorianEpoch();
  179.   s = x.Format();
  180.   _tprintf(_T("The Gregorian Epoch is %s\n"), s);
  181.  
  182.  
  183.   //Try the static operations
  184.  
  185.   ASSERT(CDate::IsLeap(2000));
  186.   ASSERT(!CDate::IsLeap(1900));
  187.   ASSERT(!CDate::IsLeap(1902));
  188.   ASSERT(CDate::IsLeap(1400));
  189.   ASSERT(CDate::IsLeap(1300));
  190.   ASSERT(!CDate::IsLeap(1302));
  191.   ASSERT(CDate::DaysInYear(2000) == 366);
  192.   ASSERT(CDate::DaysInYear(1998) == 365);
  193.   ASSERT(CDate::DaysInMonth(CDate::JANUARY, TRUE) == 31);
  194.   ASSERT(CDate::DaysInMonth(CDate::FEBRUARY, TRUE) == 29);
  195.   ASSERT(CDate::DaysInMonth(CDate::FEBRUARY, FALSE) == 28);
  196.   ASSERT(CDate::DaysInMonth(CDate::JUNE, TRUE) == 30);
  197.   ASSERT(CDate::DaysSinceJan0(CDate::JANUARY, 1, TRUE) == 1);
  198.   ASSERT(CDate::DaysSinceJan0(CDate::JANUARY, 1, FALSE) == 1);
  199.   ASSERT(CDate::DaysSinceJan0(CDate::DECEMBER, 31, TRUE) == 366);
  200.   ASSERT(CDate::DaysSinceJan0(CDate::DECEMBER, 31, FALSE) == 365);
  201.   ASSERT(CDate::DaysSinceJan0(CDate::JULY, 13, TRUE) == 195);
  202.   ASSERT(CDate::DaysSinceJan0(CDate::JULY, 13, FALSE) == 194);
  203.   ASSERT(CDate::DaysSinceJan1(CDate::DECEMBER, 31, TRUE) == 365);
  204.   ASSERT(CDate::DaysSinceJan1(CDate::DECEMBER, 31, FALSE) == 364);
  205.   ASSERT(CDate::DaysSinceJan1(CDate::JULY, 13, TRUE) == 194);
  206.   ASSERT(CDate::DaysSinceJan1(CDate::JULY, 13, FALSE) == 193);
  207.   ASSERT(CDate::DaysSinceJan1(CDate::JANUARY, 1, TRUE) == 0);
  208.   ASSERT(CDate::DaysSinceJan1(CDate::JANUARY, 1, FALSE) == 0);
  209.   
  210.   WORD m = CDate::CurrentMonth();
  211.   _tprintf(_T("The current month is %d\n"), m);
  212.  
  213.   WORD d = CDate::CurrentDay();
  214.   _tprintf(_T("The current day is %d\n"), d);
  215.  
  216.   long y = CDate::CurrentYear();
  217.   _tprintf(_T("The current year is %ld\n"), y);
  218.  
  219.   WORD dow = CDate::CurrentDayOfWeek();
  220.   _tprintf(_T("The current day of week is %d\n"), dow);
  221.  
  222.  
  223.   //is it possible to have only 3 of a weekday in a month
  224.   //Construction using the WeekOfMonth parameter
  225.   x = CDate(1995, 9, 3, CDate::FRIDAY);
  226.   ASSERT(x == CDate(1995, 9, 15));
  227.   x = CDate(1995, 9, 1, CDate::SATURDAY);
  228.   ASSERT(x == CDate(1995, 9, 2));
  229.   x = CDate(1995, 9, 1, CDate::TUESDAY);
  230.   ASSERT(x == CDate(1995, 9, 5));
  231.   x = CDate(1995, 9, 5, CDate::SUNDAY);
  232.   ASSERT(x == CDate(1995, 9, 24));
  233.   x = CDate(1995, 9, 5, CDate::FRIDAY);
  234.   ASSERT(x == CDate(1995, 9, 29));
  235.  
  236.  
  237.  
  238.  
  239.   //Testing static holiday constructors
  240.  
  241.   //some of these will need at least 2 day tests
  242.  
  243.   x = CDate::NewYearsDay();
  244.   s = x.Format();
  245.   _tprintf(_T("New Years Day occurs on %s this year\n"), s);
  246.  
  247.   x = CDate::ValentinesDay();
  248.   s = x.Format();
  249.   _tprintf(_T("Valentines Day occurs on %s this year\n"), s);
  250.  
  251.   x = CDate::StPatricksDay();
  252.   s = x.Format();
  253.   _tprintf(_T("St Patricks Day occurs on %s this year\n"), s);
  254.  
  255.   x = CDate::AshWednesday();
  256.   s = x.Format();
  257.   _tprintf(_T("Ash Wednesday occurs on %s this year\n"), s);
  258.  
  259.   x = CDate::GoodFriday();
  260.   s = x.Format();
  261.   _tprintf(_T("Good Friday occurs on %s this year\n"), s);
  262.  
  263.   x = CDate::EasterSunday();
  264.   s = x.Format();
  265.   _tprintf(_T("Easter Sunday occurs on %s this year\n"), s);
  266.  
  267.   x = CDate::CanadaDay();
  268.   s = x.Format();
  269.   _tprintf(_T("Canada Day occurs on %s this year\n"), s);
  270.  
  271.   x = CDate::IndependenceDay();
  272.   s = x.Format();
  273.   _tprintf(_T("American Independence Day occurs on %s this year\n"), s);
  274.  
  275.   x = CDate::BastilleDay();
  276.   s = x.Format();
  277.   _tprintf(_T("Bastille Day occurs on %s this year\n"), s);
  278.  
  279.   x = CDate::ChristmasDay();
  280.   s = x.Format();
  281.   _tprintf(_T("Christmas Day occurs on %s this year\n"), s);
  282.  
  283.   
  284.   //test the range of the class
  285.  
  286.   /*
  287.   CDate::SetEndJulianCalendar(1752, 8, 10);
  288.   CDate::SetBeginGregCalendar(1752, 8, 20);
  289.   */
  290.   
  291.  
  292.   
  293.   long StartYear = 1700;
  294.   long EndYear = 5000;
  295.  
  296.   /*  //Uncomment if you want to perform a full range check on CDate's construction routines
  297.   _tprintf(_T("\n\nNow going to construct a CDate for all dates\n"));
  298.   _tprintf(_T("between the years %ld and %ld\n"), StartYear, EndYear);
  299.   _tprintf(_T("This may take a while\n"));
  300.   _tprintf(_T("<Hit Enter to continue>\n"));
  301.   chr = getchar();
  302.   DWORD StartTime = GetTickCount();
  303.  
  304.   for (long Year = StartYear; Year < EndYear; Year++)
  305.   {
  306.     if (Year % 10 == 0)
  307.        _tprintf(_T("Testing Year %ld\n"), Year);
  308.     for (WORD Month = CDate::JANUARY; Month <= CDate::DECEMBER; Month++)
  309.     {
  310.       for (WORD Day = 1; Day <= CDate::DaysInMonth(Month, CDate::IsLeap(Year)); Day++)
  311.       {
  312.         x = CDate(Year, Month, Day);
  313.         if (x.IsValid())
  314.         {
  315.           DateS ds = x.GetDate();
  316.           if ((ds.lYear != Year) || (ds.wMonth != Month) || (ds.wDay != Day))
  317.           {
  318.             s = x.Format();
  319.             _tprintf(_T("Error occured testing %s\n"), s);
  320.           }
  321.         }
  322.       }
  323.     }
  324.   }
  325.  
  326.   DWORD EndTime = GetTickCount();
  327.   DWORD SecondsTaken = (EndTime - StartTime)/1000;
  328.   _tprintf(_T("The time taken for the validity test was %ld seconds\n"), SecondsTaken);
  329.   _tprintf(_T("Or about %ld seconds for 1000 years\n"), (SecondsTaken*1000)/(EndYear - StartYear));
  330.   _tprintf(_T("<Hit Enter to continue>\n"));
  331.   chr = getchar();
  332.   */
  333.  
  334.  
  335.  
  336.   //change the time when the gregorian Calendar comes into action
  337.  
  338.   //for the moment , the values will be changed to match some known values
  339.   /*
  340.   x = CDate(50000, 1, 30);
  341.   s = x.Format();
  342.   _tprintf(_T("%s (NS) Gregorian Day Number is ", s);
  343.   _tprintf(_T("%ld\n"), x.JD());
  344.   CDate::SetEndJulianCalendar(x.GetYear()+1, 8, 10);
  345.   CDate::SetBeginGregCalendar(x.GetYear()+1, 8, 20);
  346.   x = CDate(50000, 1, 30);
  347.   s = x.Format();
  348.   _tprintf(_T("%s (OS) Gregorian Day Number is ", s);
  349.   _tprintf(_T("%ld\n"), x.JD());
  350.   */
  351.  
  352.  
  353.   //try out the accessors for the end of Julian and
  354.   //begin of Gregorian dates
  355.   ds = CDate::GetEndJulianCalendar();
  356.   CDate EndJulian(ds.lYear, ds.wMonth, ds.wDay);
  357.   s = EndJulian.Format();
  358.   _tprintf(_T("The End of the Julian calendar occurs on %s\n"), s);
  359.   ds = CDate::GetBeginGregCalendar();
  360.   CDate BeginGreg(ds.lYear, ds.wMonth, ds.wDay);
  361.   s = BeginGreg.Format();
  362.   _tprintf(_T("The begining of the Gregorian calendar occurs on %s\n"), s);
  363.   
  364.     
  365.   // Try out the other operators
  366.   long l = 0;
  367.   x = CDate::CurrentDate();
  368.   l = x.Since1900Epoch();
  369.   _tprintf(_T("Today is %ld days since the 1900 epoch\n"), l);
  370.   l = x.Since1950Epoch();
  371.   _tprintf(_T("Today is %ld days since the 1950 epoch\n"), l);
  372.   l = x.SinceCTimeEpoch();
  373.   _tprintf(_T("Today is %ld days since the CTime epoch\n"), l);
  374.   l = x.Since2000Epoch();
  375.   _tprintf(_T("Today is %ld days since the 2000 epoch\n"), l);
  376.   l = x.GDN();
  377.   _tprintf(_T("Today is %ld days since the Gregorian epoch\n"), l);
  378.   l = x.JD();
  379.   _tprintf(_T("Today is %ld days since the Julian Day epoch\n"), l);
  380.   if (x.IsLeap())
  381.     _tprintf(_T("This year is a leap year\n"));
  382.   else
  383.     _tprintf(_T("This year is not a leap year\n"));
  384.   WORD diy = x.DaysInYear();
  385.   _tprintf(_T("This year contains %d days \n"), diy);
  386.   WORD dim = x.DaysInMonth();
  387.   _tprintf(_T("This month contains %d days \n"), dim);
  388.   x.AddYear(100);
  389.   s = x.Format();
  390.   _tprintf(_T("100 years from today is %s\n"), s);
  391.   x.AddYear(-100);
  392.   s = x.Format();
  393.   _tprintf(_T("100 years from today - 100 years is %s\n"), s);
  394.   x.AddMonth(100);
  395.   s = x.Format();
  396.   _tprintf(_T("100 months from today is %s\n"), s);
  397.   x.AddMonth(-100);
  398.   s = x.Format();
  399.   _tprintf(_T("100 months from today - 100 months is %s\n"), s);
  400.   x.AddWeek(100);
  401.   s = x.Format();
  402.   _tprintf(_T("100 weeks from today is %s\n"), s);
  403.   x.AddWeek(-100);
  404.   s = x.Format();
  405.   _tprintf(_T("100 weeks from today - 100 weeks is %s\n"), s);
  406.   dow = x.GetDayOfWeek();
  407.   _tprintf(_T("Todays day of week is %d\n"), dow);
  408.   s = x.GetFullStringDayOfWeek();
  409.   _tprintf(_T("Todays full string day of week is %s\n"), s);
  410.   s = x.GetAbrStringDayOfWeek();
  411.   _tprintf(_T("Todays Abreviated string day of week is %s\n"), s);
  412.   s = x.GetFullStringMonth();
  413.   _tprintf(_T("Todays full string Month is %s\n"), s);
  414.   s = x.GetAbrStringMonth();
  415.   _tprintf(_T("Todays Abreviated string Month is %s\n"), s);
  416.   _tprintf(_T("Today is %d days since the 1st of this year\n"), x.DaysSinceJan1());
  417.   _tprintf(_T("Today is %d days since the 0th of this year\n"), x.DaysSinceJan0());
  418.   
  419.   if (x.InGregorianCalendar())
  420.     _tprintf(_T("Today is in the Gregorian Calendar\n"));
  421.   else
  422.     _tprintf(_T("Today is in the Julian Calendar\n"));
  423.  
  424.  
  425.   //Creation of other CDate's from this instance
  426.   x = CDate(1995, 2, 3);
  427.   s = x.Format();
  428.   _tprintf(_T("The CDate used to test CDate creation from this instance is %s\n"), s);
  429.   CDate c = x.FirstThisMonth();
  430.   s = c.Format();
  431.   _tprintf(_T("FirstThisMonth returns %s\n"), s);
  432.   c = x.LastThisMonth();
  433.   s = c.Format();
  434.   _tprintf(_T("LastThisMonth returns %s\n"), s);
  435.   c = x.FirstThisYear();
  436.   s = c.Format();
  437.   _tprintf(_T("FirstThisYear returns %s\n"), s);
  438.   c = x.LastThisYear();
  439.   s = c.Format();
  440.   _tprintf(_T("FirstThisMonth returns %s\n"), s);
  441.  
  442.  
  443.   //assigment operator has been tested before
  444.   x = CDate::CurrentDate();
  445.   c = x + 100;
  446.   s = c.Format();
  447.   _tprintf(_T("100 days from today is %s\n"), s);
  448.   c = c - 100;
  449.   s = c.Format();
  450.   _tprintf(_T("100 days from today  - 100 days is %s\n"), s);
  451.   long diff = CDate(2000, 1, 1) - CDate::CurrentDate();
  452.   _tprintf(_T("the timespan between Epoch 2000 and today is %ld\n"), diff);
  453.   c += 1000;
  454.   s = c.Format();
  455.   _tprintf(_T("today incremented by 1000 days is %s\n"), s);
  456.   c -= 1000;
  457.   s = c.Format();
  458.   _tprintf(_T("today incremented by 1000 days decremented by 1000 is %s\n"), s);
  459.   ++c;
  460.   s = c.Format();
  461.   _tprintf(_T("Tomorrow is %s\n"), s);
  462.   --c;
  463.   --c;
  464.   s = c.Format();
  465.   _tprintf(_T("Yesterday was %s\n"), s);
  466.  
  467.  
  468.   //try out the Dump operator
  469. #ifdef _DEBUG
  470.   afxDump << c;
  471. #endif
  472.  
  473.   c = CDate::CurrentDate();
  474.   
  475.   //Full test of the Format function
  476.   _tprintf(_T("A full test of Format for Today gives\n"));
  477.   s = c.Format("%a");
  478.   _tprintf(_T("Abbreviated weekday name : %s\n"), s);
  479.   s = c.Format("%A");
  480.   _tprintf(_T("Full weekday name : %s\n"), s);
  481.   s = c.Format("%b");
  482.   _tprintf(_T("Abbreviated month name : %s\n"), s);
  483.   s = c.Format("%c");
  484.   _tprintf(_T("Year displayed using CE / BCE convention : %s\n"), s);
  485.   s = c.Format("%B");
  486.   _tprintf(_T("Full month name : %s\n"), s);
  487.   s = c.Format("%d");
  488.   _tprintf(_T("Day of month as decimal number (01 - 31) : %s\n"), s);
  489.   s = c.Format("%j");
  490.   _tprintf(_T("Day of year as decimal number (001 - 366) : %s\n"), s);
  491.   s = c.Format("%m");
  492.   _tprintf(_T("Month as decimal number (01 - 12) : %s\n"), s);
  493.   s = c.Format("%U");
  494.   _tprintf(_T("Week of year as decimal number : %s\n"), s);
  495.   s = c.Format("%w");
  496.   _tprintf(_T("Weekday as decimal number (1 - 7), Sunday is 1 : %s\n"), s);
  497.   s = c.Format("%x");
  498.   _tprintf(_T("Date representation for current locale : %s\n"), s);
  499.   s = c.Format("%y");
  500.   _tprintf(_T("Year without century, as decimal number (00 - 99) : %s\n"), s);
  501.   s = c.Format("%Y");
  502.   _tprintf(_T("Year with century, as decimal number : %s\n"), s);
  503.   s = c.Format("%#x");
  504.   _tprintf(_T("Long date representation, appropriate to current locale : %s\n"), s);
  505.   s = c.Format("%#d");
  506.   _tprintf(_T("Day of month without leading zeros : %s\n"), s);
  507.   s = c.Format("%#j");
  508.   _tprintf(_T("Day of year without leading zeros : %s\n"), s);
  509.   s = c.Format("%#m");
  510.   _tprintf(_T("Month without leading zeroes : %s\n"), s);
  511.   s = c.Format("%#U");
  512.   _tprintf(_T("Week of year without leading zeroes : %s\n"), s);
  513.   s = c.Format("%#y");
  514.   _tprintf(_T("Year without century without leading zeroes : %s\n"), s);
  515.   
  516.  
  517.  
  518.   /*
  519.   virtual void Serialize(CArchive& ar);
  520.   friend ostream& operator<<(ostream& os, const CDate& Date);
  521.   friend CArchive& operator<<(CArchive& ar, CDate& Date);
  522.   friend CArchive& operator>>(CArchive& ar, CDate& Date);
  523.   */
  524.  
  525.  
  526.  
  527.   // Try out the week of year function
  528.   x = CDate(1997, 1, 1);
  529.   s = x.Format();
  530.   _tprintf(_T("The first of January for testing the Week Of Year function is %s\n"), s);
  531.   _tprintf(_T("Setting the begining of the week to THURSDAY\n"));
  532.   CDate v = CDate(1997, CDate::JANUARY, 1, CDate::THURSDAY);
  533.   s = v.Format();
  534.   _tprintf(_T("The 1st Thursday of 1997 is %s\n"), s);
  535.   CDate::SetBeginingDayOfWeek(CDate::THURSDAY);
  536.   for (WORD i=1; i<32; i++)
  537.   {
  538.     CDate p(1997, 1, i);
  539.     WORD woy = p.GetWeekOfYear();
  540.     s = p.Format();
  541.     _tprintf(_T("The week of the year for %s is"), s);
  542.     _tprintf(_T(" %d\n"), woy);
  543.   }
  544.  
  545.  
  546.   // Try out the week of year function
  547.   x = CDate(1997, 1, 1);
  548.   s = x.Format();
  549.   _tprintf(_T("The first of january for testing the Week Of year function is %s\n"), s);
  550.   v = CDate(1997, CDate::JANUARY, 1, CDate::MONDAY);
  551.   s = v.Format();
  552.   _tprintf(_T("The 1st Monday of 1997 is %s\n"), s);
  553.   _tprintf(_T("Setting the begining of the week to MONDAY\n"));
  554.   CDate::SetBeginingDayOfWeek(CDate::MONDAY);
  555.   for (i=1; i<32; i++)
  556.   {
  557.     CDate p(x.GetYear(), x.GetMonth(), i);
  558.     WORD woy = p.GetWeekOfYear();
  559.     s = p.Format();
  560.     _tprintf(_T("The week of the year for %s is"), s);
  561.     _tprintf(_T(" %d\n"), woy);
  562.   }
  563.  
  564.  
  565.   // Try out the week of month function
  566.   x = CDate::CurrentDate();
  567.   x = x.FirstThisMonth();
  568.   s = x.Format();
  569.   _tprintf(_T("The first of this month for testing the Week Of month function is %s\n"), s);
  570.   v = CDate(x.GetYear(), x.GetMonth(), 1, CDate::THURSDAY);
  571.   s = v.Format();
  572.   _tprintf(_T("The 1st Thursday of the month is %s\n"), s);
  573.   _tprintf(_T("Setting the begining of the week to THURSDAY\n"));
  574.   CDate::SetBeginingDayOfWeek(CDate::THURSDAY);
  575.   for (i=1; i<=x.DaysInMonth(); i++)
  576.   {
  577.     CDate p(x.GetYear(), x.GetMonth(), i);
  578.     WORD wom = p.GetWeekOfMonth();
  579.     s = p.Format();
  580.     _tprintf(_T("The week of the month for %s is"), s);
  581.     _tprintf(_T(" %d\n"), wom);
  582.   }
  583.  
  584.  
  585.  
  586.   // Try out the week of Month function with a different begining of week
  587.   x = CDate::CurrentDate();
  588.   x = x.FirstThisMonth();
  589.   s = x.Format();
  590.   _tprintf(_T("The first of this month for testing the Week Of month function is %s\n"), s);
  591.   v = CDate(x.GetYear(), x.GetMonth(), 1, CDate::MONDAY);
  592.   s = v.Format();
  593.   _tprintf(_T("The 1st Monday of the month is %s\n"), s);
  594.   _tprintf(_T("Setting the begining of the week to MONDAY\n"));
  595.   CDate::SetBeginingDayOfWeek(CDate::MONDAY);
  596.   for (i=1; i<=x.DaysInMonth(); i++)
  597.   {
  598.     CDate p(x.GetYear(), x.GetMonth(), i);
  599.     WORD wom = p.GetWeekOfMonth();
  600.     s = p.Format();
  601.     _tprintf(_T("The week of the month for %s is"), s);
  602.     _tprintf(_T(" %d\n"), wom);
  603.   }
  604.  
  605.  
  606.  
  607.   //try out the collate function
  608.   x = CDate::CurrentDate();
  609.   long coll = x.Collate();
  610.   _tprintf(_T("The collate function for today returns %ld\n"), coll);
  611.  
  612.  
  613.  
  614.  
  615.   //Test of the CLTimeSpan class
  616.  
  617.   
  618.   //first the constructors
  619.   CLTimeSpan ts;
  620.   ASSERT(!ts.IsValid());
  621.  
  622.   ts = CLTimeSpan(3, 4, 5, 6, 233);
  623.   long dd = ts.GetTotalDays();
  624.   WORD hh = ts.GetHours();
  625.   WORD mm = ts.GetMinutes();
  626.   WORD ss = ts.GetSeconds();
  627.   WORD ms = ts.GetMilliSeconds();
  628.   s = ts.Format();
  629.  
  630.   ts = CLTimeSpan(3, 27, 59, 69, 1233);
  631.   s = ts.Format();
  632.  
  633.   CLTimeSpan ts2(ts);
  634.   s = ts2.Format();
  635.  
  636.   CTimeSpan OneDay(1, 0, 0, 0);
  637.   ts = CLTimeSpan(OneDay);
  638.   s = ts.Format();
  639.  
  640.   ts = CLTimeSpan(86400.5);
  641.   s = ts.Format();
  642.  
  643.   ts = CLTimeSpan(-23.5);
  644.   dd = ts.GetTotalDays();
  645.   hh = ts.GetHours();
  646.   mm = ts.GetMinutes();
  647.   ss = ts.GetSeconds();
  648.   ms = ts.GetMilliSeconds();
  649.   s = ts.Format();
  650.   double secs = ts.SecondsAsDouble();
  651.  
  652.   ts = CLTimeSpan(-86401.5987);
  653.   dd = ts.GetTotalDays();
  654.   hh = ts.GetHours();
  655.   mm = ts.GetMinutes();
  656.   ss = ts.GetSeconds();
  657.   ms = ts.GetMilliSeconds();
  658.   s = ts.Format();
  659.   secs = ts.SecondsAsDouble();
  660.  
  661.   ts = CLTimeSpan(-86401.5981);
  662.   dd = ts.GetTotalDays();
  663.   hh = ts.GetHours();
  664.   mm = ts.GetMinutes();
  665.   ss = ts.GetSeconds();
  666.   ms = ts.GetMilliSeconds();
  667.   s = ts.Format();
  668.   secs = ts.SecondsAsDouble();
  669.   
  670.   ts = CLTimeSpan(86399.999);
  671.   ms = ts.GetMilliSeconds();
  672.   s = ts.Format();
  673.   secs = ts.SecondsAsDouble();
  674.  
  675.   ts = CLTimeSpan(86399.99999);    //should round up to nearest second
  676.   ms = ts.GetMilliSeconds();
  677.   s = ts.Format();
  678.   secs = ts.SecondsAsDouble();
  679.  
  680.   ts = CLTimeSpan(263967.987654);  //should round up to nearest millisecond
  681.   s = ts.Format();
  682.   secs = ts.SecondsAsDouble();
  683.  
  684.   ts = CLTimeSpan(263967.987354);  //should round down to nearest millisecond
  685.   s = ts.Format();
  686.   secs = ts.SecondsAsDouble();
  687.  
  688.   //COleDateTimeSpan Construction
  689. #if defined(_WIN32)
  690.   COleDateTimeSpan olets(19, 12, 10, 3);
  691.   ts = CLTimeSpan(olets);  
  692.   s = ts.Format();
  693. #endif  
  694.  
  695.  
  696.  
  697.   //Set operators have been tested via the constructors
  698.  
  699.   //static Constructors
  700.  
  701.   ts = CLTimeSpan::OneCivilYear();
  702.   s = ts.Format();
  703.   _tprintf(_T("One Civil year as a time span is %s\n"), s);
  704.   ts = CLTimeSpan::OneDay();
  705.   s = ts.Format();
  706.   _tprintf(_T("One Day as a time span is %s\n"), s);
  707.   ts = CLTimeSpan::OneHour();
  708.   s = ts.Format();
  709.   _tprintf(_T("One Hour as a time span is %s\n"), s);
  710.   ts = CLTimeSpan::OneMinute();
  711.   s = ts.Format();
  712.   _tprintf(_T("One Minute as a time span is %s\n"), s);
  713.   ts = CLTimeSpan::OneSecond();
  714.   s = ts.Format();
  715.   _tprintf(_T("One Second as a time span is %s\n"), s);
  716.   ts = CLTimeSpan::OneMilliSecond();
  717.   s = ts.Format();
  718.   _tprintf(_T("One MilliSecond as a time span is %s\n"), s);
  719.  
  720.   //days, Hours, Minutes Seconds & MilliSecond accessors
  721.   //already tested via Format
  722.   
  723.  
  724.   //Overloaded Arithmetic Operators
  725.   CLTimeSpan ts1 = CLTimeSpan::OneCivilYear();
  726.   ts2 = CLTimeSpan::OneDay();
  727.   //operator= already tested           //not fully tested yet
  728.   CLTimeSpan ts3 = ts1 + ts2;
  729.   _tprintf(_T("One year + One day is %s\n"), ts3.Format());
  730.   ts3 = ts1 - ts2;
  731.   _tprintf(_T("One year - One day is %s\n"), ts3.Format());
  732.   ts3 = ts2 - ts1;
  733.  
  734.   _tprintf(_T("One day - One year is %s\n"), ts3.Format());
  735.   ts1 = CLTimeSpan::OneCivilYear();
  736.   ts2 = CLTimeSpan::OneDay();
  737.   ts1 += ts2;
  738.   _tprintf(_T("One year incremented by one day is %s\n"), ts1.Format());
  739.   ts1 -= ts2;
  740.   _tprintf(_T("One year+one day decremented by one day is %s\n"), ts1.Format());
  741.   ts1 = CLTimeSpan::OneCivilYear();
  742.   ts2 -= ts1;
  743.   _tprintf(_T("One day decremented by one year is %s\n"), ts2.Format());
  744.   ts1 = CLTimeSpan::OneCivilYear();
  745.   ts1.Negate();
  746.   ts2 = CLTimeSpan::OneDay();
  747.   ts3 = ts1 - ts2;
  748.   _tprintf(_T("-One year - one day is %s\n"), ts3.Format());
  749.   ts3 = ts1 + ts2;
  750.   _tprintf(_T("-One year + one day is %s\n"), ts3.Format());
  751.   ts1 = CLTimeSpan::OneCivilYear();
  752.   ts2 = CLTimeSpan::OneDay();
  753.   ts2.Negate();
  754.   ts3 = ts1 - ts2;
  755.   _tprintf(_T("One year - (-one day) is %s\n"), ts3.Format());
  756.   ts3 = ts1 + ts2;
  757.   _tprintf(_T("One year + (-one day) is %s\n"), ts3.Format());
  758.   ts1 = CLTimeSpan::OneCivilYear();
  759.   ts1.Negate();
  760.   ts2 = CLTimeSpan::OneDay();
  761.   ts1 += ts2;
  762.   _tprintf(_T("-One year incremented by one day is %s\n"), ts1.Format());
  763.   ts1 -= ts2;
  764.   _tprintf(_T("-One year + 1 day decremented by one day is %s\n"), ts1.Format());
  765.   ts2 = CLTimeSpan::OneCivilYear();
  766.   ts2.Negate();
  767.   ts1 -= ts2;
  768.   _tprintf(_T("-One year decremented by -one year is %s\n"), ts1.Format());
  769.   ts1 += ts2;
  770.   _tprintf(_T("-One year - -one year incremented by -one year is %s\n"), ts1.Format());
  771.   ts1 = CLTimeSpan::OneCivilYear();
  772.   ts2 = CLTimeSpan::OneDay();
  773.   ts2.Negate();
  774.   ts3 = ts1 - ts2;
  775.   _tprintf(_T("One year - -one day is %s\n"), ts3.Format());
  776.   ts3 = ts1 + ts2;
  777.   _tprintf(_T("One year + -one day is %s\n"), ts3.Format());
  778.   ts3 = ts2 - ts1;
  779.   _tprintf(_T("-One day - one year is %s\n"), ts3.Format());
  780.   ts3 = ts2 + ts1;
  781.   _tprintf(_T("-One day + one year is %s\n"), ts3.Format());
  782.   ts1 = CLTimeSpan::OneCivilYear();
  783.   ts2 = CLTimeSpan::OneDay();
  784.   ts3 = ts1 * 100;
  785.   
  786.   dd = ts3.GetTotalDays();
  787.   hh = ts3.GetHours();
  788.   mm = ts3.GetMinutes();
  789.   ss = ts3.GetSeconds();
  790.   ms = ts3.GetMilliSeconds();
  791.   s = ts3.Format();
  792.   
  793.   _tprintf(_T("One year * 100 is %s\n"), ts3.Format());
  794.   ts3 = 100 * ts1;
  795.   _tprintf(_T("100 * One year is %s\n"), ts3.Format());
  796.   ts3 = ts1 / 3;
  797.   _tprintf(_T("One year / 3 is %s\n"), ts3.Format());
  798.   ts1 *= 100;
  799.   _tprintf(_T("One year *= 100 is %s\n"), ts1.Format());
  800.   ts1 = CLTimeSpan::OneCivilYear();
  801.   ts1 /= 100;
  802.   _tprintf(_T("One year /= 100 is %s\n"), ts1.Format());
  803.   ts1 = CLTimeSpan(365, 6, 10, 34, 33);
  804.   ts3 = ts1 * 100;
  805.   _tprintf(_T("%s * 100 is"), ts1.Format());
  806.   _tprintf(_T(" %s\n"), ts3.Format());
  807.   ts3 = ts1 / 100;
  808.   _tprintf(_T("%s / 100 is"), ts1.Format());
  809.   _tprintf(_T(" %s\n"), ts3.Format());
  810.  
  811.  
  812.  
  813.   //overloaded equality operators
  814.   ts1 = CLTimeSpan::OneCivilYear();
  815.   ts2 = CLTimeSpan::OneDay();
  816.   ASSERT(ts1 >= ts2);
  817.   ASSERT(ts1 > ts2);
  818.   ASSERT(ts2 < ts1);
  819.   ASSERT(ts2 <= ts1);
  820.   ASSERT(ts2 != ts1);
  821.   ASSERT(!(ts2 == ts1));
  822.   
  823.   //AssertValid() has already been tested
  824. #ifdef _DEBUG
  825.   afxDump << ts2;
  826. #endif
  827.   
  828.   //Format has already been tested
  829.  
  830.  
  831.  
  832.  
  833.   //Try out of the CLTimeOfDay class
  834.  
  835.   //first the constructors
  836.   CLTimeOfDay tod;
  837.   ASSERT(!tod.IsValid());
  838.  
  839.   //tod = CLTimeOfDay(23, 59, 61, 0); //should assert
  840.   //tod = CLTimeOfDay(24, 59, 61, 0); //should assert
  841.   //tod = CLTimeOfDay(23, 59, 59, 1000); //should assert
  842.                      
  843.   SYSTEMTIME stnow;                   
  844. #ifdef _WIN32      
  845.   GetLocalTime(&stnow);
  846.   tod = CLTimeOfDay(stnow);
  847.   s = tod.Format();
  848. #endif  
  849.  
  850.   CLTimeOfDay tod2(tod);
  851.   s = tod.Format();
  852.  
  853.   //tod2 = CLTimeOfDay(-23.5); //should assert
  854.   s = tod2.Format();
  855.  
  856.   //tod2 = CLTimeOfDay(-86401.5); //should assert
  857.   s = tod2.Format();
  858.  
  859.   tod2 = CLTimeOfDay(86399.999);
  860.   s = tod2.Format();
  861.  
  862.   tod2 = CLTimeOfDay(86199.9766);
  863.   s = tod2.Format();
  864.  
  865.   
  866.   //Set functions tested via the constructors
  867.  
  868.  
  869.   //The static constructors
  870.  
  871.   tod = CLTimeOfDay::CurrentTimeOfDay(LOCAL);
  872.   s = tod.Format();
  873.   _tprintf(_T("The local time of day is %s\n"), s);
  874.  
  875.   tod = CLTimeOfDay::CurrentTimeOfDay(UTC);
  876.   s = tod.Format();
  877.   _tprintf(_T("The UTC time of day is %s\n"), s);
  878.  
  879.   //tod = CLTimeOfDay::CurrentTimeOfDay(ET); //should assert
  880.   
  881.   tod = CLTimeOfDay::Midnight();
  882.   s = tod.Format();
  883.   _tprintf(_T("Midnight as a time of day is %s\n"), s);
  884.  
  885.   tod = CLTimeOfDay::Midday();
  886.   s = tod.Format();
  887.   _tprintf(_T("Midday as a time of day is %s\n"), s);
  888.  
  889.   
  890.  
  891.   //try out the operations
  892.   tod = CLTimeOfDay::CurrentTimeOfDay(UTC);
  893.   WORD wVal = tod.GetHour();
  894.   wVal = tod.GetMinute();
  895.   long lVal = tod.GetTotalSeconds();
  896.   wVal = tod.GetSecond();
  897.   wVal = tod.GetMilliSecond();
  898.   ASSERT(tod.IsValid());
  899.   ULARGE_INTEGER col = tod.Collate();
  900.   _tprintf(_T("The collate function for the Current UTC time of day is\n"));
  901.   _tprintf(_T("HightPart:%ld LowPart:%ld\n"), col.HighPart, col.LowPart);
  902.   stnow = tod.GetSYSTEMTIME();
  903.  
  904.   //Arithmetic operators
  905.   
  906.   CLTimeOfDay tod3(12, 1, 2, 3);
  907.   CLTimeSpan  ts4(1, 25, 59, 45, 28);
  908.   //operator= already tested
  909.   CLTimeOfDay tod4 = tod3 + ts4;
  910.   s = tod4.Format();
  911.   CString& s2 = tod3.Format();
  912.   CString& s3 = ts4.Format();
  913.   _tprintf(_T("%s"), s2);
  914.   _tprintf(_T(" + %s = "), s3);
  915.   _tprintf(_T("%s\n"), s);
  916.  
  917.   tod2 = tod3 - ts4;
  918.   s2 = tod3.Format();
  919.   _tprintf(_T("%s"), s2);
  920.   s3 = ts4.Format();
  921.   _tprintf(_T(" - %s = "), s3);
  922.   s = tod2.Format();
  923.   _tprintf(_T("%s\n"), s);
  924.  
  925.   s2 = tod3.Format();
  926.   _tprintf(_T("%s"), s2);
  927.   tod3 += ts4;
  928.   s3 = ts4.Format();
  929.   _tprintf(_T(" += %s = "), s3);
  930.   s = tod3.Format();
  931.   _tprintf(_T("%s\n"), s);
  932.   
  933.   s2 = tod3.Format();
  934.   _tprintf(_T("%s"), s2);
  935.   tod3 -= ts4;
  936.   s3 = ts4.Format();
  937.   _tprintf(_T(" -= %s = "), s3);
  938.   s = tod3.Format();
  939.   _tprintf(_T("%s\n"), s);
  940.  
  941.   //try out negative timespans
  942.   ts4.Negate();
  943.   tod4 = tod3 + ts4;
  944.   s2 = tod3.Format();
  945.   _tprintf(_T("%s"), s2);
  946.   s3 = ts4.Format();
  947.   _tprintf(_T(" + %s = "), s3);
  948.   s = tod4.Format();
  949.   _tprintf(_T("%s\n"), s);
  950.  
  951.   tod2 = tod3 - ts4;
  952.   s2 = tod3.Format();
  953.   _tprintf(_T("%s"), s2);
  954.   s3 = ts4.Format();
  955.   _tprintf(_T(" - %s = "), s3);
  956.   s = tod2.Format();
  957.   _tprintf(_T("%s\n"), s);
  958.  
  959.   s2 = tod3.Format();
  960.   _tprintf(_T("%s"), s2);
  961.   tod3 += ts4;
  962.   s3 = ts4.Format();
  963.   _tprintf(_T(" += %s = "), s3);
  964.   s = tod3.Format();
  965.   _tprintf(_T("%s\n"), s);
  966.   
  967.   s2 = tod3.Format();
  968.   _tprintf(_T("%s"), s2);
  969.   tod3 -= ts4;
  970.   s3 = ts4.Format();
  971.   _tprintf(_T(" -= %s = "), s3);
  972.   s = tod3.Format();
  973.   _tprintf(_T("%s\n"), s);
  974.   
  975.  
  976.  
  977.   //equality operators
  978.  
  979.   CLTimeOfDay tod1(12, 1, 2, 3);
  980.   tod2 = CLTimeOfDay(13, 0, 2, 2);
  981.  
  982.   ASSERT(tod1 <= tod2);
  983.   ASSERT(tod1 < tod2);
  984.   ASSERT(tod2 > tod1);
  985.   ASSERT(tod2 >= tod1);
  986.   ASSERT(tod2 != tod1);
  987.   ASSERT(!(tod2 == tod1));
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.   //Try out the CLDate class
  995.  
  996.   //first the constructors
  997.   CLDate ldate;
  998.   ASSERT(!ldate.IsValid());
  999.   ldate = CLDate(1995, 10, 3, 12, 11, 10, 330, LOCAL);
  1000.   s = ldate.Format();
  1001.   //SYSTEMTIME st; 
  1002. #ifdef _WIN32  
  1003.   ::GetLocalTime(&st);
  1004.   ldate = CLDate(st, LOCAL);
  1005.   s = ldate.Format();
  1006. #endif  
  1007.   ldate = CLDate(1995, 3, 5, CDate::SUNDAY, 0, 0, 0, 0, UTC); 
  1008.   s = ldate.Format();
  1009.   ldate = CLDate(1000, CDate::EPOCH_JD, 0, 0, 0, 0, UTC);
  1010.   s = ldate.Format();
  1011.   //Copy constructor already tested
  1012.   CTime ct = CTime::GetCurrentTime();
  1013.   ldate = CLDate(ct);
  1014.   s = ldate.Format();
  1015.   ldate = CLDate(CDate::CurrentDate(), CLTimeOfDay::CurrentTimeOfDay(LOCAL), LOCAL);
  1016.   s = ldate.Format();
  1017.       
  1018. #if defined(_WIN32)
  1019.   COleDateTime ldt(1992, CDate::OCTOBER, 10, 3, 4, 5);
  1020.   ldate = CLDate(ldt, UTC);
  1021.   s = ldate.Format();
  1022.   ldt = COleDateTime(1970, 2, 1, 5, 6, 7);
  1023.   ldate = CLDate(ldt, LOCAL);
  1024.   s = ldate.Format();
  1025. #endif  
  1026.   
  1027.   //Set operators tested via the constructors above
  1028.  
  1029.   //Static Constructors
  1030.   ldate = CLDate::CurrentTime(UTC);
  1031.   s = ldate.Format();   
  1032.  
  1033.   //need to test SetDefaultFormat()
  1034.  
  1035.   //check out the deltaT function
  1036.   CLTimeSpan DT = CLDate::DeltaT(ldate);
  1037.   s = DT.Format();
  1038.   
  1039.   DT = CLDate::DeltaT(CLDate(1650, 1, 1, 0, 0, 0, 0, UTC));
  1040.   s = DT.Format();
  1041.   _tprintf(_T("The DeltaT timespan for the Year 1650 is %s\n"), s);  //should be +48 Seconds
  1042.  
  1043.   DT = CLDate::DeltaT(CLDate(1750, 1, 1, 0, 0, 0, 0, UTC));
  1044.   s = DT.Format();
  1045.   _tprintf(_T("The DeltaT timespan for the Year 1750 is %s\n"), s);  //should be +13 Seconds
  1046.  
  1047.   DT = CLDate::DeltaT(CLDate(1850, 1, 1, 0, 0, 0, 0, UTC));
  1048.   s = DT.Format();
  1049.   _tprintf(_T("The DeltaT timespan for the Year 1850 is %s\n"), s);  //should be +7.1 Seconds
  1050.  
  1051.   DT = CLDate::DeltaT(CLDate(1910, 1, 1, 0, 0, 0, 0, UTC));
  1052.   s = DT.Format();
  1053.   _tprintf(_T("The DeltaT timespan for the Year 1910 is %s\n"), s);  //should be +10.5 Seconds
  1054.   
  1055.   DT = CLDate::DeltaT(CLDate(1950, 1, 1, 0, 0, 0, 0, UTC));
  1056.   s = DT.Format();
  1057.   _tprintf(_T("The DeltaT timespan for the Year 1950 is %s\n"), s);  //should be +29.1 Seconds
  1058.  
  1059.   DT = ldate.DeltaT();
  1060.   s = DT.Format();
  1061.   _tprintf(_T("The current DeltaT timespan is %s\n"), s);            //??? depends on current date
  1062.   
  1063.   DT = CLDate::DeltaT(CLDate(2000, 1, 1, 0, 0, 0, 0, UTC));
  1064.   s = DT.Format();
  1065.   _tprintf(_T("The DeltaT timespan for the Year 2000 is %s\n"), s);  //should be around +1 minute
  1066.  
  1067.  
  1068.  
  1069.   //check page 72 of the Book "Astronomical Algorithms" for 
  1070.   //other sample values of DeltaT
  1071.  
  1072.   //Need to try out the following functions
  1073.   //GetCDate & GetCLTimeOfDay tested through the Format function
  1074.   st = ldate.GetSYSTEMTIME();
  1075.   
  1076.   ldate.AddYear(10);
  1077.   s = ldate.Format();
  1078.   _tprintf(_T("10 years from now UTC is %s\n"), s);
  1079.  
  1080.   ldate = CLDate::CurrentTime(UTC);
  1081.   ldate.AddWeek(-10);
  1082.   s = ldate.Format();
  1083.   _tprintf(_T("10 weeks before today UTC is %s\n"), s);
  1084.  
  1085.   ldate = CLDate::CurrentTime(UTC);
  1086.   ldate.AddMonth(-14);
  1087.   s = ldate.Format();
  1088.   _tprintf(_T("14 months before today UTC is %s\n"), s);
  1089.  
  1090.   
  1091.   ASSERT(ldate.IsValid());     
  1092.   ldate = CLDate();
  1093.   ASSERT(!ldate.IsValid());
  1094.  
  1095.  
  1096.   //Test a daylight savings date
  1097.  
  1098.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, UTC);
  1099.   CString& s1 = ldate.Format();
  1100.   _tprintf(_T("%s is "), s1);
  1101.   ldate.SetTimeFrame(UTC);
  1102.   s = ldate.Format();
  1103.   _tprintf(_T("%s\n"), s);
  1104.  
  1105.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, UTC);
  1106.   s1 = ldate.Format();
  1107.   _tprintf(_T("%s is "), s1);
  1108.   ldate.SetTimeFrame(ET);
  1109.   s = ldate.Format();
  1110.   _tprintf(_T("%s\n"), s);
  1111.  
  1112.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, UTC);
  1113.   s1 = ldate.Format();
  1114.   _tprintf(_T("%s is "), s1);
  1115.   ldate.SetTimeFrame(LOCAL);
  1116.   s = ldate.Format();
  1117.   _tprintf(_T("%s\n"), s);
  1118.  
  1119.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, ET);
  1120.   s1 = ldate.Format();
  1121.   _tprintf(_T("%s is "), s1);
  1122.   ldate.SetTimeFrame(UTC);
  1123.   s = ldate.Format();
  1124.   _tprintf(_T("%s\n"), s);
  1125.  
  1126.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, ET);
  1127.   s1 = ldate.Format();
  1128.   _tprintf(_T("%s is "), s1);
  1129.   ldate.SetTimeFrame(ET);
  1130.   s = ldate.Format();
  1131.   _tprintf(_T("%s\n"), s);
  1132.   
  1133.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, ET);
  1134.   s1 = ldate.Format();
  1135.   _tprintf(_T("%s is "), s1);
  1136.   ldate.SetTimeFrame(LOCAL);
  1137.   s = ldate.Format();
  1138.   _tprintf(_T("%s\n"), s);
  1139.  
  1140.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, LOCAL);
  1141.   s1 = ldate.Format();
  1142.   _tprintf(_T("%s is "), s1);
  1143.   ldate.SetTimeFrame(UTC);
  1144.   s = ldate.Format();
  1145.   _tprintf(_T("%s\n"), s);
  1146.   
  1147.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, LOCAL);
  1148.   s1 = ldate.Format();
  1149.   _tprintf(_T("%s is "), s1);
  1150.   ldate.SetTimeFrame(ET);
  1151.   s = ldate.Format();
  1152.   _tprintf(_T("%s\n"), s);
  1153.   
  1154.   ldate = CLDate(1995, 7, 9, 8, 7, 6, 0, LOCAL);
  1155.   s1 = ldate.Format();
  1156.   _tprintf(_T("%s is "), s1);
  1157.   ldate.SetTimeFrame(LOCAL);
  1158.   s = ldate.Format();
  1159.   _tprintf(_T("%s\n"), s);
  1160.  
  1161.  
  1162.   //test a Standard time
  1163.  
  1164.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, UTC);
  1165.   s1 = ldate.Format();
  1166.   _tprintf(_T("%s is "), s1);
  1167.   ldate.SetTimeFrame(UTC);
  1168.   s = ldate.Format();
  1169.   _tprintf(_T("%s\n"), s);
  1170.  
  1171.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, UTC);
  1172.   s1 = ldate.Format();
  1173.   _tprintf(_T("%s is "), s1);
  1174.   ldate.SetTimeFrame(ET);
  1175.   s = ldate.Format();
  1176.   _tprintf(_T("%s\n"), s);
  1177.  
  1178.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, UTC);
  1179.   s1 = ldate.Format();
  1180.   _tprintf(_T("%s is "), s1);
  1181.   ldate.SetTimeFrame(LOCAL);
  1182.   s = ldate.Format();
  1183.   _tprintf(_T("%s\n"), s);
  1184.  
  1185.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, ET);
  1186.   s1 = ldate.Format();
  1187.   _tprintf(_T("%s is "), s1);
  1188.   ldate.SetTimeFrame(UTC);
  1189.   s = ldate.Format();
  1190.   _tprintf(_T("%s\n"), s);
  1191.  
  1192.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, ET);
  1193.   s1 = ldate.Format();
  1194.   _tprintf(_T("%s is "), s1);
  1195.   ldate.SetTimeFrame(ET);
  1196.   s = ldate.Format();
  1197.   _tprintf(_T("%s\n"), s);
  1198.   
  1199.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, ET);
  1200.   s1 = ldate.Format();
  1201.   _tprintf(_T("%s is "), s1);
  1202.   ldate.SetTimeFrame(LOCAL);
  1203.   s = ldate.Format();
  1204.   _tprintf(_T("%s\n"), s);
  1205.  
  1206.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, LOCAL);
  1207.   s1 = ldate.Format();
  1208.   _tprintf(_T("%s is "), s1);
  1209.   ldate.SetTimeFrame(UTC);
  1210.   s = ldate.Format();
  1211.   _tprintf(_T("%s\n"), s);
  1212.   
  1213.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, LOCAL);
  1214.   s1 = ldate.Format();
  1215.   _tprintf(_T("%s is "), s1);
  1216.   ldate.SetTimeFrame(ET);
  1217.   s = ldate.Format();
  1218.   _tprintf(_T("%s\n"), s);
  1219.   
  1220.   ldate = CLDate(1995, 12, 9, 8, 7, 6, 0, LOCAL);
  1221.   s1 = ldate.Format();
  1222.   _tprintf(_T("%s is "), s1);
  1223.   ldate.SetTimeFrame(LOCAL);
  1224.   s = ldate.Format();
  1225.   _tprintf(_T("%s\n"), s);
  1226.  
  1227.  
  1228.  
  1229.   //Need to test the two conditions where a LOCAL time occurs twice 
  1230.   //or not at all
  1231.  
  1232.  
  1233.   ldate = CLDate::CurrentTime(UTC);
  1234.   s = ldate.Format();
  1235.   _tprintf(_T("The current UTC date is %s\n"), s);
  1236.   ldate = CLDate::CurrentTime(ET);
  1237.   s = ldate.Format();
  1238.   _tprintf(_T("The current ET date is %s\n"), s);
  1239.   ldate = CLDate::CurrentTime(LOCAL);
  1240.   s = ldate.Format();
  1241.   _tprintf(_T("The current LOCAL date is %s\n"), s);
  1242.  
  1243.   BOOL bInDst = ldate.IsDST();
  1244.   if (bInDst)
  1245.     _tprintf(_T("Current date is a Daylight Time\n"));
  1246.   else
  1247.     _tprintf(_T("Current date is a Standard Time\n"));
  1248.  
  1249.   //operator= already tried out
  1250.  
  1251.   ldate = CLDate::CurrentTime(UTC);
  1252.   ts = CTimeSpan(10, 10, 10, 10);
  1253.   ldate += ts;
  1254.   s1 = ts.Format();
  1255.   _tprintf(_T("%s from today UTC is "), s1);
  1256.   s = ldate.Format();
  1257.   _tprintf(_T("%s\n"), s);
  1258.  
  1259.  
  1260.   //Arithmetic operators
  1261.   ldate = CLDate::CurrentTime(LOCAL);
  1262.   CLDate ldate3 = ldate;
  1263.   ldate3.SetTimeFrame(UTC);
  1264.   ldate3 += CLTimeSpan(0, 0, 0, 1, 0);
  1265.   ts = ldate3 - ldate;
  1266.  
  1267.  
  1268.  
  1269.   //try out the equality operators
  1270.   ldate = CLDate::CurrentTime(UTC);
  1271.   CLDate ldate2(ldate);
  1272.   ldate2.SetTimeFrame(LOCAL);
  1273.   ASSERT(ldate == ldate2);
  1274.   ASSERT(!(ldate != ldate2));
  1275.   ldate2 += CLTimeSpan(0, 0, 0, 0, 1);
  1276.   ASSERT(ldate2 != ldate);
  1277.   ASSERT(ldate2 >= ldate);
  1278.   ASSERT(ldate <= ldate2);
  1279.   ASSERT(ldate < ldate2);
  1280.  
  1281.   //AssertValid() already tested internally
  1282.  
  1283. #ifdef _DEBUG
  1284.   afxDump << ldate;
  1285. #endif
  1286.   
  1287.   
  1288.   //Full test of the Format function
  1289.   ldate = CLDate::CurrentTime(LOCAL);
  1290.   _tprintf(_T("A full test of CLDate::Format for Now (LOCAL) gives\n"));
  1291.   s = ldate.Format("%a");
  1292.   _tprintf(_T("Abbreviated weekday name : %s\n"), s);
  1293.   s = ldate.Format("%A");
  1294.   _tprintf(_T("Full weekday name : %s\n"), s);
  1295.   s = ldate.Format("%b");
  1296.   _tprintf(_T("Abbreviated month name : %s\n"), s);
  1297.   s = ldate.Format("%B");
  1298.   _tprintf(_T("Full month name : %s\n"), s);
  1299.   s = ldate.Format("%c");
  1300.   _tprintf(_T("Year displayed using CE / BCE convention : %s\n"), s);
  1301.   s = ldate.Format("%d");
  1302.   _tprintf(_T("Day of month as decimal number (01 - 31) : %s\n"), s);
  1303.   s = ldate.Format("%j");
  1304.   _tprintf(_T("Day of year as decimal number (001 - 366) : %s\n"), s);
  1305.   s = ldate.Format("%m");
  1306.   _tprintf(_T("Month as decimal number (01 - 12) : %s\n"), s);
  1307.   s = ldate.Format("%U");
  1308.   _tprintf(_T("Week of year as decimal number : %s\n"), s);
  1309.   s = ldate.Format("%w");
  1310.   _tprintf(_T("Weekday as decimal number (1 - 7), Sunday is 1 : %s\n"), s);
  1311.   s = ldate.Format("%x");
  1312.   _tprintf(_T("Date representation for current locale : %s\n"), s);
  1313.   s = ldate.Format("%y");
  1314.   _tprintf(_T("Year without century, as decimal number (00 - 99) : %s\n"), s);
  1315.   s = ldate.Format("%Y");
  1316.   _tprintf(_T("Year with century, as decimal number : %s\n"), s);
  1317.   s = ldate.Format("%#x");
  1318.   _tprintf(_T("Long date representation, appropriate to current locale : %s\n"), s);
  1319.   s = ldate.Format("%#d");
  1320.   _tprintf(_T("Day of month without leading zeros : %s\n"), s);
  1321.   s = ldate.Format("%#j");
  1322.   _tprintf(_T("Day of year without leading zeros : %s\n"), s);
  1323.   s = ldate.Format("%#m");
  1324.   _tprintf(_T("Month without leading zeroes : %s\n"), s);
  1325.   s = ldate.Format("%#U");
  1326.   _tprintf(_T("Week of year without leading zeroes, with Sunday as first day of week : %s\n"), s);
  1327.   s = ldate.Format("%#y");
  1328.   _tprintf(_T("Year without century without leading zeroes : %s\n"), s);
  1329.   s = ldate.Format("%H");
  1330.   _tprintf(_T("Hours in the current day : %s\n"), s);
  1331.   s = ldate.Format("%h");
  1332.   _tprintf(_T("AM / PM Hours in the current day : %s\n"), s);
  1333.   s = ldate.Format("%P");
  1334.   _tprintf(_T("AM / PM Indicator for the current day : %s\n"), s);
  1335.   s = ldate.Format("%M");
  1336.   _tprintf(_T("Minutes in the current day : %s\n"), s);
  1337.   s = ldate.Format("%S");
  1338.   _tprintf(_T("Seconds in the current day : %s\n"), s);
  1339.   s = ldate.Format("%F");
  1340.   _tprintf(_T("Milliseconds in the current day : %s\n"), s);
  1341.   s = ldate.Format("%#H");
  1342.   _tprintf(_T("Hours in the current day without leading zeros: %s\n"), s);
  1343.   s = ldate.Format("%#h");
  1344.   _tprintf(_T("AM / PM Hours in the current day without leading zeros: %s\n"), s);
  1345.   s = ldate.Format("%#M");
  1346.   _tprintf(_T("Minutes in the current day without leading zeros : %s\n"), s);
  1347.   s = ldate.Format("%#S");
  1348.   _tprintf(_T("Seconds in the current day without leading zeros : %s\n"), s);
  1349.   ldate = CLDate::CurrentTime(UTC);
  1350.   s = ldate.Format();
  1351.   _tprintf(_T("The Current UTC long date is %s\n"), s);
  1352.  
  1353.  
  1354.   //cross the DST marker
  1355.   _tprintf(_T("\n\n"));
  1356.  
  1357.   _tprintf(_T("Some of the following code is designed to cause ASSERTIONS\n"));
  1358.   _tprintf(_T("You can safely press IGNORE. To see why these assertions occur\n"));
  1359.   _tprintf(_T("you should trace into the DTime code\n"));
  1360.   _tprintf(_T("<Hit Enter to continue>\n"));
  1361.   chr = getchar();
  1362.  
  1363.  
  1364.   //you will need to modify these values depending on when your
  1365.   //computer is set to cross the DST marker
  1366.  
  1367.   ldate = CLDate(1996, 3, 31, 0, 10, 0, 0, LOCAL);
  1368.   for (int p=0; p<24; p++)
  1369.   {
  1370.     CLDate OldDate(ldate);
  1371.     s = ldate.Format();
  1372.     _tprintf(_T("%s is "), s);
  1373.     ldate.SetTimeFrame(UTC);
  1374.     s1 = ldate.Format();
  1375.     _tprintf(_T("%s\n"), s1);
  1376.     ldate = OldDate;
  1377.     ldate += CLTimeSpan(0, 0, 10, 0, 0);
  1378.   }
  1379.  
  1380.   ldate = CLDate(1996, 3, 31, 1, 59, 0, 0, LOCAL);  //does occur
  1381.   BOOL bIsDst = ldate.IsDST();
  1382.  
  1383.   ldate = CLDate(1996, 3, 31, 2, 00, 0, 0, LOCAL);  //does occur
  1384.   bIsDst = ldate.IsDST();
  1385.  
  1386.   ldate = CLDate(1996, 3, 31, 2, 01, 0, 0, LOCAL);  //does not occur
  1387.   //bIsDst = ldate.IsDST();    //should assert
  1388.  
  1389.   ldate = CLDate(1996, 3, 31, 2, 30, 0, 0, LOCAL);  //does not occur
  1390.   //bIsDst = ldate.IsDST();    //should assert
  1391.  
  1392.   ldate = CLDate(1996, 3, 31, 3, 00, 0, 0, LOCAL);  //does occur
  1393.   bIsDst = ldate.IsDST();
  1394.  
  1395.   ldate = CLDate(1996, 10, 27, 1, 59, 0, 0, LOCAL);  //does occur
  1396.   bIsDst = ldate.IsDST();
  1397.  
  1398.   ldate = CLDate(1996, 10, 27, 3, 00, 0, 0, LOCAL);  //occurs twice
  1399.   //bIsDst = ldate.IsDST();    //should assert
  1400.  
  1401.   ldate = CLDate(1996, 10, 27, 2, 30, 0, 0, LOCAL);  //occurs twice
  1402.   //bIsDst = ldate.IsDST();    //should assert
  1403.  
  1404.   ldate = CLDate(1996, 10, 27, 2, 59, 0, 0, LOCAL);  //occurs twice
  1405.   //bIsDst = ldate.IsDST();    //should assert
  1406.  
  1407.   ldate = CLDate(1996, 10, 27, 2, 00, 0, 0, LOCAL);  //occurs twice
  1408.   //bIsDst = ldate.IsDST();  //should assert
  1409.  
  1410.   ldate = CLDate(1996, 10, 27, 3, 01, 0, 0, LOCAL);  //does occur
  1411.   bIsDst = ldate.IsDST();
  1412.  
  1413.   ldate = CLDate(1996, 3, 31, 1, 59, 0, 0, UTC);
  1414.   bIsDst = ldate.IsDST();
  1415.   ldate.SetTimeFrame(LOCAL);
  1416.   s = ldate.Format();
  1417.  
  1418.   ldate = CLDate(1996, 3, 31, 2, 00, 0, 0, UTC);
  1419.   bIsDst = ldate.IsDST();
  1420.   ldate.SetTimeFrame(LOCAL);
  1421.   s = ldate.Format();
  1422.  
  1423.   ldate = CLDate(1996, 3, 31, 2, 01, 0, 0, UTC);
  1424.   bIsDst = ldate.IsDST();
  1425.   ldate.SetTimeFrame(LOCAL);
  1426.   s = ldate.Format();
  1427.  
  1428.   ldate = CLDate(1996, 3, 31, 2, 30, 0, 0, UTC);
  1429.   bIsDst = ldate.IsDST();
  1430.   ldate.SetTimeFrame(LOCAL);
  1431.   s = ldate.Format();
  1432.  
  1433.   ldate = CLDate(1996, 3, 31, 2, 59, 0, 0, UTC);
  1434.   bIsDst = ldate.IsDST();
  1435.   ldate.SetTimeFrame(LOCAL);
  1436.   s = ldate.Format();
  1437.   
  1438.   ldate = CLDate(1996, 3, 31, 3, 00, 0, 0, UTC);
  1439.   bIsDst = ldate.IsDST();
  1440.   ldate.SetTimeFrame(LOCAL);
  1441.   s = ldate.Format();
  1442.  
  1443.   ldate = CLDate(1996, 10, 27, 1, 59, 0, 0, UTC);
  1444.   s = ldate.Format();
  1445.   bIsDst = ldate.IsDST();
  1446.   ldate.SetTimeFrame(LOCAL);
  1447.   s = ldate.Format();
  1448.  
  1449.   ldate = CLDate(1996, 10, 27, 2, 00, 0, 0, UTC);
  1450.   bIsDst = ldate.IsDST();
  1451.   ldate.SetTimeFrame(LOCAL);
  1452.   s = ldate.Format();
  1453.  
  1454.   ldate = CLDate(1996, 10, 27, 2, 30, 0, 0, UTC);
  1455.   bIsDst = ldate.IsDST();
  1456.   ldate.SetTimeFrame(LOCAL);
  1457.   s = ldate.Format();
  1458.  
  1459.   ldate = CLDate(1996, 10, 27, 2, 59, 0, 0, UTC);
  1460.   bIsDst = ldate.IsDST();
  1461.   ldate.SetTimeFrame(LOCAL);
  1462.   s = ldate.Format();
  1463.  
  1464.   ldate = CLDate(1996, 10, 27, 3, 00, 0, 0, UTC);
  1465.   bIsDst = ldate.IsDST();
  1466.   ldate.SetTimeFrame(LOCAL);
  1467.   s = ldate.Format();
  1468.  
  1469.   ldate = CLDate(1996, 10, 27, 3, 01, 0, 0, UTC);
  1470.   bIsDst = ldate.IsDST();
  1471.   ldate.SetTimeFrame(LOCAL);
  1472.   s = ldate.Format();
  1473.  
  1474. #if defined(_WINDOWS) || defined(_WIN32)
  1475.   DWORD TimeInterval = GetTickCount() - StartTicks;
  1476.   _tprintf(_T("Time taken to execute program in milliseconds is : %ld\n"), TimeInterval);
  1477. #else                                            
  1478.   time_t TimeInterval = time(NULL) - StartTime;
  1479.   _tprintf(_T("Time taken to execute program in seconds is : %ld\n"), TimeInterval);
  1480. #endif
  1481.  
  1482.   TermDTime();
  1483.   
  1484.   return FALSE;
  1485. }
  1486.