diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/misc.cpp | 13 | ||||
-rw-r--r-- | src/common/misc.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 4954fc0..35a5560 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -26,6 +26,8 @@ #include <string.h> #include <ctype.h> #include <time.h> +#include <sstream> +#include <iomanip> // Returns a non-accented letter. @@ -232,6 +234,17 @@ void TimeToAsciiClean(time_t time, char *buffer) when.tm_hour, when.tm_min); } +std::string TimeFormat(float time) +{ + int minutes = floor(time/60); + double time2 = fmod(time, 60); + double seconds; + double fraction = modf(time2, &seconds)*100; + std::ostringstream sstream; + sstream << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << floor(seconds) << "." << std::setfill('0') << std::setw(2) << floor(fraction); + return sstream.str(); +} + // Adds an extension to file, if doesn't already one. diff --git a/src/common/misc.h b/src/common/misc.h index 4b75ae3..b53bbdd 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -22,6 +22,7 @@ #include <time.h> +#include <string> // TODO: rewrite/refactor or remove @@ -32,6 +33,7 @@ extern char GetToLower(char letter); extern void TimeToAscii(time_t time, char *buffer); extern void TimeToAsciiClean(time_t time, char *buffer); +extern std::string TimeFormat(float time); extern void AddExt(char* filename, const char* ext); |