Skip to content

Commit 7fd4745

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 1aea212 commit 7fd4745

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/util/time.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ std::optional<int64_t> ParseISO8601DateTime(std::string_view str)
116116
return int64_t{TicksSinceEpoch<std::chrono::seconds>(tp)};
117117
}
118118

119+
std::string FormatISO8601Time(int64_t nTime) {
120+
const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};
121+
const auto days{std::chrono::floor<std::chrono::days>(secs)};
122+
const std::chrono::hh_mm_ss hms{secs - days};
123+
return strprintf("%02i:%02i:%02iZ", hms.hours().count(), hms.minutes().count(), hms.seconds().count());
124+
}
125+
119126
struct timeval MillisToTimeval(int64_t nTimeout)
120127
{
121128
struct timeval timeout;

src/util/time.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ T GetTime()
132132
*/
133133
std::string FormatISO8601DateTime(int64_t nTime);
134134
std::string FormatISO8601Date(int64_t nTime);
135+
std::string FormatISO8601Time(int64_t nTime);
135136
std::optional<int64_t> ParseISO8601DateTime(std::string_view str);
136137

137138
/**

0 commit comments

Comments
 (0)