Skip to content

Commit 34e02e0

Browse files
committed
Merge pull request #7094
1bb289f Assert now > 0 in GetTime GetTimeMillis GetTimeMicros (Patick Strateman)
2 parents eb77416 + 1bb289f commit 34e02e0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/utiltime.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ int64_t GetTime()
2020
{
2121
if (nMockTime) return nMockTime;
2222

23-
return time(NULL);
23+
time_t now = time(NULL);
24+
assert(now > 0);
25+
return now;
2426
}
2527

2628
void SetMockTime(int64_t nMockTimeIn)
@@ -30,14 +32,18 @@ void SetMockTime(int64_t nMockTimeIn)
3032

3133
int64_t GetTimeMillis()
3234
{
33-
return (boost::posix_time::microsec_clock::universal_time() -
34-
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
35+
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
36+
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
37+
assert(now > 0);
38+
return now;
3539
}
3640

3741
int64_t GetTimeMicros()
3842
{
39-
return (boost::posix_time::microsec_clock::universal_time() -
40-
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
43+
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
44+
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
45+
assert(now > 0);
46+
return now;
4147
}
4248

4349
/** Return a time useful for the debug log */

0 commit comments

Comments
 (0)