Skip to content

Commit

Permalink
2020-05-19-Human-Readable-Duration-Format-add-actual-code-for-passing…
Browse files Browse the repository at this point in the history
…-fourth-test
  • Loading branch information
JinHoooooou committed May 19, 2020
1 parent 12319e3 commit 75afba5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/humanReadableDurationFormat_20200519/TimeFormatter.java
Expand Up @@ -4,8 +4,10 @@ public class TimeFormatter {

public static String formatDuration(int seconds) {
String result = "";
int hour = seconds / 3600;
int minute = seconds % 3600 / 60;
int second = seconds % 60;
int minute = seconds / 60;

if (second > 0) {
result = second + (second > 1 ? " seconds" : " second");
}
Expand All @@ -15,6 +17,12 @@ public static String formatDuration(int seconds) {
}
result = minute + (minute > 1 ? " minutes" : " minute") + result;
}
if (hour > 0) {
if (minute > 0 || second > 0) {
result = " and" + result;
}
result = hour + (hour > 1 ? " hours" : " hour") + result;
}

return result;
}
Expand Down

0 comments on commit 75afba5

Please sign in to comment.