Chromium Code Reviews| 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 library utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:math'; | 8 import 'dart:math'; |
| 9 | 9 |
| 10 class Utils { | 10 class Utils { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 return '${now.year}-${now.month}-${now.day} ' | 139 return '${now.year}-${now.month}-${now.day} ' |
| 140 '${now.hour.toString().padLeft(2)}:' | 140 '${now.hour.toString().padLeft(2)}:' |
| 141 '${now.minute.toString().padLeft(2)}:' | 141 '${now.minute.toString().padLeft(2)}:' |
| 142 '${now.second.toString().padLeft(2)}'; | 142 '${now.second.toString().padLeft(2)}'; |
| 143 } | 143 } |
| 144 | 144 |
| 145 static String formatSeconds(double x) { | 145 static String formatSeconds(double x) { |
| 146 return x.toStringAsFixed(2); | 146 return x.toStringAsFixed(2); |
| 147 } | 147 } |
| 148 | 148 |
| 149 static String formatDurationInSeconds(Duration x) { | |
| 150 return formatSeconds(x.inMilliseconds / 1000.0); | |
|
Cutch
2016/08/09 20:21:52
return formatSeconds(x.inSeconds);
cbernaschina
2016/08/09 20:29:39
it is not equivalent.
x.inMilliseconds / 1000.0
(
| |
| 151 } | |
| 152 | |
| 149 static bool runningInJavaScript() => identical(1.0, 1); | 153 static bool runningInJavaScript() => identical(1.0, 1); |
| 150 } | 154 } |
| 151 | 155 |
| 152 /// A [Task] that can be scheduled on the Dart event queue. | 156 /// A [Task] that can be scheduled on the Dart event queue. |
| 153 class Task { | 157 class Task { |
| 154 Timer _timer; | 158 Timer _timer; |
| 155 final Function callback; | 159 final Function callback; |
| 156 | 160 |
| 157 Task(this.callback); | 161 Task(this.callback); |
| 158 | 162 |
| 159 /// Queue [this] to run on the next Dart event queue pump. Does nothing | 163 /// Queue [this] to run on the next Dart event queue pump. Does nothing |
| 160 /// if [this] is already queued. | 164 /// if [this] is already queued. |
| 161 queue() { | 165 queue() { |
| 162 if (_timer != null) { | 166 if (_timer != null) { |
| 163 // Already scheduled. | 167 // Already scheduled. |
| 164 return; | 168 return; |
| 165 } | 169 } |
| 166 _timer = new Timer(Duration.ZERO, () { | 170 _timer = new Timer(Duration.ZERO, () { |
| 167 _timer = null; | 171 _timer = null; |
| 168 callback(); | 172 callback(); |
| 169 }); | 173 }); |
| 170 } | 174 } |
| 171 } | 175 } |
| OLD | NEW |