aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-21 12:44:12 -0700
committerAllan Wang <me@allanwang.ca>2017-06-21 12:44:12 -0700
commitc58df447ebea1408b33209098851557847e6c652 (patch)
treeda28712c7f92da64d4a7f4ef1699bb51ce4a62eb /library
parent49b9c772aecce5c40cda4295c4c3880729c65861 (diff)
downloadkau-c58df447ebea1408b33209098851557847e6c652.tar.gz
kau-c58df447ebea1408b33209098851557847e6c652.tar.bz2
kau-c58df447ebea1408b33209098851557847e6c652.zip
Minute to text
Diffstat (limited to 'library')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt17
1 files changed, 15 insertions, 2 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
index 8aaadaf..d3db05e 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
@@ -1,12 +1,12 @@
package ca.allanwang.kau.utils
import android.content.Context
+import android.content.pm.PackageManager
import android.content.res.Resources
import android.os.Build
import android.os.Looper
+import ca.allanwang.kau.R
import ca.allanwang.kau.logging.KL
-import android.content.pm.PackageManager
-
/**
@@ -48,4 +48,17 @@ fun Context.isAppInstalled(packageName: String): Boolean {
installed = false
}
return installed
+}
+
+/**
+ * Converts minute value to string
+ * Whole hours and days will be converted as such, otherwise it will default to x minutes
+ */
+fun Context.minuteToText(minutes: Long): String = with(minutes) {
+ if (this < 0L) string(R.string.kau_none)
+ else if (this == 60L) string(R.string.kau_one_hour)
+ else if (this == 1440L) string(R.string.kau_one_day)
+ else if (this % 1440L == 0L) String.format(string(R.string.kau_x_days), this / 1440L)
+ else if (this % 60L == 0L) String.format(string(R.string.kau_x_hours), this / 60L)
+ else String.format(string(R.string.kau_x_minutes), this)
} \ No newline at end of file