From: <dd...@us...> - 2003-01-30 03:40:25
|
Update of /cvsroot/babylonlib/_SrcPool/Cpp/Samples/DateTime/Src In directory sc8-pr-cvs1:/tmp/cvs-serv25199/Cpp/Samples/DateTime/Src Modified Files: TsLeapYear.cpp main.cpp Log Message: Update Index: TsLeapYear.cpp =================================================================== RCS file: /cvsroot/babylonlib/_SrcPool/Cpp/Samples/DateTime/Src/TsLeapYear.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TsLeapYear.cpp 28 Jan 2003 05:44:15 -0000 1.1 --- TsLeapYear.cpp 30 Jan 2003 03:40:22 -0000 1.2 *************** *** 1,125 **** ! /*$Workfile: TsLeapYear.cpp$: implementation file ! $Revision$ $Date$ ! $Author$ ! ! Test leap year validation ! Copyright: CommonSoft Inc. ! Jan. 2k2 Darko Kolakovic ! */ ! ! // Group=Examples ! ! /*Note: MS VC/C++ - Disable precompiled headers (/Yu"StdAfx.h" option) */ ! ! #include "KTypedef.h" //LPCTSTR typedef ! #include "KTrace.h" //ASSERT macro ! #include "KTime.h" //IsLeapYear() ! #include "KTChar.h" //TCHAR typedef ! ! extern bool TsWriteToView(LPCTSTR lszText); ! ! //TestLeapYear()------------------------------------------------------------ ! /*Function validates leap years. ! ! Returns: true if successful, otherwise returns false. ! */ ! bool TestLeapYear() ! { ! TsWriteToView(_T("TestLeapYear()\r\n")); ! bool bRes = true; ! const int TESTCOUNT = 19; ! const int ID_HYSTORIC = 0; //Id of Gregorian Calendar results ! const int ID_PROLEPTIC = 1; //Id of Proleptic Gregorian Calendar results ! int iYear[TESTCOUNT] = ! { ! 1996, //00 ! 1609, //01 ! 1500, //02 ! 4000, //03 ! 1800, //04 ! 9250, //05 ! 1900, //06 ! 2000, //07 ! 1388, //08 ! 1582, //09 ! 2002, //10 ! 2004, //11 ! 104, //12 ! 96, //13 ! 4, //14 ! 12, //15 ! 7866, //16 ! -120, //17 ! 0 //18 ! }; ! bool bLeapYear[TESTCOUNT][2] = ! { ! //Hist, Prlp ! true, true, //00 1996, ! false, false,//01 1609, ! true, false,//02 1500, < YEAR_GREGORIAN ! true, true, //03 4000, ! false, false,//04 1800, ! false, false,//05 9250, ! false, false,//06 1900, ! true, true, //07 2000, ! true, true, //08 1388, < YEAR_GREGORIAN ! false, false,//09 1582, = YEAR_GREGORIAN ! false, false,//10 2002, ! true, true, //11 2004, ! true, true, //12 104, < YEAR_GREGORIAN ! true, true, //13 96, < YEAR_GREGORIAN ! true, true, //14 4, < YEAR_GREGORIAN ! true, true, //15 12, < YEAR_GREGORIAN ! false, false,//16 7866, ! true, true, //17 -120, < YEAR_GREGORIAN ! true, true //18 0 < YEAR_GREGORIAN ! }; ! ! TsWriteToView(_T("Proleptic Gregorian Calendar:\r\n")); ! int i = 0; ! while ((i < TESTCOUNT) && bRes) ! { ! ! bRes = (IsLeapYear(iYear[i]) == bLeapYear[i][ID_HYSTORIC]); //Test inline ! if (bRes) ! { ! //Test proleptic macro ! bRes = (IS_LEAP_YEAR(iYear[i]) == bLeapYear[i][ID_PROLEPTIC]); ! } ! ! if (bRes) ! { ! //Proleptic Gregorian Calendar ! TCHAR szYear[8]; ! TsWriteToView(_itot(iYear[i],szYear,10)); ! TsWriteToView(_T(". is ")); ! if (iYear[i] > 0 ) ! { ! //Note: (year&3) is faster (year%4), but vaild only for years > 0 ! if(!((iYear[i] & 3) == 0 && iYear[i] % 100 != 0 || iYear[i] % 400 == 0)) ! TsWriteToView(_T("not")); ! } ! else ! { ! if(!((iYear[i] % 4) == 0 && iYear[i] % 100 != 0 || iYear[i] % 400 == 0)) ! TsWriteToView(_T("not")); ! } ! TsWriteToView(_T(" leap year.\r\n")); ! } ! i++; ! } ! ! TsWriteToView(_T("======================\r\n")); ! return bRes; ! } ! ! /////////////////////////////////////////////////////////////////////////////// ! /***************************************************************************** ! * $Log: ! * 3 Biblioteka1.2 22/01/2003 10:23:23 PMDarko Unicode ! * 2 Biblioteka1.1 20/01/2003 3:15:36 AMDarko Replaced BOOL ! * with bool ! * 1 Biblioteka1.0 15/01/2003 12:29:45 AMDarko ! * $ ! *****************************************************************************/ --- 1,125 ---- ! /*$Workfile: TsLeapYear.cpp$: implementation file ! $Revision$ $Date$ ! $Author$ ! ! Test leap year validation ! Copyright: CommonSoft Inc. ! Jan. 2k2 Darko Kolakovic ! */ ! ! // Group=Examples ! ! /*Note: MS VC/C++ - Disable precompiled headers (/Yu"StdAfx.h" option) */ ! ! #include "KTypedef.h" //LPCTSTR typedef ! #include "KTrace.h" //ASSERT macro ! #include "KTime.h" //IsLeapYear() ! #include "KTChar.h" //TCHAR typedef ! ! extern bool TsWriteToView(LPCTSTR lszText); ! ! //TestLeapYear()------------------------------------------------------------ ! /*Function validates leap years. ! ! Returns: true if successful, otherwise returns false. ! */ ! bool TestLeapYear() ! { ! TsWriteToView(_T("TestLeapYear()\r\n")); ! bool bRes = true; ! const int TESTCOUNT = 19; ! const int ID_HYSTORIC = 0; //Id of Gregorian Calendar results ! const int ID_PROLEPTIC = 1; //Id of Proleptic Gregorian Calendar results ! int iYear[TESTCOUNT] = ! { ! 1996, //00 ! 1609, //01 ! 1500, //02 ! 4000, //03 ! 1800, //04 ! 9250, //05 ! 1900, //06 ! 2000, //07 ! 1388, //08 ! 1582, //09 ! 2002, //10 ! 2004, //11 ! 104, //12 ! 96, //13 ! 4, //14 ! 12, //15 ! 7866, //16 ! -120, //17 ! 0 //18 ! }; ! bool bLeapYear[TESTCOUNT][2] = ! { ! //Hist, Prlp ! true, true, //00 1996, ! false, false,//01 1609, ! true, false,//02 1500, < YEAR_GREGORIAN ! true, true, //03 4000, ! false, false,//04 1800, ! false, false,//05 9250, ! false, false,//06 1900, ! true, true, //07 2000, ! true, true, //08 1388, < YEAR_GREGORIAN ! false, false,//09 1582, = YEAR_GREGORIAN ! false, false,//10 2002, ! true, true, //11 2004, ! true, true, //12 104, < YEAR_GREGORIAN ! true, true, //13 96, < YEAR_GREGORIAN ! true, true, //14 4, < YEAR_GREGORIAN ! true, true, //15 12, < YEAR_GREGORIAN ! false, false,//16 7866, ! true, true, //17 -120, < YEAR_GREGORIAN ! true, true //18 0 < YEAR_GREGORIAN ! }; ! ! TsWriteToView(_T("Proleptic Gregorian Calendar:\r\n")); ! int i = 0; ! while ((i < TESTCOUNT) && bRes) ! { ! ! bRes = (IsLeapYear(iYear[i]) == bLeapYear[i][ID_HYSTORIC]); //Test inline ! if (bRes) ! { ! //Test proleptic macro ! bRes = (IS_LEAP_YEAR(iYear[i]) == bLeapYear[i][ID_PROLEPTIC]); ! } ! ! if (bRes) ! { ! //Proleptic Gregorian Calendar ! TCHAR szYear[8]; ! TsWriteToView(_itot(iYear[i],szYear,10)); ! TsWriteToView(_T(". is ")); ! if (iYear[i] > 0 ) ! { ! //Note: (year&3) is faster (year%4), but vaild only for years > 0 ! if(!((iYear[i] & 3) == 0 && iYear[i] % 100 != 0 || iYear[i] % 400 == 0)) ! TsWriteToView(_T("not")); ! } ! else ! { ! if(!((iYear[i] % 4) == 0 && iYear[i] % 100 != 0 || iYear[i] % 400 == 0)) ! TsWriteToView(_T("not")); ! } ! TsWriteToView(_T(" leap year.\r\n")); ! } ! i++; ! } ! ! TsWriteToView(_T("======================\r\n")); ! return bRes; ! } ! ! /////////////////////////////////////////////////////////////////////////////// ! /***************************************************************************** ! * $Log: ! * 3 Biblioteka1.2 22/01/2003 10:23:23 PMDarko Unicode ! * 2 Biblioteka1.1 20/01/2003 3:15:36 AMDarko Replaced BOOL ! * with bool ! * 1 Biblioteka1.0 15/01/2003 12:29:45 AMDarko ! * $ ! *****************************************************************************/ Index: main.cpp =================================================================== RCS file: /cvsroot/babylonlib/_SrcPool/Cpp/Samples/DateTime/Src/main.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.cpp 28 Jan 2003 05:44:15 -0000 1.1 --- main.cpp 30 Jan 2003 03:40:22 -0000 1.2 *************** *** 1,75 **** ! /*$Workfile: main.cpp$: implementation file ! $Revision$ $Date$ ! $Author$ ! ! Console application used to test various operations with date and time ! Jan. 90 Darko Kolakovic ! */ ! ! // Group=Examples ! ! #ifdef _MSC_VER /*Microsoft Visual Studio C/C++ compiler */ ! #ifndef _CONSOLE ! #error "define _CONSOLE macro in the project" ! #endif ! #endif ! ! #ifdef __GNUG__ /*GNU C++ compiler */ ! #ifndef _CONSOLE ! #warning "define _CONSOLE macro in the project" ! #endif ! #endif ! ! #include <iostream> ! #include <iomanip.h> //std::endl ! #include <string> //std::string ! #include "KTrace.h" //TRACE macro ! #include "KTypedef.h" //BOOL typedef ! ! extern bool TestLeapYear(); ! ! //TsWriteToView()-------------------------------------------------------------- ! /*Writes a character string at the console standard output stream. ! ! Returns: TRUE always. ! ! Note: uses Standard Template Library (STL). ! */ ! BOOL TsWriteToView(LPCTSTR lszText) ! { ! if (lszText != NULL) ! cout << lszText; ! else ! cout << "<null>"; ! cout.flush(); ! return TRUE; ! } ! ! //main()----------------------------------------------------------------------- ! /*Validates different date and time routines. ! ! Returns: EXIT_SUCCESS, which represents a value of 0, if successful. Otherwise ! a non-zero error code is returned. ! */ ! int main() ! { ! cout << "Start Date and Time String " << endl << endl; ! ! if(TestLeapYear()) ! cout << "Succeeded." << endl << endl; ! else ! { ! cout << "Failed!" << endl; ! return EXIT_FAILURE + 1; ! } ! ! ! return EXIT_SUCCESS; ! } ! ! /////////////////////////////////////////////////////////////////////////////// ! /****************************************************************************** ! * $Log: ! * 1 Biblioteka1.0 15/01/2003 12:29:47 AMDarko ! * $ ! *****************************************************************************/ --- 1,75 ---- ! /*$Workfile: main.cpp$: implementation file ! $Revision$ $Date$ ! $Author$ ! ! Console application used to test various operations with date and time ! Jan. 90 Darko Kolakovic ! */ ! ! // Group=Examples ! ! #ifdef _MSC_VER /*Microsoft Visual Studio C/C++ compiler */ ! #ifndef _CONSOLE ! #error "define _CONSOLE macro in the project" ! #endif ! #endif ! ! #ifdef __GNUG__ /*GNU C++ compiler */ ! #ifndef _CONSOLE ! #warning "define _CONSOLE macro in the project" ! #endif ! #endif ! ! #include <iostream> ! #include <iomanip.h> //std::endl ! #include <string> //std::string ! #include "KTrace.h" //TRACE macro ! #include "KTypedef.h" //BOOL typedef ! ! extern bool TestLeapYear(); ! ! //TsWriteToView()-------------------------------------------------------------- ! /*Writes a character string at the console standard output stream. ! ! Returns: TRUE always. ! ! Note: uses Standard Template Library (STL). ! */ ! BOOL TsWriteToView(LPCTSTR lszText) ! { ! if (lszText != NULL) ! cout << lszText; ! else ! cout << "<null>"; ! cout.flush(); ! return TRUE; ! } ! ! //main()----------------------------------------------------------------------- ! /*Validates different date and time routines. ! ! Returns: EXIT_SUCCESS, which represents a value of 0, if successful. Otherwise ! a non-zero error code is returned. ! */ ! int main() ! { ! cout << "Start Date and Time String " << endl << endl; ! ! if(TestLeapYear()) ! cout << "Succeeded." << endl << endl; ! else ! { ! cout << "Failed!" << endl; ! return EXIT_FAILURE + 1; ! } ! ! ! return EXIT_SUCCESS; ! } ! ! /////////////////////////////////////////////////////////////////////////////// ! /****************************************************************************** ! * $Log: ! * 1 Biblioteka1.0 15/01/2003 12:29:47 AMDarko ! * $ ! *****************************************************************************/ |