PSTime/test/testTime.cpp

Go to the documentation of this file.
00001 
00002 /* Test of time methods in class Time */
00003 
00004 #include "PSTime/Time.h"
00005 
00006 #include <iostream>
00007 #include <time.h>
00008 
00009 
00010 using namespace std;
00011 using namespace PSTime;
00012 
00013 int main ()
00014 {
00015   cout << "\n\nTest implementation of the class PSTime\n";
00016   //-------------
00017 
00018   cout << "\n\n\nTest  Time *UTCtime1 = new Time();\n";   
00019   Time *UTCtime1 = new Time();
00020   cout << *UTCtime1 << endl;
00021 
00022   //-------------
00023 
00024 //  cout << "\n\n\nTest getPSTZoneTimeOffsetSec() = " << Time::getPSTZoneTimeOffsetSec() 
00025 //       << " sec = " << UTCtime1 -> getPSTZoneTimeOffsetSec()/3600. << " h.\n";
00026 
00027   //-------------
00028 
00029   cout << "\n\n\nTest Time *UTCtime2 = new Time(*UTCtime1);\n";   
00030   Time *UTCtime2 = new Time(*UTCtime1);
00031   cout << *UTCtime2 << endl;
00032 
00033   //-------------
00034 
00035   cout << "\n\n\nTest Time *UTCtime3 = new Time(UTCtime1->getUTCSec()+10,UTCtime1->getUTCNsec()+10);\n";
00036   Time *UTCtime3 = new Time(UTCtime1->sec()+10,UTCtime1->nsec()+10);
00037   cout << *UTCtime3 << endl;
00038 
00039   //-------------
00040 
00041   cout << "\n\n\nTest Time *UTCtime4 = new Time(year,month,day,hour,min,sec,nsec,zone)";
00042   cout << "\n  for parameters (2010,10,8,17,04,43,123456,Time::UTC);\n";
00043   Time *UTCtime4 = new Time(2010,10,8,17,04,43,123456,Time::UTC);
00044   cout << *UTCtime4 << endl;
00045 
00046   cout << "\n  for parameters (2010,10,8,17,04,43,123456,Time::Local);\n";
00047   Time *UTCtime5 = new Time(2010,10,8,17,04,43,123456,Time::Local);
00048   cout << *UTCtime5 << endl;
00049 
00050   cout << "\n  for parameters (2010,10,8,17,04,43,123456,Time::Local);\n";
00051   Time *UTCtime6 = new Time(2010,10,8,17,04,43,123456,Time::Local);
00052   cout << *UTCtime6 << endl;
00053 
00054   //-------------
00055   struct timespec currentHRTime;
00056   int gettimeStatus = 0;
00057       gettimeStatus = clock_gettime( CLOCK_REALTIME, &currentHRTime );
00058   cout << "\n\n\nTest   Time *UTCtime7 = new Time(currentHRTime);\n";
00059   Time *UTCtime7 = new Time(currentHRTime);
00060   cout << *UTCtime7 << endl;
00061 
00062   //-------------
00063   time_t     local=time(NULL);                // current local time
00064   tm         locTime=*localtime(&local);      // convert local to local, store as tm
00065   tm         utcTime=*gmtime(&local);         // convert local to GMT, store as tm
00066 
00067   cout << "\n\n\nTest   Time *UTCtime8 = new Time(utcTime,Time::UTC);\n";   
00068   Time *UTCtime8 = new Time(utcTime,Time::UTC);
00069   cout << *UTCtime8 << endl;
00070 
00071   //-------------
00072 
00073 //  cout << "\n\nTest UTCtime8->strZoneHuman(Time::UTC)   : " << UTCtime8->strZoneHuman(Time::UTC) << endl ;
00074 //  cout << "\n\nTest UTCtime8->strZoneHuman(Time::Local) : " << UTCtime8->strZoneHuman(Time::Local) << endl ;   
00075 //
00076 //  cout << "\n\nTest UTCtime8->strZoneBasic(Time::UTC)   : " << UTCtime8->strZoneBasic(Time::UTC) << endl ;   
00077 //  cout << "\n\nTest UTCtime8->strZoneBasic(Time::Local) : " << UTCtime8->strZoneBasic(Time::Local) << endl ;
00078 //
00079 //  //-------------
00080 //
00081 //  cout << "\n\nTest UTCtime8->strDateHuman(Time::UTC)   : " << UTCtime8->strDateHuman(Time::UTC) << endl ; 
00082 //  cout << "\n\nTest UTCtime8->strDateHuman(Time::Local) : " << UTCtime8->strDateHuman(Time::Local) << endl ;
00083 //
00084 //  cout << "\n\nTest UTCtime8->strDateBasic(Time::UTC)   : " << UTCtime8->strDateBasic(Time::UTC) << endl ;
00085 //  cout << "\n\nTest UTCtime8->strDateBasic(Time::Local) : " << UTCtime8->strDateBasic(Time::Local) << endl ;
00086 //
00087 //  //-------------
00088 //
00089 //  cout << "\n\nTest UTCtime8->strTimeHuman(Time::UTC)   : " << UTCtime8->strTimeHuman(Time::UTC) << endl ;
00090 //  cout << "\n\nTest UTCtime8->strTimeHuman(Time::Local) : " << UTCtime8->strTimeHuman(Time::Local) << endl ;
00091 //
00092 //  cout << "\n\nTest UTCtime8->strTimeBasic(Time::UTC)   : " << UTCtime8->strTimeBasic(Time::UTC) << endl ;
00093 //  cout << "\n\nTest UTCtime8->strTimeBasic(Time::Local) : " << UTCtime8->strTimeBasic(Time::Local) << endl ;
00094 
00095 //  cout << "\n\nTest UTCtime8->strDateTimeFreeFormat()   : " << UTCtime8->strDateTimeFreeFormat() << endl ;
00096 //  cout << "\n\nTest UTCtime8->strDateTimeFreeFormat(<DateTime format>,Time::Local)   : " <<
00097 //                           UTCtime8->strDateTimeFreeFormat("%B %D %Z %Y%m%d %H:%M:%S",Time::Local) << endl ;
00098 
00099   //-------------
00100 
00101   //Time UTCtime9 = Time::getTimeNow();
00102   
00103   time_t sec  = 1287712731;
00104   time_t nsec = 123456789;
00105   
00106   Time *UTCtime9 = new Time(sec,nsec);
00107   
00108   cout << *UTCtime9 << endl;
00109 //  cout << "\nTest UTCtime9->strNsec(0)  : " << UTCtime9->strNsec(0) << endl ;
00110 //  cout << "\nTest UTCtime9->strNsec(1)  : " << UTCtime9->strNsec(1) << endl ;
00111 //  cout << "\nTest UTCtime9->strNsec(6)  : " << UTCtime9->strNsec(6) << endl ;
00112 //  cout << "\nTest UTCtime9->strNsec(9)  : " << UTCtime9->strNsec(9) << endl ;
00113 //  cout << "\nTest UTCtime9->strNsec(15) : " << UTCtime9->strNsec(15) << endl ;
00114   
00115   //-------------
00116   
00117   cout << "\n\nTest UTCtime9->asStringCompact(Time::Local)   : " << UTCtime9->asStringCompact(Time::Local) << endl ;
00118   cout << "\n\nTest UTCtime9->asStringCompact(Time::Local,5) : " << UTCtime9->asStringCompact(Time::Local,5) << endl ;
00119   cout << "\n\nTest UTCtime9->asStringCompact(Time::Local,0) : " << UTCtime9->asStringCompact(Time::Local,0) << endl ;
00120   
00121   cout << "\n\nTest UTCtime9->asString(Time::Local)   : " << UTCtime9->asString(Time::Local) << endl ;
00122   cout << "\n\nTest UTCtime9->asString(Time::Local,3) : " << UTCtime9->asString(Time::Local,3) << endl ;
00123   cout << "\n\nTest UTCtime9->asString(Time::Local,0) : " << UTCtime9->asString(Time::Local,0) << endl ;
00124   
00125   cout << "\n\nTest UTCtime9->asStringFormat()   : " << UTCtime9->asStringFormat() << endl ; 
00126   cout << "\n\nTest UTCtime9->asStringFormat(<DateTime format>,Time::Local)   : " <<
00127                      UTCtime9->asStringFormat("%Y%m%d %H:%M:%S%.4f%z",Time::Local) << endl ;
00128   
00129 
00130   //-------------  
00131   return 0;
00132   //-------------
00133 }

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7