| 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 // Dart core library. | 5 // Dart core library. |
| 6 | 6 |
| 7 class DurationImplementation implements Duration { | 7 class DurationImplementation implements Duration { |
| 8 final int _durationInMilliseconds; | 8 final int inMilliseconds; |
| 9 | 9 |
| 10 const DurationImplementation([int days = 0, | 10 const DurationImplementation([int days = 0, |
| 11 int hours = 0, | 11 int hours = 0, |
| 12 int minutes = 0, | 12 int minutes = 0, |
| 13 int seconds = 0, | 13 int seconds = 0, |
| 14 int milliseconds = 0]) | 14 int milliseconds = 0]) |
| 15 : _durationInMilliseconds = days * Duration.MILLISECONDS_PER_DAY + | 15 : inMilliseconds = days * Duration.MILLISECONDS_PER_DAY + |
| 16 hours * Duration.MILLISECONDS_PER_HOUR + | 16 hours * Duration.MILLISECONDS_PER_HOUR + |
| 17 minutes * Duration.MILLISECONDS_PER_MINUTE + | 17 minutes * Duration.MILLISECONDS_PER_MINUTE + |
| 18 seconds * Duration.MILLISECONDS_PER_SECOND + | 18 seconds * Duration.MILLISECONDS_PER_SECOND + |
| 19 milliseconds; | 19 milliseconds; |
| 20 | 20 |
| 21 int get inDays() { | 21 int get inDays() { |
| 22 return _durationInMilliseconds ~/ Duration.MILLISECONDS_PER_DAY; | 22 return inMilliseconds ~/ Duration.MILLISECONDS_PER_DAY; |
| 23 } | 23 } |
| 24 | 24 |
| 25 int get inHours() { | 25 int get inHours() { |
| 26 return _durationInMilliseconds ~/ Duration.MILLISECONDS_PER_HOUR; | 26 return inMilliseconds ~/ Duration.MILLISECONDS_PER_HOUR; |
| 27 } | 27 } |
| 28 | 28 |
| 29 int get inMinutes() { | 29 int get inMinutes() { |
| 30 return _durationInMilliseconds ~/ Duration.MILLISECONDS_PER_MINUTE; | 30 return inMilliseconds ~/ Duration.MILLISECONDS_PER_MINUTE; |
| 31 } | 31 } |
| 32 | 32 |
| 33 int get inSeconds() { | 33 int get inSeconds() { |
| 34 return _durationInMilliseconds ~/ Duration.MILLISECONDS_PER_SECOND; | 34 return inMilliseconds ~/ Duration.MILLISECONDS_PER_SECOND; |
| 35 } | |
| 36 | |
| 37 int get inMilliseconds() { | |
| 38 return _durationInMilliseconds; | |
| 39 } | 35 } |
| 40 | 36 |
| 41 bool operator ==(other) { | 37 bool operator ==(other) { |
| 42 if (!(other is DurationImplementation)) return false; | 38 if (other is !Duration) return false; |
| 43 return _durationInMilliseconds == other.inMilliseconds; | 39 return inMilliseconds == other.inMilliseconds; |
| 44 } | 40 } |
| 45 | 41 |
| 46 int hashCode() { | 42 int hashCode() { |
| 47 return _durationInMilliseconds.hashCode(); | 43 return inMilliseconds.hashCode(); |
| 48 } | 44 } |
| 49 | 45 |
| 50 int compareTo(Duration other) { | 46 int compareTo(Duration other) { |
| 51 return inMilliseconds.compareTo(other.inMilliseconds); | 47 return inMilliseconds.compareTo(other.inMilliseconds); |
| 52 } | 48 } |
| 53 | 49 |
| 54 String toString() { | 50 String toString() { |
| 55 String threeDigits(int n) { | 51 String threeDigits(int n) { |
| 56 if (n >= 100) return "${n}"; | 52 if (n >= 100) return "${n}"; |
| 57 if (n > 10) return "0${n}"; | 53 if (n > 10) return "0${n}"; |
| 58 return "00${n}"; | 54 return "00${n}"; |
| 59 } | 55 } |
| 60 String twoDigits(int n) { | 56 String twoDigits(int n) { |
| 61 if (n >= 10) return "${n}"; | 57 if (n >= 10) return "${n}"; |
| 62 return "0${n}"; | 58 return "0${n}"; |
| 63 } | 59 } |
| 64 | 60 |
| 65 if (_durationInMilliseconds < 0) { | 61 if (inMilliseconds < 0) { |
| 66 Duration duration = | 62 Duration duration = |
| 67 new DurationImplementation(milliseconds: -_durationInMilliseconds); | 63 new DurationImplementation(milliseconds: -inMilliseconds); |
| 68 return "-${duration}"; | 64 return "-${duration}"; |
| 69 } | 65 } |
| 70 String twoDigitMinutes = | 66 String twoDigitMinutes = |
| 71 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); | 67 twoDigits(inMinutes.remainder(Duration.MINUTES_PER_HOUR)); |
| 72 String twoDigitSeconds = | 68 String twoDigitSeconds = |
| 73 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); | 69 twoDigits(inSeconds.remainder(Duration.SECONDS_PER_MINUTE)); |
| 74 String threeDigitMs = | 70 String threeDigitMs = |
| 75 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); | 71 threeDigits(inMilliseconds.remainder(Duration.MILLISECONDS_PER_SECOND)); |
| 76 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}"; | 72 return "${inHours}:${twoDigitMinutes}:${twoDigitSeconds}.${threeDigitMs}"; |
| 77 } | 73 } |
| 78 } | 74 } |
| OLD | NEW |