1 #ifndef ERF_EPOCH_TIME_H_
2 #define ERF_EPOCH_TIME_H_
10 #define timegm _mkgmtime
14 std::time_t
getEpochTime(
const std::string& dateTime,
const std::string& dateTimeFormat) {
19 if (sscanf(dateTime.c_str(),
"%d-%d-%d_%d:%d:%dUTC",
20 &tmTime.tm_year, &tmTime.tm_mon, &tmTime.tm_mday,
21 &tmTime.tm_hour, &tmTime.tm_min, &tmTime.tm_sec) != 6) {
26 tmTime.tm_year -= 1900;
30 return timegm(&tmTime);
35 getTimestamp (
const amrex::Real epoch_real,
const std::string& datetime_format)
37 auto epoch_nearest_sec =
static_cast<std::time_t
>(epoch_real);
38 std::tm *time_info = std::gmtime(&epoch_nearest_sec);
41 std::strftime(buffer,
sizeof(buffer), datetime_format.c_str(), time_info);
42 std::string str_nearest_sec(buffer);
44 double frac_sec = epoch_real - epoch_nearest_sec;
45 snprintf(buffer, 80,
"%.6f", frac_sec);
46 AMREX_ASSERT(buffer[0] ==
'0');
47 std::string str_frac_sec(buffer);
49 return str_nearest_sec + str_frac_sec.substr(1);
AMREX_FORCE_INLINE std::time_t getEpochTime(const std::string &dateTime, const std::string &dateTimeFormat)
Definition: ERF_EpochTime.H:14
AMREX_FORCE_INLINE std::string getTimestamp(const amrex::Real epoch_real, const std::string &datetime_format)
Definition: ERF_EpochTime.H:35