Commit b3096d5d566bde95a61215c5969cbfcceb9c23e2
1 parent
61bdda87
Exists in
master
and in
67 other branches
correcting time iso with z
Showing
6 changed files
with
78 additions
and
13 deletions
Show diff stats
src/Common/OutputFormatTime.hh
... | ... | @@ -19,6 +19,7 @@ namespace AMDA { |
19 | 19 | enum OutputFormatTime { |
20 | 20 | FORMAT_OUTPUT_TIME_DD, ///< DD_server style |
21 | 21 | FORMAT_OUTPUT_TIME_ISO, ///< ISO STYLE AAAA-MM-JJTHH:MM:ss.msd |
22 | + FORMAT_OUTPUT_TIME_ISO_Z, ///< ISO STYLE AAAA-MM-JJTHH:MM:ss.msd | |
22 | 23 | FORMAT_OUTPUT_TIME_DOUBLE, ///< in second; stating from 1970 |
23 | 24 | FORMAT_OUTPUT_TIME_SPACES, /// < YYYY MM DD hh mm ss |
24 | 25 | FORMAT_OUTPUT_TIME_MS, /// < Double with milliseconds |
... | ... | @@ -27,6 +28,7 @@ enum OutputFormatTime { |
27 | 28 | static std::map<OutputFormatTime,std::string> ouputFormatTimeToStr = { |
28 | 29 | {OutputFormatTime::FORMAT_OUTPUT_TIME_DD, "DD Time"}, |
29 | 30 | {OutputFormatTime::FORMAT_OUTPUT_TIME_ISO, "ISO 8601"}, |
31 | + {OutputFormatTime::FORMAT_OUTPUT_TIME_ISO_Z, "ISO 8601Z"}, | |
30 | 32 | {OutputFormatTime::FORMAT_OUTPUT_TIME_DOUBLE, "Seconds from 1970"}, |
31 | 33 | {OutputFormatTime::FORMAT_OUTPUT_TIME_SPACES, "YYYY MM DD hh mm ss"}, |
32 | 34 | {OutputFormatTime::FORMAT_OUTPUT_TIME_MS, "Seconds from 1970, milliseconds"}, | ... | ... |
src/TTConversion/TTConversionLauncher.cc
... | ... | @@ -43,8 +43,8 @@ int ttConversion(int argc, char *argv[], AMDA::helpers::Properties& /*properties |
43 | 43 | } |
44 | 44 | |
45 | 45 | // Default value for time format (Option) |
46 | - AMDA::OutputFormatTime timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO; | |
47 | - if (argc >= 7) { | |
46 | + AMDA::OutputFormatTime timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO; | |
47 | + if (argc >= 7) { | |
48 | 48 | // Map time enum between php and C++ |
49 | 49 | // See Request/TTRequestImpl/TTRequestDataClass.php and AMDA_Kernel/src/Common/OutputFormatTime.hh |
50 | 50 | const string pTimeFormat = argv[6]; |
... | ... | @@ -53,12 +53,15 @@ int ttConversion(int argc, char *argv[], AMDA::helpers::Properties& /*properties |
53 | 53 | else if (pTimeFormat.compare("SPACES") == 0) timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_SPACES; |
54 | 54 | else if (pTimeFormat.compare("MS") == 0) timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_MS; |
55 | 55 | } |
56 | - | |
57 | - TimeTableCatalog::TimeTable ttMgr(timeFormat); | |
56 | + const string ttFormat = argv[5]; | |
57 | + if(ttFormat.compare("SPACE") ==0) | |
58 | + timeFormat= AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO_Z; | |
59 | + | |
60 | + TimeTableCatalog::TimeTable ttMgr(timeFormat); | |
58 | 61 | |
59 | - ttMgr.convert(std::string(argv[1]), std::string(argv[2]), std::string(argv[3]), std::string(argv[4]), std::string(argv[5])); | |
60 | - | |
61 | - return 0; | |
62 | + ttMgr.convert(std::string(argv[1]), std::string(argv[2]), std::string(argv[3]), std::string(argv[4]), std::string(argv[5])); | |
63 | + | |
64 | + return 0; | |
62 | 65 | } |
63 | 66 | |
64 | 67 | /** | ... | ... |
src/TimeTableCatalog/SpaceWriter.cc
... | ... | @@ -72,7 +72,7 @@ void SpaceWriter::writeMetaData(const TimeTable& pTT, |
72 | 72 | |
73 | 73 | // -- write creation date |
74 | 74 | pOut << "# " << SpaceData::CREATION_DATE_KEYWORD << " "; |
75 | - writeISOTime(pTT._creationDate, pTT._timeFormat, pOut); | |
75 | + writeTimeData(pTT._creationDate, pTT._extTimeFormat, pOut); | |
76 | 76 | pOut << std::endl; |
77 | 77 | |
78 | 78 | // -- write modify date |
... | ... | @@ -80,7 +80,7 @@ void SpaceWriter::writeMetaData(const TimeTable& pTT, |
80 | 80 | if(pTT._modificationDate == 0){ |
81 | 81 | pOut <<"0001-01-01T00:00:00:00.000Z"; |
82 | 82 | }else{ |
83 | - writeISOTime(pTT._modificationDate, pTT._timeFormat, pOut); | |
83 | + writeTimeData(pTT._modificationDate, pTT._extTimeFormat, pOut); | |
84 | 84 | } |
85 | 85 | pOut << std::endl; |
86 | 86 | |
... | ... | @@ -120,7 +120,7 @@ void SpaceWriter::writeMetaData(const TimeTable& pTT, |
120 | 120 | if(pTT._listStartDate == 0){ |
121 | 121 | pOut <<"0001-01-01T00:00:00:00.000Z"; |
122 | 122 | }else{ |
123 | - writeISOTime(pTT._listStartDate, pTT._timeFormat, pOut); | |
123 | + writeTimeData(pTT._listStartDate, pTT._extTimeFormat, pOut); | |
124 | 124 | } |
125 | 125 | pOut << std::endl; |
126 | 126 | |
... | ... | @@ -129,7 +129,7 @@ void SpaceWriter::writeMetaData(const TimeTable& pTT, |
129 | 129 | if(pTT._listStopDate == 0){ |
130 | 130 | pOut <<"0001-01-01T00:00:00:00.000Z"; |
131 | 131 | }else{ |
132 | - writeISOTime(pTT._listStopDate, pTT._timeFormat, pOut); | |
132 | + writeTimeData(pTT._listStopDate, pTT._extTimeFormat, pOut); | |
133 | 133 | } |
134 | 134 | pOut << std::endl; |
135 | 135 | |
... | ... | @@ -145,7 +145,8 @@ void SpaceWriter::writeMetaData(const TimeTable& pTT, |
145 | 145 | for (auto line : pTT._description) { |
146 | 146 | pOut << "# " << line << std::endl; |
147 | 147 | } |
148 | - pOut << pTT._history << std::endl; | |
148 | + if(! pTT._history.empty()) | |
149 | + pOut << "# " << pOut << pTT._history << std::endl; | |
149 | 150 | |
150 | 151 | // repeat variable names |
151 | 152 | pOut << "# " << "t_begin" <<" "<< "t_end"<<" "; | ... | ... |
src/TimeTableCatalog/TimeTableCatalogUtil.cc
... | ... | @@ -259,6 +259,10 @@ void writeTimeData(const double pTime, const AMDA::OutputFormatTime pFormat, std |
259 | 259 | AMDA::TimeUtil::formatTimeDateInIso(pTime, os); |
260 | 260 | pOut << os.str(); |
261 | 261 | break; |
262 | + case AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO_Z: | |
263 | + AMDA::TimeUtil::formatTimeDateInIsoZ(pTime, os); | |
264 | + pOut << os.str(); | |
265 | + break; | |
262 | 266 | case AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_DD: |
263 | 267 | AMDA::TimeUtil::double2DD_TimeDate(pTime, pOut); |
264 | 268 | pOut << os.str(); | ... | ... |
src/TimeUtil/TimeUtil.cc
... | ... | @@ -49,6 +49,49 @@ void TimeUtil::formatTimeInIso(const double time, std::ostream& pOs, t_DDTimeKin |
49 | 49 | << "." << std::setw(3) << tm.msec; |
50 | 50 | } |
51 | 51 | |
52 | +void TimeUtil::formatTimeInIsoWithoutMs(const double time, std::ostream& pOs, t_DDTimeKind timeKind) { | |
53 | + | |
54 | + | |
55 | + dd_tmstr_t tm; | |
56 | + int visocos; | |
57 | + | |
58 | + tm.times = time; | |
59 | + SetIntNew(&tm, timeKind); | |
60 | + if (((tm.year & 3) == 0)&&(((tm.year % 100) != 0)||((tm.year % 400)==0))) visocos = 1; else visocos = 0; | |
61 | + int month = 0; | |
62 | + while((month < 12) && (tm.day >= monthday[visocos][month])) month++; | |
63 | + | |
64 | + | |
65 | + | |
66 | + int day = tm.day +1 - monthday[visocos][month-1]; | |
67 | + pOs << std::setfill('0') << tm.year << "-" << std::setw(2) | |
68 | + << std::right << month << "-" << std::setw(2) << std::right << day | |
69 | + << "T" << std::setw(2) << std::right << tm.hour << ":" | |
70 | + << std::setw(2) << std::right << tm.min << ":" << std::setw(2) <<tm.sec; | |
71 | +} | |
72 | + | |
73 | +void TimeUtil::formatTimeInIsoZ(const double time, std::ostream& pOs, t_DDTimeKind timeKind) { | |
74 | + | |
75 | + | |
76 | + dd_tmstr_t tm; | |
77 | + int visocos; | |
78 | + | |
79 | + tm.times = time; | |
80 | + SetIntNew(&tm, timeKind); | |
81 | + if (((tm.year & 3) == 0)&&(((tm.year % 100) != 0)||((tm.year % 400)==0))) visocos = 1; else visocos = 0; | |
82 | + int month = 0; | |
83 | + while((month < 12) && (tm.day >= monthday[visocos][month])) month++; | |
84 | + | |
85 | + | |
86 | + | |
87 | + int day = tm.day +1 - monthday[visocos][month-1]; | |
88 | + pOs << std::setfill('0') << tm.year << "-" << std::setw(2) | |
89 | + << std::right << month << "-" << std::setw(2) << std::right << day | |
90 | + << "T" << std::setw(2) << std::right << tm.hour << ":" | |
91 | + << std::setw(2) << std::right << tm.min << ":" << std::setw(2) <<tm.sec | |
92 | + << "." << std::setw(3) << tm.msec<<"Z"; | |
93 | +} | |
94 | + | |
52 | 95 | double TimeUtil::readTimeInIso(char *Stime) { |
53 | 96 | |
54 | 97 | dd_tmstr_t *UT; | ... | ... |
src/TimeUtil/TimeUtil.hh
... | ... | @@ -23,10 +23,22 @@ class TimeUtil { |
23 | 23 | virtual ~TimeUtil(); |
24 | 24 | public: |
25 | 25 | static void formatTimeInIso(const double time, std::ostream& pOs, t_DDTimeKind timeKind); |
26 | - | |
26 | + | |
27 | + static void formatTimeInIsoWithoutMs(const double time, std::ostream& pOs, t_DDTimeKind timeKind); | |
28 | + | |
29 | + static void formatTimeInIsoZ(const double time, std::ostream& pOs, t_DDTimeKind timeKind); | |
30 | + | |
27 | 31 | static void formatTimeDateInIso(const double time, std::ostream& pOs) { |
28 | 32 | formatTimeInIso(time, pOs, DD_TM_DATE); |
29 | 33 | } |
34 | + | |
35 | + static void formatTimeDateInIsoWithoutMs(const double time, std::ostream& pOs) { | |
36 | + formatTimeInIsoWithoutMs(time, pOs, DD_TM_DATE); | |
37 | + } | |
38 | + | |
39 | + static void formatTimeDateInIsoZ(const double time, std::ostream& pOs) { | |
40 | + formatTimeInIsoZ(time, pOs, DD_TM_DATE); | |
41 | + } | |
30 | 42 | static void formatTimeIntervalInIso(const double time, std::ostream& pOs) { |
31 | 43 | formatTimeInIso(time, pOs, DD_TM_TIME_INTERVAL); |
32 | 44 | } | ... | ... |