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

Side by Side Diff: lib/coreimpl/duration_implementation.dart

Issue 10939030: Reapply conversion of most core interfaces to abstract classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | « lib/coreimpl/date.dart ('k') | lib/coreimpl/exceptions.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Dart core library.
6
7 class DurationImplementation implements Duration {
8 final int inMilliseconds;
9
10 const DurationImplementation({int days: 0,
11 int hours: 0,
12 int minutes: 0,
13 int seconds: 0,
14 int milliseconds: 0})
15 : inMilliseconds = days * Duration.MILLISECONDS_PER_DAY +
16 hours * Duration.MILLISECONDS_PER_HOUR +
17 minutes * Duration.MILLISECONDS_PER_MINUTE +
18 seconds * Duration.MILLISECONDS_PER_SECOND +
19 milliseconds;
20
21 int get inDays {
22 return inMilliseconds ~/ Duration.MILLISECONDS_PER_DAY;
23 }
24
25 int get inHours {
26 return inMilliseconds ~/ Duration.MILLISECONDS_PER_HOUR;
27 }
28
29 int get inMinutes {
30 return inMilliseconds ~/ Duration.MILLISECONDS_PER_MINUTE;
31 }
32
33 int get inSeconds {
34 return inMilliseconds ~/ Duration.MILLISECONDS_PER_SECOND;
35 }
36
37 bool operator ==(other) {
38 if (other is !Duration) return false;
39 return inMilliseconds == other.inMilliseconds;
40 }
41
42 int hashCode() {
43 return inMilliseconds.hashCode();
44 }
45
46 int compareTo(Duration other) {
47 return inMilliseconds.compareTo(other.inMilliseconds);
48 }
49
50 String toString() {
51 String threeDigits(int n) {
52 if (n >= 100) return "${n}";
53 if (n > 10) return "0${n}";
54 return "00${n}";
55 }
56 String twoDigits(int n) {
57 if (n >= 10) return "${n}";
58 return "0${n}";
59 }
60
61 if (inMilliseconds < 0) {
62 Duration duration =
63 new DurationImplementation(milliseconds: -inMilliseconds);
64 return "-${duration}";
65 }
66 String twoDigitMinutes =
67 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR));
68 String twoDigitSeconds =
69 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE));
70 String threeDigitMs =
71 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND));
72 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}";
73 }
74 }
OLDNEW
« no previous file with comments | « lib/coreimpl/date.dart ('k') | lib/coreimpl/exceptions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698