summaryrefslogtreecommitdiff
path: root/core/src/main/java/de/danoeh/antennapod
diff options
context:
space:
mode:
authorNathan Mascitelli <mascitelli.nathan@gmail.com>2019-02-12 17:32:58 -0500
committerNathan Mascitelli <mascitelli.nathan@gmail.com>2019-02-12 19:43:37 -0500
commitd0f617880cda8bacfc70610d5ef04a6c8805a74b (patch)
tree10a391a16c4906ecb43b4abb18404b39e216546e /core/src/main/java/de/danoeh/antennapod
parent96b0336b2cbaa2166964757c089957bf4f1a420b (diff)
downloadAntennaPod-d0f617880cda8bacfc70610d5ef04a6c8805a74b.zip
Converter handles HH:MM and MM:SS
Diffstat (limited to 'core/src/main/java/de/danoeh/antennapod')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/Converter.java29
1 files changed, 18 insertions, 11 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java
index 1f9418c98..6ecca941a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java
@@ -74,13 +74,14 @@ public final class Converter {
return String.format(Locale.getDefault(), "%02d:%02d:%02d", h, m, s);
}
- /** Converts milliseconds to a string containing hours and minutes */
- public static String getDurationStringShort(int duration) {
- int minutes = duration / MINUTES_MIL;
- int rest = duration - minutes * MINUTES_MIL;
- int seconds = rest / SECONDS_MIL;
-
- return String.format(Locale.getDefault(), "%02d:%02d", minutes, seconds);
+ /** Converts milliseconds to a string containing hours and minutes or minutes and seconds*/
+ public static String getDurationStringShort(int duration, boolean durationIsInHours) {
+ int firstPartBase = durationIsInHours ? HOURS_MIL : MINUTES_MIL;
+ int firstPart = duration / firstPartBase;
+ int leftoverFromFirstPart = duration - firstPart * firstPartBase;
+ int secondPart = leftoverFromFirstPart / (durationIsInHours ? MINUTES_MIL : SECONDS_MIL);
+
+ return String.format(Locale.getDefault(), "%02d:%02d", firstPart, secondPart);
}
/** Converts long duration string (HH:MM:SS) to milliseconds. */
@@ -94,14 +95,20 @@ public final class Converter {
Integer.parseInt(parts[2]) * 1000;
}
- /** Converts short duration string (HH:MM) to milliseconds. */
- public static int durationStringShortToMs(String input) {
+ /**
+ * Converts short duration string (XX:YY) to milliseconds. If durationIsInHours is true then the
+ * format is HH:MM, otherwise it's MM:SS.
+ * */
+ public static int durationStringShortToMs(String input, boolean durationIsInHours) {
String[] parts = input.split(":");
if (parts.length != 2) {
return 0;
}
- return Integer.parseInt(parts[0]) * 60 * 1000 +
- Integer.parseInt(parts[1]) * 1000;
+
+ int modifier = durationIsInHours ? 60 : 1;
+
+ return Integer.parseInt(parts[0]) * 60 * 1000 * modifier+
+ Integer.parseInt(parts[1]) * 1000 * modifier;
}
/** Converts milliseconds to a localized string containing hours and minutes */