From 6d2fd18b419ddc202fa14cb14c98e8f3d5ecf646 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 29 Oct 2014 17:53:46 +0100 Subject: Implemented mission timer --- src/common/misc.cpp | 13 +++++++++++++ src/common/misc.h | 2 ++ 2 files changed, 15 insertions(+) (limited to 'src/common') 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 #include #include +#include +#include // 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 +#include // 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); -- cgit v1.2.3-1-g7c22