Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: sdk/lib/core/duration.dart

Issue 431263004: Adding Duration documentation, abs(), and isNegative() (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/duration_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds. 8 * A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.
Lasse Reichstein Nielsen 2014/08/04 07:42:25 Add paragraph: * * A `Duration` represents a di
srawlins 2014/08/04 21:45:09 Done.
9 * 9 *
10 * To create a new Duration object, use this class's single constructor 10 * To create a new Duration object, use this class's single constructor
11 * giving the appropriate arguments: 11 * giving the appropriate arguments:
12 * 12 *
13 * Duration fastestMarathon = new Duration(hours:2, minutes:3, seconds:2); 13 * Duration fastestMarathon = new Duration(hours:2, minutes:3, seconds:2);
14 * 14 *
15 * The Duration is the sum of all individual parts. 15 * The Duration is the sum of all individual parts.
16 * This means that individual parts can be larger than the next-bigger unit. 16 * This means that individual parts can be larger than the next-bigger unit.
17 * For example, [minutes] can be greater than 59. 17 * For example, [minutes] can be greater than 59.
18 * 18 *
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 * Returns `true` if this Duration is the same object as [other]. 201 * Returns `true` if this Duration is the same object as [other].
202 */ 202 */
203 bool operator ==(other) { 203 bool operator ==(other) {
204 if (other is !Duration) return false; 204 if (other is !Duration) return false;
205 return _duration == other._duration; 205 return _duration == other._duration;
206 } 206 }
207 207
208 int get hashCode => _duration.hashCode; 208 int get hashCode => _duration.hashCode;
209 209
210 /** 210 /**
211 * Compares this Duration to [other], 211 * Compares this Duration to [other], returning zero if the values are equal.
212 * returning zero if the values are equal.
213 * 212 *
214 * This function returns a negative integer 213 * This function returns a negative integer if this Duration is smaller than
Lasse Reichstein Nielsen 2014/08/04 07:42:25 "This function returns" -> "Returns" Duration -> `
srawlins 2014/08/04 21:45:09 Done.
215 * if this Duration is smaller than [other], 214 * [other], or a positive integer if it is greater.
Lasse Reichstein Nielsen 2014/08/04 07:42:25 greater -> longer. Add: * A negative `Duration`
srawlins 2014/08/04 21:45:09 Done.
216 * or a positive integer if it is greater.
217 */ 215 */
218 int compareTo(Duration other) => _duration.compareTo(other._duration); 216 int compareTo(Duration other) => _duration.compareTo(other._duration);
219 217
218 /**
219 * Returns a string representation of this Duration with hours, minutes,
Lasse Reichstein Nielsen 2014/08/04 07:42:25 Make a short first line, e.g.: "Returns a string
srawlins 2014/08/04 21:45:09 Done.
220 * seconds, and microseconds, in the following format: `HH:MM:SS.mmmmmm`. For
221 * example,
222 *
223 * var d = new Duration(days:1, hours:1, minutes:33, microseconds: 500);
224 * d.toString(); // "25:33:00.000500"
225 */
220 String toString() { 226 String toString() {
221 String sixDigits(int n) { 227 String sixDigits(int n) {
222 if (n >= 100000) return "$n"; 228 if (n >= 100000) return "$n";
223 if (n >= 10000) return "0$n"; 229 if (n >= 10000) return "0$n";
224 if (n >= 1000) return "00$n"; 230 if (n >= 1000) return "00$n";
225 if (n >= 100) return "000$n"; 231 if (n >= 100) return "000$n";
226 if (n >= 10) return "0000$n"; 232 if (n >= 10) return "0000$n";
227 return "00000$n"; 233 return "00000$n";
228 } 234 }
229 String twoDigits(int n) { 235 String twoDigits(int n) {
230 if (n >= 10) return "$n"; 236 if (n >= 10) return "$n";
231 return "0$n"; 237 return "0$n";
232 } 238 }
233 239
234 if (inMicroseconds < 0) { 240 if (inMicroseconds < 0) {
235 Duration duration = 241 Duration duration =
236 new Duration(microseconds: -inMicroseconds); 242 new Duration(microseconds: -inMicroseconds);
237 return "-$duration"; 243 return "-$duration";
238 } 244 }
239 String twoDigitMinutes = twoDigits(inMinutes.remainder(MINUTES_PER_HOUR)); 245 String twoDigitMinutes = twoDigits(inMinutes.remainder(MINUTES_PER_HOUR));
240 String twoDigitSeconds = twoDigits(inSeconds.remainder(SECONDS_PER_MINUTE)); 246 String twoDigitSeconds = twoDigits(inSeconds.remainder(SECONDS_PER_MINUTE));
241 String sixDigitUs = 247 String sixDigitUs =
242 sixDigits(inMicroseconds.remainder(MICROSECONDS_PER_SECOND)); 248 sixDigits(inMicroseconds.remainder(MICROSECONDS_PER_SECOND));
243 return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs"; 249 return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs";
244 } 250 }
251
252 /**
253 * Returns whether this Duration is negative.
Lasse Reichstein Nielsen 2014/08/04 07:42:25 Durations should never have been allowed to be neg
srawlins 2014/08/04 21:45:09 Done.
254 */
255 bool isNegative() => _duration.isNegative;
floitsch 2014/08/01 13:07:03 predicates are getters in Dart.
Lasse Reichstein Nielsen 2014/08/04 07:42:25 Agree bool get isNegative => _duration < 0;
srawlins 2014/08/04 21:45:09 Done.
srawlins 2014/08/04 21:45:09 Done.
256
257 /**
258 * Returns a new Duration representing the absolute value of this Duration.
Lasse Reichstein Nielsen 2014/08/04 07:42:24 Duration -> `Duration` (twice). Also add: * * T
srawlins 2014/08/04 21:45:09 Done.
259 */
260 Duration abs() => new Duration(microseconds: _duration.abs());
245 } 261 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/duration_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698