diff options
author | calderwoodra <calderwoodra@google.com> | 2017-07-17 16:01:53 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-07-25 16:41:33 +0000 |
commit | fab1c8bd31a3871d466e4c3d24a4d90fcb25564c (patch) | |
tree | 6e3d8ff1dcf489055d30f3fa52ce52a2d06cf0cf /java/com/android/dialer/calllogutils | |
parent | 57697f256238b43b888d8f6d9a1b17d335082513 (diff) |
Fixed issue where calls longer than 60 minutes would be truncated.
SimpleDateFormatter cannot display times longer than 60 minutes. If
a time is longer than 60 minutes, it will display the time % 60. This
change accounts for that and replaces the truncated time with the correct
time.
Bug: 63709810
Test: CallEntryFormatterTest
PiperOrigin-RevId: 162284780
Change-Id: Ib01b135c028b5d59637850e873e5a218f9c39ae8
Diffstat (limited to 'java/com/android/dialer/calllogutils')
-rw-r--r-- | java/com/android/dialer/calllogutils/CallEntryFormatter.java | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/java/com/android/dialer/calllogutils/CallEntryFormatter.java b/java/com/android/dialer/calllogutils/CallEntryFormatter.java index 8288ea9ed..c5ec15748 100644 --- a/java/com/android/dialer/calllogutils/CallEntryFormatter.java +++ b/java/com/android/dialer/calllogutils/CallEntryFormatter.java @@ -104,8 +104,17 @@ public class CallEntryFormatter { // If new translation issues arise, we should catch them here to prevent crashes. try { - return new SimpleDateFormat(formatPattern) - .format(new Date(TimeUnit.SECONDS.toMillis(elapsedSeconds))); + Date date = new Date(TimeUnit.SECONDS.toMillis(elapsedSeconds)); + SimpleDateFormat format = new SimpleDateFormat(formatPattern); + String duration = format.format(date); + + // SimpleDateFormat cannot display more than 59 minutes, instead it displays MINUTES % 60. + // Here we check for that value and replace it with the correct value. + if (elapsedSeconds >= TimeUnit.MINUTES.toSeconds(60)) { + int minutes = (int) (elapsedSeconds / 60); + duration = duration.replaceFirst(Integer.toString(minutes % 60), Integer.toString(minutes)); + } + return duration; } catch (Exception e) { return ""; } |