00001
00002
00003 #include "PSTime/TimeFormat.h"
00004
00005 #include <stdio.h>
00006 #include <time.h>
00007
00008 #include <iostream>
00009 #include <string>
00010
00011 using namespace std;
00012 using namespace PSTime;
00013
00014 int main ()
00015 {
00016
00017 char separationLine[]="----------------------------------";
00018
00019 string time_stamp_human1="2010-11-21 10:58:51.123456789-08:00";
00020 string time_stamp_human2="2010-11-21 10:58:51.123456Z";
00021 string time_stamp_human3="2010-11-21 10:58:51-08:00";
00022 string time_stamp_human4="2010-11-21 10:58:51Z";
00023
00024 string time_stamp_basic1="20101121T105851.12346-0800";
00025 string time_stamp_basic2="20101121T105851.12346Z";
00026 string time_stamp_basic3="20101121T105851-0800";
00027 string time_stamp_basic4="20101121T105851Z";
00028
00029 string time_stamp_mixed1="20101121 105851.55+01";
00030 string time_stamp_mixed2="20101121T10:58:51-0115";
00031 string time_stamp_mixed3="2010-11-21T105851Z";
00032 string time_stamp_mixed4="2010-11-21T105851+0145";
00033
00034
00035
00036 cout << "\n\n\nTest Time test_time1 = new Time();\n";
00037 Time test_time1 ;
00038 cout << test_time1 << endl;
00039
00040
00041 cout << endl << separationLine << endl
00042 << "Test parsification of human-readable time stamps" << endl;
00043
00044 cout << endl << "Parse t-stamp: " << time_stamp_human1 << endl;
00045 test_time1 = TimeFormat::parseTime( time_stamp_human1 );
00046 cout << test_time1 << endl;
00047
00048 cout << endl << "Parse t-stamp: " << time_stamp_human2 << endl;
00049 test_time1 = TimeFormat::parseTime( time_stamp_human2 );
00050 cout << test_time1 << endl;
00051
00052 cout << endl << "Parse t-stamp: " << time_stamp_human3 << endl;
00053 test_time1 = TimeFormat::parseTime( time_stamp_human3 );
00054 cout << test_time1 << endl;
00055
00056 cout << endl << "Parse t-stamp: " << time_stamp_human4 << endl;
00057 test_time1 = TimeFormat::parseTime( time_stamp_human4 );
00058 cout << test_time1 << endl;
00059
00060
00061 cout << endl << separationLine << endl
00062 << "Test parsification of basic-format time stamps" << endl;
00063
00064 cout << endl << "Parse t-stamp: " << time_stamp_basic1 << endl;
00065 test_time1 = TimeFormat::parseTime( time_stamp_basic1 );
00066 cout << test_time1 << endl;
00067
00068 cout << endl << "Parse t-stamp: " << time_stamp_basic2 << endl;
00069 test_time1 = TimeFormat::parseTime( time_stamp_basic2 );
00070 cout << test_time1 << endl;
00071
00072 cout << endl << "Parse t-stamp: " << time_stamp_basic3 << endl;
00073 test_time1 = TimeFormat::parseTime( time_stamp_basic3 );
00074 cout << test_time1 << endl;
00075
00076 cout << endl << "Parse t-stamp: " << time_stamp_basic4 << endl;
00077 test_time1 = TimeFormat::parseTime( time_stamp_basic4 );
00078 cout << test_time1 << endl;
00079
00080
00081 cout << endl << separationLine << endl
00082 << "Test parsification of mixed-format time stamps" << endl;
00083
00084 cout << endl << "Parse t-stamp: " << time_stamp_mixed1 << endl;
00085 test_time1 = TimeFormat::parseTime( time_stamp_mixed1 );
00086 cout << test_time1 << endl;
00087
00088 cout << endl << "Parse t-stamp: " << time_stamp_mixed2 << endl;
00089 test_time1 = TimeFormat::parseTime( time_stamp_mixed2 );
00090 cout << test_time1 << endl;
00091
00092 cout << endl << "Parse t-stamp: " << time_stamp_mixed3 << endl;
00093 test_time1 = TimeFormat::parseTime( time_stamp_mixed3 );
00094 cout << test_time1 << endl;
00095
00096 cout << endl << "Parse t-stamp: " << time_stamp_mixed4 << endl;
00097 test_time1 = TimeFormat::parseTime( time_stamp_mixed4 );
00098 cout << test_time1 << endl;
00099
00100
00101 cout << endl << separationLine << endl
00102 << "Test parsification of other mixed-format time stamps" << endl;
00103
00104 cout << endl << "Parse t-stamp: " << "20101121 105851" << endl;
00105 test_time1 = TimeFormat::parseTime( "20101121 105851" );
00106 cout << test_time1 << endl;
00107
00108 cout << endl << "Parse t-stamp: " << "20101121T105851.33" << endl;
00109 test_time1 = TimeFormat::parseTime( "20101121T105851.33" );
00110 cout << test_time1 << endl;
00111
00112 cout << endl << "Parse t-stamp: " << "20101121 105851.33+01" << endl;
00113 test_time1 = TimeFormat::parseTime( "20101121 105851.33+01" );
00114 cout << test_time1 << endl;
00115
00116 cout << endl << separationLine << endl;
00117
00118
00119
00120 cout << endl << separationLine << endl
00121 << "Test constructor with string parsification" << endl;
00122
00123 cout << endl << "Parse t-stamp: " << time_stamp_human1 << endl;
00124 Time time_pars1( time_stamp_human1);
00125 cout << time_pars1 << endl;
00126
00127 cout << endl << "Parse t-stamp: " << time_stamp_basic1 << endl;
00128 Time time_pars2( time_stamp_basic1);
00129 cout << time_pars2 << endl;
00130
00131
00132 cout << endl << separationLine << endl;
00133
00134
00135 return 0;
00136
00137 }