diff --git a/src/external/nexus/PNeXus.cpp b/src/external/nexus/PNeXus.cpp index 3b1153c6..055030c6 100644 --- a/src/external/nexus/PNeXus.cpp +++ b/src/external/nexus/PNeXus.cpp @@ -73,6 +73,9 @@ #include #include #include +#include +#include +#include #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 diff --git a/src/external/nexus/PNeXus.h b/src/external/nexus/PNeXus.h index 9f9e7f2c..2182022d 100644 --- a/src/external/nexus/PNeXus.h +++ b/src/external/nexus/PNeXus.h @@ -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 /** @@ -2034,9 +2042,9 @@ private: */ std::string findDatasetPath(H5::Group& parent, const std::string& requestedPath); - // ======================================================================== - // Dataset reading helper methods - // ======================================================================== + // ======================================================================== + // Dataset reading helper methods + // ======================================================================== /** * @brief Read an integer dataset and store in data map @@ -2072,6 +2080,6 @@ private: void ReadDatasetAttributes(H5::DataSet& dataset, PNXdata& data); }; -} +} // end namespace nxH5 #endif // _PNEXUS_H_