@@ -288,7 +288,7 @@ string Version::getAppFullInfo(bool csv) {
288288 if (!csv) {
289289 out << " Compile Time: " ;
290290 }
291- out << __DATE__ << " " << __TIME__ ;
291+ out << getCompilationDateTime (csv) ;
292292 out << commaOrLineBreak ();
293293
294294 if (!csv) {
@@ -349,3 +349,39 @@ string Version::getBackend() {
349349#endif
350350 ;
351351}
352+
353+ string Version::getCompilationDateTime (const bool csv) {
354+ if (csv) {
355+ try {
356+ // Try to return date-time in the following format (completely numeric): YYYY-MM-DD-HH-MM-SS
357+ const vector<std::string> dateStrs = Global::split (__DATE__);
358+ const vector<std::string> timeStrs = Global::split (__TIME__, ' :' );
359+
360+ const int year = Global::stringToInt (dateStrs[2 ]);
361+
362+ static const vector<string> months = {
363+ " Jan" ," Feb" ," Mar" ," Apr" ," May" ," Jun" ," Jul" ," Aug" ," Sep" ," Oct" ," Nov" ," Dec"
364+ };
365+ const size_t monthIndex = indexOf (months, dateStrs[0 ]);
366+ if (monthIndex == std::string::npos) throw std::runtime_error (" Invalid month" );
367+
368+ const int day = Global::stringToInt (dateStrs[1 ]);
369+
370+ const int hour = Global::stringToInt (timeStrs[0 ]);
371+
372+ const int minute = Global::stringToInt (timeStrs[1 ]);
373+
374+ const int second = Global::stringToInt (timeStrs[2 ]);
375+
376+ std::string out;
377+ out.resize (19 ); // "YYYY-MM-DD-hh-mm-ss" = 19 chars
378+ std::snprintf (out.data (), out.size () + 1 ,
379+ " %04d-%02d-%02d-%02d-%02d-%02d" ,
380+ year, static_cast <int >(monthIndex) + 1 , day, hour, minute, second);
381+ return out;
382+ } catch (const std::exception& _) {
383+ }
384+ }
385+
386+ return string (__DATE__) + " " + string (__TIME__);
387+ }
0 commit comments