00001 #pragma ident "$Id: CommandOptionWithTimeArg.cpp 274 2006-10-27 14:24:35Z rickmach $"
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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00051 #include "StringUtils.hpp"
00052 #include "CommandOptionWithTimeArg.hpp"
00053
00054 using namespace std;
00055
00056 namespace gpstk
00057 {
00058 string CommandOptionWithTimeArg :: checkArguments()
00059 {
00060 string errstr = CommandOptionWithAnyArg::checkArguments();
00061
00062 if (errstr != string())
00063 return errstr;
00064
00065 vector<string>::size_type vecindex;
00066 for(vecindex = 0; vecindex < value.size(); vecindex++)
00067 {
00068 string thisTimeSpec = getTimeSpec(vecindex);
00069 if (thisTimeSpec != string())
00070 {
00071 try {
00072 DayTime dt;
00073 dt.setToString(value[vecindex], thisTimeSpec);
00074 times.push_back(dt);
00075 }
00076 catch (...)
00077 {
00078 errstr += "\"" + value[vecindex] + "\" is not a valid time.";
00079 }
00080 }
00081 else
00082 errstr += "\"" + value[vecindex] + "\" is not a valid time.";
00083 }
00084
00085 return errstr;
00086 }
00087
00088 string CommandOptionWithSimpleTimeArg :: getTimeSpec
00089 (vector<string>::size_type index) const
00090 {
00091 int numwords = gpstk::StringUtils::numWords(value[index]);
00092 string thisTimeSpec;
00093 switch (numwords)
00094 {
00095 case 1:
00096 thisTimeSpec = "%m/%d/%Y";
00097 break;
00098 case 2:
00099 thisTimeSpec = "%Y %j";
00100 break;
00101 case 3:
00102 thisTimeSpec = "%Y %j %s";
00103 break;
00104 }
00105
00106 return thisTimeSpec;
00107 }
00108
00109 }