| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of app; | 5 part of app; |
| 6 | 6 |
| 7 class Utils { | 7 class Utils { |
| 8 static String formatPercent(num a, num total) { | 8 static String formatPercent(num a, num total) { |
| 9 var percent = 100.0 * (a / total); | 9 var percent = 100.0 * (a / total); |
| 10 return '${percent.toStringAsFixed(2)}%'; | 10 return '${percent.toStringAsFixed(2)}%'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ":${zeroPad(seconds,2)}" | 66 ":${zeroPad(seconds,2)}" |
| 67 ".${zeroPad(millis,3)}"); | 67 ".${zeroPad(millis,3)}"); |
| 68 } else { | 68 } else { |
| 69 return ("${zeroPad(minutes,2)}" | 69 return ("${zeroPad(minutes,2)}" |
| 70 ":${zeroPad(seconds,2)}" | 70 ":${zeroPad(seconds,2)}" |
| 71 ".${zeroPad(millis,3)}"); | 71 ".${zeroPad(millis,3)}"); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 static String formatSize(int bytes) { | 75 static String formatSize(int bytes) { |
| 76 const int digits = 2; |
| 76 const int bytesPerKB = 1024; | 77 const int bytesPerKB = 1024; |
| 77 const int bytesPerMB = 1024 * bytesPerKB; | 78 const int bytesPerMB = 1024 * bytesPerKB; |
| 78 const int bytesPerGB = 1024 * bytesPerMB; | 79 const int bytesPerGB = 1024 * bytesPerMB; |
| 79 const int bytesPerTB = 1024 * bytesPerGB; | 80 const int bytesPerTB = 1024 * bytesPerGB; |
| 80 | 81 |
| 81 if (bytes < bytesPerKB) { | 82 if (bytes < bytesPerKB) { |
| 82 return "${bytes}B"; | 83 return "${bytes}B"; |
| 83 } else if (bytes < bytesPerMB) { | 84 } else if (bytes < bytesPerMB) { |
| 84 return "${(bytes / bytesPerKB).round()}KB"; | 85 return "${(bytes / bytesPerKB).toStringAsFixed(digits)}KB"; |
| 85 } else if (bytes < bytesPerGB) { | 86 } else if (bytes < bytesPerGB) { |
| 86 return "${(bytes / bytesPerMB).round()}MB"; | 87 return "${(bytes / bytesPerMB).toStringAsFixed(digits)}MB"; |
| 87 } else if (bytes < bytesPerTB) { | 88 } else if (bytes < bytesPerTB) { |
| 88 return "${(bytes / bytesPerGB).round()}GB"; | 89 return "${(bytes / bytesPerGB).toStringAsFixed(digits)}GB"; |
| 89 } else { | 90 } else { |
| 90 return "${(bytes / bytesPerTB).round()}TB"; | 91 return "${(bytes / bytesPerTB).toStringAsFixed(digits)}TB"; |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 94 static String formatTime(double time) { | 95 static String formatTime(double time) { |
| 95 if (time == null) { | 96 if (time == null) { |
| 96 return "-"; | 97 return "-"; |
| 97 } | 98 } |
| 98 const millisPerHour = 60 * 60 * 1000; | 99 const millisPerHour = 60 * 60 * 1000; |
| 99 const millisPerMinute = 60 * 1000; | 100 const millisPerMinute = 60 * 1000; |
| 100 const millisPerSecond = 1000; | 101 const millisPerSecond = 1000; |
| 101 | 102 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 116 if (minutes != 0) { | 117 if (minutes != 0) { |
| 117 return '${minutes}m ${seconds}s'; | 118 return '${minutes}m ${seconds}s'; |
| 118 } | 119 } |
| 119 return '${seconds}s'; | 120 return '${seconds}s'; |
| 120 } | 121 } |
| 121 | 122 |
| 122 static String formatSeconds(double x) { | 123 static String formatSeconds(double x) { |
| 123 return x.toStringAsFixed(2); | 124 return x.toStringAsFixed(2); |
| 124 } | 125 } |
| 125 } | 126 } |
| OLD | NEW |