-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(noent): implement Format::ElapsedTime
- Loading branch information
1 parent
976809a
commit 098b441
Showing
1 changed file
with
18 additions
and
5 deletions.
There are no files selected for viewing
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
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(); | ||
}; |