summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/text/format/DateUtils.java54
-rw-r--r--core/java/android/text/format/Time.java4
2 files changed, 25 insertions, 33 deletions
diff --git a/core/java/android/text/format/DateUtils.java b/core/java/android/text/format/DateUtils.java
index 0babcc5..9e8c5b9 100644
--- a/core/java/android/text/format/DateUtils.java
+++ b/core/java/android/text/format/DateUtils.java
@@ -45,7 +45,6 @@ public class DateUtils
private static final String FAST_FORMAT_HMMSS = "%1$d:%2$02d:%3$02d";
private static final String FAST_FORMAT_MMSS = "%1$02d:%2$02d";
- private static final char TIME_PADDING = '0';
private static final char TIME_SEPARATOR = ':';
@@ -648,33 +647,36 @@ public class DateUtils
}
}
+ private static void append(StringBuilder sb, long value, boolean pad, char zeroDigit) {
+ if (value < 10) {
+ if (pad) {
+ sb.append(zeroDigit);
+ }
+ } else {
+ sb.append((char) (zeroDigit + (value / 10)));
+ }
+ sb.append((char) (zeroDigit + (value % 10)));
+ }
+
/**
- * Fast formatting of h:mm:ss
+ * Fast formatting of h:mm:ss.
*/
private static String formatElapsedTime(StringBuilder recycle, String format, long hours,
long minutes, long seconds) {
if (FAST_FORMAT_HMMSS.equals(format)) {
+ char zeroDigit = LocaleData.get(Locale.getDefault()).zeroDigit;
+
StringBuilder sb = recycle;
if (sb == null) {
sb = new StringBuilder(8);
} else {
sb.setLength(0);
}
- sb.append(hours);
+ append(sb, hours, false, zeroDigit);
sb.append(TIME_SEPARATOR);
- if (minutes < 10) {
- sb.append(TIME_PADDING);
- } else {
- sb.append(toDigitChar(minutes / 10));
- }
- sb.append(toDigitChar(minutes % 10));
+ append(sb, minutes, true, zeroDigit);
sb.append(TIME_SEPARATOR);
- if (seconds < 10) {
- sb.append(TIME_PADDING);
- } else {
- sb.append(toDigitChar(seconds / 10));
- }
- sb.append(toDigitChar(seconds % 10));
+ append(sb, seconds, true, zeroDigit);
return sb.toString();
} else {
return String.format(format, hours, minutes, seconds);
@@ -682,40 +684,28 @@ public class DateUtils
}
/**
- * Fast formatting of m:ss
+ * Fast formatting of mm:ss.
*/
private static String formatElapsedTime(StringBuilder recycle, String format, long minutes,
long seconds) {
if (FAST_FORMAT_MMSS.equals(format)) {
+ char zeroDigit = LocaleData.get(Locale.getDefault()).zeroDigit;
+
StringBuilder sb = recycle;
if (sb == null) {
sb = new StringBuilder(8);
} else {
sb.setLength(0);
}
- if (minutes < 10) {
- sb.append(TIME_PADDING);
- } else {
- sb.append(toDigitChar(minutes / 10));
- }
- sb.append(toDigitChar(minutes % 10));
+ append(sb, minutes, false, zeroDigit);
sb.append(TIME_SEPARATOR);
- if (seconds < 10) {
- sb.append(TIME_PADDING);
- } else {
- sb.append(toDigitChar(seconds / 10));
- }
- sb.append(toDigitChar(seconds % 10));
+ append(sb, seconds, true, zeroDigit);
return sb.toString();
} else {
return String.format(format, minutes, seconds);
}
}
- private static char toDigitChar(long digit) {
- return (char) (digit + '0');
- }
-
/**
* Format a date / time such that if the then is on the same day as now, it shows
* just the time and if it's a different day, it shows just the date.
diff --git a/core/java/android/text/format/Time.java b/core/java/android/text/format/Time.java
index 45d5a70..e2de8f2 100644
--- a/core/java/android/text/format/Time.java
+++ b/core/java/android/text/format/Time.java
@@ -151,6 +151,8 @@ public class Time {
private static String sDateTimeFormat;
private static String sAm;
private static String sPm;
+
+ // Referenced by native code.
private static String sDateCommand = "%a %b %e %H:%M:%S %Z %Y";
/**
@@ -673,7 +675,7 @@ public class Time {
int minutes = (offset % 3600) / 60;
int hours = offset / 3600;
- return String.format("%s%s%02d:%02d", base, sign, hours, minutes);
+ return String.format(Locale.US, "%s%s%02d:%02d", base, sign, hours, minutes);
}
}