add a function in the NeXus lib which gives the time in ISO8601.
This commit is contained in:
26
src/external/nexus/PNeXus.cpp
vendored
26
src/external/nexus/PNeXus.cpp
vendored
@@ -73,6 +73,9 @@
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
|
||||
#include "Minuit2/MnStrategy.h"
|
||||
#include "Minuit2/MnMinimize.h"
|
||||
@@ -130,6 +133,29 @@ nxs::HDFType nxs::checkHDFType(const std::string& filename) {
|
||||
return nxs::HDFType::Unknown;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// nxs::getIso8601TimestampLocal - current time stamp in ISO8601 format
|
||||
//=============================================================================
|
||||
std::string nxs::getIso8601TimestampLocal() {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
|
||||
std::tm* local_tm = std::localtime(&now_c);
|
||||
|
||||
// Get timezone offset
|
||||
char tz_offset[10];
|
||||
std::strftime(tz_offset, sizeof(tz_offset), "%z", local_tm);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << std::put_time(local_tm, "%Y-%m-%dT%H:%M:%S");
|
||||
|
||||
// Insert colon in timezone offset: +0100 → +01:00
|
||||
std::string tz_str(tz_offset);
|
||||
tz_str.insert(3, ":");
|
||||
oss << tz_str;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
#ifdef HAVE_HDF4
|
||||
//=============================================================================
|
||||
// nxH4::PNeXusDeadTime Constructor
|
||||
|
||||
12
src/external/nexus/PNeXus.h
vendored
12
src/external/nexus/PNeXus.h
vendored
@@ -181,6 +181,14 @@ enum class HDFType {
|
||||
*/
|
||||
HDFType checkHDFType(const std::string& filename);
|
||||
|
||||
/**
|
||||
* @brief get the current time and return it as na IOS8601
|
||||
* time stamp.
|
||||
*
|
||||
* @return ISO 8601 time stamp string
|
||||
*/
|
||||
std::string getIso8601TimestampLocal();
|
||||
|
||||
} // end namespace nxs
|
||||
|
||||
#ifdef HAVE_HDF4
|
||||
@@ -1089,7 +1097,7 @@ private:
|
||||
static int32 convertToHdf4Type(H4DataType dataType);
|
||||
};
|
||||
|
||||
}
|
||||
} // end namespace nxH4
|
||||
#endif // HAVE_HDF4
|
||||
|
||||
/**
|
||||
@@ -2072,6 +2080,6 @@ private:
|
||||
void ReadDatasetAttributes(H5::DataSet& dataset, PNXdata<T>& data);
|
||||
};
|
||||
|
||||
}
|
||||
} // end namespace nxH5
|
||||
|
||||
#endif // _PNEXUS_H_
|
||||
|
||||
Reference in New Issue
Block a user