From fab1c8bd31a3871d466e4c3d24a4d90fcb25564c Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Mon, 17 Jul 2017 16:01:53 -0700 Subject: 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 --- .../com/android/dialer/calllogutils/CallEntryFormatter.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'java/com/android/dialer/calllogutils') 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 ""; } -- cgit v1.2.3