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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 if (hours != 0) { | 129 if (hours != 0) { |
130 return '${hours}h ${minutes}m ${seconds}s'; | 130 return '${hours}h ${minutes}m ${seconds}s'; |
131 } | 131 } |
132 if (minutes != 0) { | 132 if (minutes != 0) { |
133 return '${minutes}m ${seconds}s'; | 133 return '${minutes}m ${seconds}s'; |
134 } | 134 } |
135 return '${seconds}s'; | 135 return '${seconds}s'; |
136 } | 136 } |
137 | 137 |
| 138 static String formatDateTime(DateTime now) { |
| 139 return '${now.year}-${now.month}-${now.day} ' |
| 140 '${now.hour.toString().padLeft(2)}:' |
| 141 '${now.minute.toString().padLeft(2)}:' |
| 142 '${now.second.toString().padLeft(2)}'; |
| 143 } |
| 144 |
138 static String formatSeconds(double x) { | 145 static String formatSeconds(double x) { |
139 return x.toStringAsFixed(2); | 146 return x.toStringAsFixed(2); |
140 } | 147 } |
141 | 148 |
142 static bool runningInJavaScript() => identical(1.0, 1); | 149 static bool runningInJavaScript() => identical(1.0, 1); |
143 } | 150 } |
144 | 151 |
145 /// A [Task] that can be scheduled on the Dart event queue. | 152 /// A [Task] that can be scheduled on the Dart event queue. |
146 class Task { | 153 class Task { |
147 Timer _timer; | 154 Timer _timer; |
148 final Function callback; | 155 final Function callback; |
149 | 156 |
150 Task(this.callback); | 157 Task(this.callback); |
151 | 158 |
152 /// Queue [this] to run on the next Dart event queue pump. Does nothing | 159 /// Queue [this] to run on the next Dart event queue pump. Does nothing |
153 /// if [this] is already queued. | 160 /// if [this] is already queued. |
154 queue() { | 161 queue() { |
155 if (_timer != null) { | 162 if (_timer != null) { |
156 // Already scheduled. | 163 // Already scheduled. |
157 return; | 164 return; |
158 } | 165 } |
159 _timer = new Timer(Duration.ZERO, () { | 166 _timer = new Timer(Duration.ZERO, () { |
160 _timer = null; | 167 _timer = null; |
161 callback(); | 168 callback(); |
162 }); | 169 }); |
163 } | 170 } |
164 } | 171 } |
OLD | NEW |