Skip to content

Commit

Permalink
feat(noent): implement Format::ElapsedTime
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmundHusserl committed Oct 23, 2024
1 parent 976809a commit 098b441
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/format.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#include <string>

#include "format.h"

#include <sstream>
#include <string>

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(); }
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();
};

0 comments on commit 098b441

Please sign in to comment.