summaryrefslogtreecommitdiffstats
path: root/core/java/android/util/TimeUtils.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-07-21 12:37:26 -0700
committerJeff Sharkey <jsharkey@android.com>2012-07-21 12:39:48 -0700
commiteaaf396169abdbd213565cacb37dc0c9c391b365 (patch)
treecef3fb9ab6b792522c2261a4249b410f18ad7f0d /core/java/android/util/TimeUtils.java
parent971a3cfa51b89aa0f3ab47ee082f05586a1f16f0 (diff)
downloadframeworks_base-eaaf396169abdbd213565cacb37dc0c9c391b365.zip
frameworks_base-eaaf396169abdbd213565cacb37dc0c9c391b365.tar.gz
frameworks_base-eaaf396169abdbd213565cacb37dc0c9c391b365.tar.bz2
Avoid emitting broken ASCII.
Bug: 6131887 Change-Id: Iff13573aad8128cc7ae3613ab718c81e6d0862a1
Diffstat (limited to 'core/java/android/util/TimeUtils.java')
-rw-r--r--core/java/android/util/TimeUtils.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/core/java/android/util/TimeUtils.java b/core/java/android/util/TimeUtils.java
index c4ebec4..7d33ff4a 100644
--- a/core/java/android/util/TimeUtils.java
+++ b/core/java/android/util/TimeUtils.java
@@ -18,8 +18,10 @@ package android.util;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
+import android.text.format.DateUtils;
+
+import com.android.internal.util.XmlUtils;
-import libcore.util.ZoneInfoDB;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -28,10 +30,10 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
-import java.util.TimeZone;
import java.util.Date;
+import java.util.TimeZone;
-import com.android.internal.util.XmlUtils;
+import libcore.util.ZoneInfoDB;
/**
* A class containing utility methods related to time zones.
@@ -245,6 +247,8 @@ public class TimeUtils {
private static final Object sFormatSync = new Object();
private static char[] sFormatStr = new char[HUNDRED_DAY_FIELD_LEN+5];
+ private static final long LARGEST_DURATION = (1000 * DateUtils.DAY_IN_MILLIS) - 1;
+
static private int accumField(int amt, int suffix, boolean always, int zeropad) {
if (amt > 99 || (always && zeropad >= 3)) {
return 3+suffix;
@@ -307,6 +311,10 @@ public class TimeUtils {
duration = -duration;
}
+ if (duration > LARGEST_DURATION) {
+ duration = LARGEST_DURATION;
+ }
+
int millis = (int)(duration%1000);
int seconds = (int) Math.floor(duration / 1000);
int days = 0, hours = 0, minutes = 0;