#include <string>
#include <sstream>
#include <iomanip>
#include <ctime>
Go to the source code of this file.
|
AMREX_GPU_HOST AMREX_FORCE_INLINE std::time_t | getEpochTime (const std::string &dateTime, const std::string &dateTimeFormat) |
|
AMREX_FORCE_INLINE std::string | getTimestamp (const amrex::Real epoch_real, const std::string &datetime_format) |
|
◆ getEpochTime()
AMREX_GPU_HOST AMREX_FORCE_INLINE std::time_t getEpochTime |
( |
const std::string & |
dateTime, |
|
|
const std::string & |
dateTimeFormat |
|
) |
| |
18 const char* dt = dateTime.c_str();
19 const char* fmt = dateTimeFormat.c_str();
27 tmTime.tm_year = (dt[0]-
'0')*1000 + (dt[1]-
'0')*100
28 + (dt[2]-
'0')*10 + (dt[3]-
'0');
29 tmTime.tm_year -= 1900;
33 tmTime.tm_mon = (dt[0]-
'0')*10 + (dt[1]-
'0');
38 tmTime.tm_mday = (dt[0]-
'0')*10 + (dt[1]-
'0');
42 tmTime.tm_hour = (dt[0]-
'0')*10 + (dt[1]-
'0');
46 tmTime.tm_min = (dt[0]-
'0')*10 + (dt[1]-
'0');
50 tmTime.tm_sec = (dt[0]-
'0')*10 + (dt[1]-
'0');
67 return timegm(&tmTime);
Referenced by ERF::ReadParameters().
◆ getTimestamp()
AMREX_FORCE_INLINE std::string getTimestamp |
( |
const amrex::Real |
epoch_real, |
|
|
const std::string & |
datetime_format |
|
) |
| |
74 auto epoch_nearest_sec =
static_cast<std::time_t
>(epoch_real);
75 std::tm *time_info = std::gmtime(&epoch_nearest_sec);
78 std::strftime(buffer,
sizeof(buffer), datetime_format.c_str(), time_info);
79 std::string str_nearest_sec(buffer);
81 double frac_sec = epoch_real - epoch_nearest_sec;
82 snprintf(buffer, 80,
"%.6f", frac_sec);
83 AMREX_ASSERT(buffer[0] ==
'0');
84 std::string str_frac_sec(buffer);
86 return str_nearest_sec + str_frac_sec.substr(1);
Referenced by ERF::Evolve().