Last active
February 6, 2018 22:53
-
-
Save ffAudio/4fe99716246a4fff8644e451e7877b05 to your computer and use it in GitHub Desktop.
Addition for juce::RelativeTime to write a technical string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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