Skip to content

Commit 3e865ef

Browse files
committed
util: Add GetTimeMillis convenience wrapper for chrono timestamps
Add a convenience wrapper function for obtaining the current system time in milliseconds. This uses the modern std::chrono library internally while providing a shorter, more readable interface for code that needs millisecond precision timestamps. This improves code readability in areas like the TrafficGraphWidget that work with millisecond timestamps while maintaining compatibility with Bitcoin Core's move toward using std::chrono-based time handling.
1 parent 12509d0 commit 3e865ef

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/util/time.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ std::chrono::seconds GetMockTime()
5858

5959
int64_t GetTime() { return GetTime<std::chrono::seconds>().count(); }
6060

61+
int64_t GetTimeMillis()
62+
{
63+
return std::chrono::duration_cast<std::chrono::milliseconds>(
64+
std::chrono::system_clock::now().time_since_epoch()
65+
).count();
66+
}
67+
6168
std::string FormatISO8601DateTime(int64_t nTime)
6269
{
6370
const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};

src/util/time.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ using MillisecondsDouble = std::chrono::duration<double, std::chrono::millisecon
7373
*/
7474
int64_t GetTime();
7575

76+
/**
77+
* Convenience wrapper for getting current time in milliseconds.
78+
* Internally uses std::chrono::system_clock for consistency with other time functions.
79+
*/
80+
int64_t GetTimeMillis();
81+
7682
/**
7783
* DEPRECATED
7884
* Use SetMockTime with chrono type

0 commit comments

Comments
 (0)