Skip to content

Commit afc97c7

Browse files
Don't throw in GetTime{Millis,Micros}(). Mark as noexcept.
1 parent 76ae7a1 commit afc97c7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/util/time.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ int64_t GetMockTime()
3737
return nMockTime.load(std::memory_order_relaxed);
3838
}
3939

40-
int64_t GetTimeMillis()
40+
int64_t GetTimeMillis() noexcept
4141
{
42+
static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
4243
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
43-
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
44+
epoch).total_milliseconds();
4445
assert(now > 0);
4546
return now;
4647
}
4748

48-
int64_t GetTimeMicros()
49+
int64_t GetTimeMicros() noexcept
4950
{
51+
static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
5052
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
51-
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
53+
epoch).total_microseconds();
5254
assert(now > 0);
5355
return now;
5456
}

src/util/time.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121

2222
int64_t GetTime();
23-
int64_t GetTimeMillis();
24-
int64_t GetTimeMicros();
23+
int64_t GetTimeMillis() noexcept;
24+
int64_t GetTimeMicros() noexcept;
2525
int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable
2626
void SetMockTime(int64_t nMockTimeIn);
2727
int64_t GetMockTime();

0 commit comments

Comments
 (0)