1 #ifndef ERF_EPOCH_TIME_H_
2 #define ERF_EPOCH_TIME_H_
11 #define timegm _mkgmtime
14 AMREX_GPU_HOST AMREX_FORCE_INLINE
20 for (
int idx = 0; idx < width; ++idx) {
21 unsigned char ch =
static_cast<unsigned char>(dt[idx]);
22 if (ch ==
'\0' || !std::isdigit(ch)) {
32 AMREX_GPU_HOST AMREX_FORCE_INLINE
34 getEpochTime (
const std::string& dateTime,
const std::string& dateTimeFormat)
37 const char* dt = dateTime.c_str();
38 const char* fmt = dateTimeFormat.c_str();
48 tmTime.tm_year = parsed_value;
49 tmTime.tm_year -= 1900;
53 tmTime.tm_mon = parsed_value;
58 tmTime.tm_mday = parsed_value;
62 tmTime.tm_hour = parsed_value;
66 tmTime.tm_min = parsed_value;
70 tmTime.tm_sec = parsed_value;
86 if (*fmt !=
'\0' || *dt !=
'\0') {
90 if (tmTime.tm_mon < 0 || tmTime.tm_mon > 11 ||
91 tmTime.tm_mday < 1 || tmTime.tm_mday > 31 ||
92 tmTime.tm_hour < 0 || tmTime.tm_hour > 23 ||
93 tmTime.tm_min < 0 || tmTime.tm_min > 59 ||
94 tmTime.tm_sec < 0 || tmTime.tm_sec > 60) {
98 return timegm(&tmTime);
105 auto epoch_nearest_sec =
static_cast<std::time_t
>(epoch_real);
106 std::tm *time_info = std::gmtime(&epoch_nearest_sec);
109 std::strftime(buffer,
sizeof(buffer), datetime_format.c_str(), time_info);
110 std::string str_nearest_sec(buffer);
115 double frac_sec = std::abs(epoch_real - epoch_nearest_sec);
116 snprintf(buffer, 80,
"%.6f", frac_sec);
117 AMREX_ASSERT(buffer[0] ==
'0');
118 std::string str_frac_sec(buffer);
119 return str_nearest_sec + str_frac_sec.substr(1);
121 return str_nearest_sec;
AMREX_GPU_HOST AMREX_FORCE_INLINE std::time_t getEpochTime(const std::string &dateTime, const std::string &dateTimeFormat)
Definition: ERF_EpochTime.H:34
AMREX_GPU_HOST AMREX_FORCE_INLINE bool parse_fixed_width_int(const char *&dt, int width, int &value)
Definition: ERF_EpochTime.H:16
AMREX_FORCE_INLINE std::string getTimestamp(const amrex::Real epoch_real, const std::string &datetime_format, bool add_long_frac=true)
Definition: ERF_EpochTime.H:103
amrex::Real value
Definition: ERF_HurricaneDiagnostics.H:20
amrex::Real Real
Definition: ERF_ShocInterface.H:19