summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-01-09 03:19:03 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-01-09 03:19:03 +0000
commita2fe748e7a24fcb631daa3e228564eca81f8a670 (patch)
treed9ad3b8c382b90e8311b5d1b578008e79190c556 /core/java/android
parentaa31e19ae1189f022b22d7de17e93e10516f80da (diff)
parent761d3ff06c74a4da50a395f6269ea8b81d60f51f (diff)
Merge "Duration format for tunable settings"
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/util/KeyValueListParser.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/java/android/util/KeyValueListParser.java b/core/java/android/util/KeyValueListParser.java
index 0a00794a1471..7eef63efd14d 100644
--- a/core/java/android/util/KeyValueListParser.java
+++ b/core/java/android/util/KeyValueListParser.java
@@ -17,6 +17,9 @@ package android.util;
import android.text.TextUtils;
+import java.time.Duration;
+import java.time.format.DateTimeParseException;
+
/**
* Parses a list of key=value pairs, separated by some delimiter, and puts the results in
* an internal Map. Values can be then queried by key, or if not found, a default value
@@ -189,4 +192,24 @@ public class KeyValueListParser {
public String keyAt(int index) {
return mValues.keyAt(index);
}
+
+ /**
+ * {@hide}
+ * Parse a duration in millis based on java.time.Duration or just a number (millis)
+ */
+ public long getDurationMillis(String key, long def) {
+ String value = mValues.get(key);
+ if (value != null) {
+ try {
+ if (value.startsWith("P") || value.startsWith("p")) {
+ return Duration.parse(value).toMillis();
+ } else {
+ return Long.parseLong(value);
+ }
+ } catch (NumberFormatException | DateTimeParseException e) {
+ // fallthrough
+ }
+ }
+ return def;
+ }
}