Merge branch 'fix_1192_date_time' of https://github.com/owncloud/android into materia...
authorAndy Scherzinger <info@andy-scherzinger.de>
Fri, 16 Oct 2015 12:47:12 +0000 (14:47 +0200)
committerAndy Scherzinger <info@andy-scherzinger.de>
Fri, 16 Oct 2015 12:47:12 +0000 (14:47 +0200)
1  2 
src/com/owncloud/android/utils/DisplayUtils.java

@@@ -37,7 -37,6 +37,7 @@@ import com.owncloud.android.MainApp
  import com.owncloud.android.R;\r
  import com.owncloud.android.datamodel.OCFile;\r
  \r
 +import java.math.BigDecimal;\r
  import java.net.IDN;\r
  import java.text.DateFormat;\r
  import java.util.Calendar;\r
@@@ -53,7 -52,6 +53,7 @@@ public class DisplayUtils 
      private static final String OWNCLOUD_APP_NAME = "ownCloud";\r
      \r
      private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };\r
 +    private static final int[] sizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 };\r
  \r
      private static Map<String, String> mimeType2HumanReadable;\r
  \r
  \r
      /**\r
       * Converts the file size in bytes to human readable output.\r
 -     * \r
 +     * <ul>\r
 +     *     <li>appends a size suffix, e.g. B, KB, MB etc.</li>\r
 +     *     <li>rounds the size based on the suffix to 0,1 or 2 decimals</li>\r
 +     * </ul>\r
 +     *\r
       * @param bytes Input file size\r
       * @return Like something readable like "12 MB"\r
       */\r
      public static String bytesToHumanReadable(long bytes) {\r
          double result = bytes;\r
 -        int attachedsuff = 0;\r
 -        while (result > 1024 && attachedsuff < sizeSuffixes.length) {\r
 +        int attachedSuff = 0;\r
 +        while (result > 1024 && attachedSuff < sizeSuffixes.length) {\r
              result /= 1024.;\r
 -            attachedsuff++;\r
 +            attachedSuff++;\r
          }\r
 -        result = ((int) (result * 100)) / 100.;\r
 -        return result + " " + sizeSuffixes[attachedsuff];\r
 +\r
 +        return new BigDecimal(result).setScale(\r
 +                sizeScales[attachedSuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedSuff];\r
      }\r
  \r
      /**\r
                  dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);\r
              }\r
          }\r
-         \r
-         return dateString.toString().split(",")[0];\r
\r
+         String[] parts = dateString.toString().split(",");\r
+         if (parts.length == 2) {\r
+             if (parts[1].contains(":") && !parts[0].contains(":")) {\r
+                 return parts[0];\r
+             } else if (parts[0].contains(":") && !parts[1].contains(":")) {\r
+                 return parts[1];\r
+             }\r
+         }\r
+         //dateString contains unexpected format. use localized, absolute date.\r
+         return DisplayUtils.unixTimeToHumanReadable(time);\r
      }\r
  \r
      /**\r