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<Duration> { | 10 class Duration implements Comparable<Duration> { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 * Returns the difference of this [Duration] and [other] as a new | 75 * Returns the difference of this [Duration] and [other] as a new |
76 * [Duration]. | 76 * [Duration]. |
77 */ | 77 */ |
78 Duration operator -(Duration other) { | 78 Duration operator -(Duration other) { |
79 return new Duration(microseconds: _duration - other._duration); | 79 return new Duration(microseconds: _duration - other._duration); |
80 } | 80 } |
81 | 81 |
82 /** | 82 /** |
83 * Multiplies this [Duration] by the given [factor] and returns the result | 83 * Multiplies this [Duration] by the given [factor] and returns the result |
84 * as a new [Duration]. | 84 * as a new [Duration]. |
| 85 * |
| 86 * Note that when [factor] is a double, and the duration is greater than |
| 87 * 53 bits, precision is lost because of double-precision arithmetic. |
85 */ | 88 */ |
86 Duration operator *(int factor) { | 89 Duration operator *(num factor) { |
87 return new Duration(microseconds: _duration * factor); | 90 return new Duration(microseconds: (_duration * factor).round()); |
88 } | 91 } |
89 | 92 |
90 /** | 93 /** |
91 * Divides this [Duration] by the given [quotient] and returns the truncated | 94 * Divides this [Duration] by the given [quotient] and returns the truncated |
92 * result as a new [Duration]. | 95 * result as a new [Duration]. |
93 * | 96 * |
94 * Throws an [IntegerDivisionByZeroException] if [quotient] is `0`. | 97 * Throws an [IntegerDivisionByZeroException] if [quotient] is `0`. |
95 */ | 98 */ |
96 Duration operator ~/(int quotient) { | 99 Duration operator ~/(int quotient) { |
97 // By doing the check here instead of relying on "~/" below we get the | 100 // By doing the check here instead of relying on "~/" below we get the |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 new Duration(microseconds: -inMicroseconds); | 177 new Duration(microseconds: -inMicroseconds); |
175 return "-$duration"; | 178 return "-$duration"; |
176 } | 179 } |
177 String twoDigitMinutes = twoDigits(inMinutes.remainder(MINUTES_PER_HOUR)); | 180 String twoDigitMinutes = twoDigits(inMinutes.remainder(MINUTES_PER_HOUR)); |
178 String twoDigitSeconds = twoDigits(inSeconds.remainder(SECONDS_PER_MINUTE)); | 181 String twoDigitSeconds = twoDigits(inSeconds.remainder(SECONDS_PER_MINUTE)); |
179 String sixDigitUs = | 182 String sixDigitUs = |
180 sixDigits(inMicroseconds.remainder(MICROSECONDS_PER_SECOND)); | 183 sixDigits(inMicroseconds.remainder(MICROSECONDS_PER_SECOND)); |
181 return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs"; | 184 return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs"; |
182 } | 185 } |
183 } | 186 } |
OLD | NEW |