| 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 library utils; |
| 6 |
| 7 import 'dart:math'; |
| 6 | 8 |
| 7 class Utils { | 9 class Utils { |
| 8 static String formatPercent(num a, num total) { | 10 static String formatPercent(num a, num total) { |
| 9 var percent = 100.0 * (a / total); | 11 var percent = 100.0 * (a / total); |
| 10 return '${percent.toStringAsFixed(2)}%'; | 12 return '${percent.toStringAsFixed(2)}%'; |
| 11 } | 13 } |
| 12 | 14 |
| 13 static String zeroPad(int value, int pad) { | 15 static String zeroPad(int value, int pad) { |
| 14 String prefix = ""; | 16 String prefix = ""; |
| 15 while (pad > 1) { | 17 while (pad > 1) { |
| 16 int pow10 = pow(10, pad - 1); | 18 int pow10 = pow(10, pad - 1); |
| 17 if (value < pow10) { | 19 if (value < pow10) { |
| 18 prefix = prefix + "0"; | 20 prefix = prefix + "0"; |
| 19 } | 21 } |
| 20 pad--; | 22 pad--; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 var millis = (time * millisPerSecond).round(); | 105 var millis = (time * millisPerSecond).round(); |
| 104 | 106 |
| 105 var hours = millis ~/ millisPerHour; | 107 var hours = millis ~/ millisPerHour; |
| 106 millis = millis % millisPerHour; | 108 millis = millis % millisPerHour; |
| 107 | 109 |
| 108 var minutes = millis ~/ millisPerMinute; | 110 var minutes = millis ~/ millisPerMinute; |
| 109 millis = millis % millisPerMinute; | 111 millis = millis % millisPerMinute; |
| 110 | 112 |
| 111 var seconds = millis ~/ millisPerSecond; | 113 var seconds = millis ~/ millisPerSecond; |
| 112 | 114 |
| 113 StringBuffer out = new StringBuffer(); | |
| 114 if (hours != 0) { | 115 if (hours != 0) { |
| 115 return '${hours}h ${minutes}m ${seconds}s'; | 116 return '${hours}h ${minutes}m ${seconds}s'; |
| 116 } | 117 } |
| 117 if (minutes != 0) { | 118 if (minutes != 0) { |
| 118 return '${minutes}m ${seconds}s'; | 119 return '${minutes}m ${seconds}s'; |
| 119 } | 120 } |
| 120 return '${seconds}s'; | 121 return '${seconds}s'; |
| 121 } | 122 } |
| 122 | 123 |
| 123 static String formatSeconds(double x) { | 124 static String formatSeconds(double x) { |
| 124 return x.toStringAsFixed(2); | 125 return x.toStringAsFixed(2); |
| 125 } | 126 } |
| 126 | 127 |
| 127 static bool runningInJavaScript() => identical(1.0, 1); | 128 static bool runningInJavaScript() => identical(1.0, 1); |
| 128 } | 129 } |
| OLD | NEW |