[uptime] enhance UptimeToString() and add flags (#12841)

This commit enhances the `UptimeToString()` function by introducing
`UptimeStringFlags` to allow customization of the output string.
Specifically, it adds the following flags:

- `kUptimeStringIncludeMsec`: Includes milliseconds in the string.
- `kUptimeStringSkipHoursIfZero`: Omits the `<hh>:` part when hours
  and days are zero.

The commit also adds a new `UptimeToString()` overload that returns
an `UptimeString` (a `String` object), simplifying usage in logging
and other areas. All existing call sites are updated to use the new
flags and the new overload where appropriate.
This commit is contained in:
Abtin Keshavarzian
2026-04-06 17:13:32 -07:00
committed by GitHub
parent 7aa9d92600
commit f8af79817b
7 changed files with 66 additions and 26 deletions
+1 -1
View File
@@ -533,7 +533,7 @@ void otConvertDurationInSecondsToString(uint32_t aDuration, char *aBuffer, uint1
StringWriter writer(aBuffer, aSize);
UptimeMsec uptime = static_cast<UptimeMsec>(aDuration) * Time::kOneSecondInMsec;
UptimeToString(uptime, writer, /* aIncludeMsec */ false);
UptimeToString(uptime, writer, /* aFlags */ 0);
}
#endif