00001 #pragma ident "$Id: daytimetest.cpp 1895 2009-05-12 19:34:29Z afarris $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <iostream>
00030
00031 #include "StringUtils.hpp"
00032 #include "DayTime.hpp"
00033 #include "GPSZcount.hpp"
00034
00035 using namespace std;
00036 using namespace gpstk::StringUtils;
00037
00039 void dtft(ostream& s, const gpstk::DayTime& t, const string& fmt)
00040 {
00041 string fs = fmt;
00042 string p = t.printf(fmt.c_str());
00043
00044 s << leftJustify(fs, 30) << " "
00045 << p << endl;
00046 }
00047
00049 int main()
00050 {
00051 using gpstk::DayTime;
00052
00053 try
00054 {
00055 cout << "BOT:" << DayTime(gpstk::DayTime::BEGINNING_OF_TIME) << endl;
00056 cout << "EOT:" << DayTime(gpstk::DayTime::END_OF_TIME) << endl;
00057
00058 DayTime dt;
00059 dt.setSystemTime();
00060 cout << "Check that the output matches the current UTC time." << endl
00061 << "string printf()" << endl;
00062
00063 dtft(cout, dt, "mjd: %Q (%.0Q)");
00064 dtft(cout, dt, "mjd: %5.3Q");
00065 dtft(cout, dt, "mdy: %02m/%02d/%04Y");
00066 dtft(cout, dt, "hms: %02H:%02M:%02S");
00067 dtft(cout, dt, "hms: %02H:%02M:%06.3f");
00068 dtft(cout, dt, "cal: %A, %B %d, %Y");
00069 dtft(cout, dt, "week: %F(%G)");
00070 dtft(cout, dt, "sow: %g");
00071 dtft(cout, dt, "sow: %06.3g");
00072 dtft(cout, dt, "doy: %j:%s");
00073 dtft(cout, dt, "dow: %w");
00074 dtft(cout, dt, "z: %Z (%z)");
00075 dtft(cout, dt, "unix: %U.%06u");
00076
00077 cout << endl
00078 << "The following functions use DayTime::setToString()" << endl;
00079
00080 string format = "%02m/%02d/%04Y %02H:%02M:%02S";
00081 string st = dt.printf(format);
00082
00083 DayTime q;
00084 q.setToString(st, format);
00085 dtft(cout, q, format);
00086
00087 cout << "Tests complete." << endl;
00088 return 0;
00089 }
00090 catch(gpstk::Exception& e)
00091 {
00092 cout << e << endl;
00093 }
00094 catch(...)
00095 {
00096 cout << "Some other exception thrown..." << endl;
00097 }
00098
00099 cout << "Exiting with exceptions." << endl;
00100 return -1;
00101 }