Skip to content

Commit

Permalink
🐛 bugfix: duration is displayed as 00:00
Browse files Browse the repository at this point in the history
  • Loading branch information
naXa777 committed Sep 6, 2018
1 parent 624e714 commit d0bdfad
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/src/main/java/by/naxa/soundrecorder/util/TimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@
public class TimeUtils {

public static String formatDuration(long millis) {
String format;
final String sign;
if (millis < 0) {
format = "-";
sign = "-";
millis = -millis;
} else {
format = "";
sign = "";
}

long hours = TimeUnit.MILLISECONDS.toHours(millis);
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(hours);
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.HOURS.toSeconds(hours)
- TimeUnit.MINUTES.toSeconds(minutes);
if (hours > 0) {
format += "%d:%02d:%02d";
return String.format(Locale.ENGLISH, sign + "%d:%02d:%02d", hours, minutes, seconds);
} else {
format += "%02d:%02d";
return String.format(Locale.ENGLISH, sign + "%02d:%02d", minutes, seconds);
}

return String.format(Locale.ENGLISH, format, hours, minutes, seconds);
}

}

0 comments on commit d0bdfad

Please sign in to comment.