Skip to content

Commit df021bf

Browse files
committed
util: Add FormatISO8601Time function for time-only ISO format
Add a new time formatting function that matches the existing date and datetime ISO8601 formatting functions, providing consistent time display for the traffic graph widget tooltips and other UI elements that need time-only display.
1 parent 9c4583e commit df021bf

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/util/time.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ void MockableSteadyClock::ClearMockTime()
7575

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

78+
std::string FormatISO8601Time(int64_t nTime)
79+
{
80+
const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};
81+
const auto days{std::chrono::floor<std::chrono::days>(secs)};
82+
const std::chrono::hh_mm_ss hms{secs - days};
83+
return strprintf("%02i:%02i:%02iZ", hms.hours().count(), hms.minutes().count(), hms.seconds().count());
84+
}
85+
7886
std::string FormatISO8601DateTime(int64_t nTime)
7987
{
8088
const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};

src/util/time.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ T GetTime()
130130
* ISO 8601 formatting is preferred. Use the FormatISO8601{DateTime,Date}
131131
* helper functions if possible.
132132
*/
133+
std::string FormatISO8601Time(int64_t nTime);
133134
std::string FormatISO8601DateTime(int64_t nTime);
134135
std::string FormatISO8601Date(int64_t nTime);
135136
std::optional<int64_t> ParseISO8601DateTime(std::string_view str);

0 commit comments

Comments
 (0)