diff --git a/src/format.cpp b/src/format.cpp index 8f8f854b..fb295857 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -1,11 +1,24 @@ -#include - #include "format.h" +#include +#include + using std::string; -// TODO: Complete this helper function +// DONE: Complete this helper function // INPUT: Long int measuring seconds // OUTPUT: HH:MM:SS -// REMOVE: [[maybe_unused]] once you define the function -string Format::ElapsedTime(long seconds[[maybe_unused]]) { return string(); } \ No newline at end of file +string Format::ElapsedTime(long seconds) { + long hours = seconds / 3600; + long minutes = (seconds % 3600) / 60; + long secs = seconds % 3600 % 60; + std::ostringstream formatted_time{}; + string s_hours = + hours <= 9 ? "0" + std::to_string(hours) : std::to_string(hours); + string s_minutes = + minutes <= 9 ? "0" + std::to_string(minutes) : std::to_string(minutes); + string s_seconds = + secs <= 9 ? "0" + std::to_string(secs) : std::to_string(secs); + formatted_time << s_hours << ":" << s_minutes << ":" << s_seconds; + return formatted_time.str(); +}; \ No newline at end of file