OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 dart.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * A [Duration] represents a time span. A duration can be negative. | 8 * A [Duration] represents a time span. A duration can be negative. |
9 */ | 9 */ |
10 class Duration implements Comparable { | 10 class Duration implements Comparable { |
11 static const int MILLISECONDS_PER_SECOND = 1000; | 11 static const int MILLISECONDS_PER_SECOND = 1000; |
12 static const int SECONDS_PER_MINUTE = 60; | 12 static const int SECONDS_PER_MINUTE = 60; |
13 static const int MINUTES_PER_HOUR = 60; | 13 static const int MINUTES_PER_HOUR = 60; |
14 static const int HOURS_PER_DAY = 24; | 14 static const int HOURS_PER_DAY = 24; |
15 | 15 |
16 static const int MILLISECONDS_PER_MINUTE = | 16 static const int MILLISECONDS_PER_MINUTE = |
17 MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE; | 17 MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE; |
18 static const int MILLISECONDS_PER_HOUR = | 18 static const int MILLISECONDS_PER_HOUR = |
19 MILLISECONDS_PER_MINUTE * MINUTES_PER_HOUR; | 19 MILLISECONDS_PER_MINUTE * MINUTES_PER_HOUR; |
20 static const int MILLISECONDS_PER_DAY = | 20 static const int MILLISECONDS_PER_DAY = |
21 MILLISECONDS_PER_HOUR * HOURS_PER_DAY; | 21 MILLISECONDS_PER_HOUR * HOURS_PER_DAY; |
22 | 22 |
23 static const int SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR; | 23 static const int SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR; |
24 static const int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; | 24 static const int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; |
25 | 25 |
26 static const int MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY; | 26 static const int MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY; |
27 | 27 |
| 28 static const Duration ZERO = const Duration(seconds: 0); |
| 29 |
28 /** | 30 /** |
29 * This [Duration] in milliseconds. | 31 * This [Duration] in milliseconds. |
30 */ | 32 */ |
31 final int inMilliseconds; | 33 final int inMilliseconds; |
32 | 34 |
33 /** | 35 /** |
34 * The duration is the sum of all individual parts. This means that individual | 36 * The duration is the sum of all individual parts. This means that individual |
35 * parts don't need to be less than the next-bigger unit. For example [hours] | 37 * parts don't need to be less than the next-bigger unit. For example [hours] |
36 * is allowed to have a value greater than 23. | 38 * is allowed to have a value greater than 23. |
37 * | 39 * |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 159 } |
158 String twoDigitMinutes = | 160 String twoDigitMinutes = |
159 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); | 161 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); |
160 String twoDigitSeconds = | 162 String twoDigitSeconds = |
161 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); | 163 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); |
162 String threeDigitMs = | 164 String threeDigitMs = |
163 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); | 165 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); |
164 return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$threeDigitMs"; | 166 return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$threeDigitMs"; |
165 } | 167 } |
166 } | 168 } |
OLD | NEW |