Skip to content

Instantly share code, notes, and snippets.

@ffAudio
Last active February 6, 2018 22:53
Show Gist options
  • Save ffAudio/4fe99716246a4fff8644e451e7877b05 to your computer and use it in GitHub Desktop.
Save ffAudio/4fe99716246a4fff8644e451e7877b05 to your computer and use it in GitHub Desktop.
Addition for juce::RelativeTime to write a technical string
String RelativeTime::toString (bool includeDays) const
{
String result;
result.preallocateBytes (32);
if (numSeconds < 0)
result << '-';
bool empty = true;
if (includeDays) {
auto days = (int)inDays();
if (days > 0) {
result << String (days) << ' ';
empty = false;
}
}
result << String ((int)inHours() % 24).paddedLeft ('0', empty ? 1 : 2) << ':';
result << String ((int)inMinutes() % 60).paddedLeft ('0', 2) << ':';
result << String ((int)inSeconds() % 60).paddedLeft ('0', 2);
auto millis = (int)inMilliseconds() % 1000;
if (millis > 0)
result << '.' << String (millis).paddedLeft ('0', 3);
return result.trimEnd();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment