diff --git a/src/timer.cpp b/src/timer.cpp index 288ac28f43..c6f6401799 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -28,8 +28,8 @@ Timer::Timer(LAMMPS *_lmp) : Pointers(_lmp) { _level = NORMAL; _sync = OFF; - _timeout = -1; - _s_timeout = -1; + _timeout = -1.0; + _s_timeout = -1.0; _checkfreq = 10; _nextcheck = -1; this->_stamp(RESET); @@ -251,7 +251,7 @@ void Timer::modify_params(int narg, char **arg) // format timeout setting std::string timeout = "off"; - if (_timeout >= 0) { + if (_timeout >= 0.0) { std::tm tv = fmt::gmtime((std::time_t) _timeout); timeout = fmt::format("{:02d}:{:%M:%S}", tv.tm_yday * 24 + tv.tm_hour, tv); } diff --git a/src/timer.h b/src/timer.h index f7efa5ac64..371a895d1f 100644 --- a/src/timer.h +++ b/src/timer.h @@ -110,12 +110,12 @@ class Timer : protected Pointers { double previous_cpu; double previous_wall; double timeout_start; - int _level; // level of detail: off=0,loop=1,normal=2,full=3 - int _sync; // if nonzero, synchronize tasks before setting the timer - int _timeout; // max allowed wall time in seconds. infinity if negative - int _s_timeout; // copy of timeout for restoring after a forced timeout - int _checkfreq; // frequency of timeout checking - int _nextcheck; // loop number of next timeout check + double _timeout; // max allowed wall time in seconds. infinity if negative + double _s_timeout; // copy of timeout for restoring after a forced timeout + int _level; // level of detail: off=0,loop=1,normal=2,full=3 + int _sync; // if nonzero, synchronize tasks before setting the timer + int _checkfreq; // frequency of timeout checking + int _nextcheck; // loop number of next timeout check // update one specific timer array void _stamp(enum ttype); diff --git a/src/utils.cpp b/src/utils.cpp index c760f9ffbf..87c46c47ab 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1677,7 +1677,7 @@ double utils::timespec2seconds(const std::string ×pec) try { for (i = 0; i < 3; i++) { if (!values.has_next()) break; - vals[i] = values.next_int(); + vals[i] = values.next_double(); } } catch (TokenizerException &) { return -1.0; diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 58940f6600..c486d0cf3e 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -1061,6 +1061,16 @@ TEST(Utils, timespec2seconds_hhmmss) ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:10:45"), 7845.0); } +TEST(Utils, timespec2seconds_ssfraction) +{ + ASSERT_DOUBLE_EQ(utils::timespec2seconds("5.2"), 5.2); +} + +TEST(Utils, timespec2seconds_mmfraction) +{ + ASSERT_DOUBLE_EQ(utils::timespec2seconds("2.5:10"), 160.0); +} + TEST(Utils, timespec2seconds_invalid) { ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:aa:45"), -1.0);