| OLD | NEW |
| (Empty) |
| 1 part of dart.core; | |
| 2 class Duration implements Comparable<Duration> {static const int MICROSECONDS_P
ER_MILLISECOND = 1000; | |
| 3 static const int MILLISECONDS_PER_SECOND = 1000; | |
| 4 static const int SECONDS_PER_MINUTE = 60; | |
| 5 static const int MINUTES_PER_HOUR = 60; | |
| 6 static const int HOURS_PER_DAY = 24; | |
| 7 static const int MICROSECONDS_PER_SECOND = MICROSECONDS_PER_MILLISECOND * MILLI
SECONDS_PER_SECOND; | |
| 8 static const int MICROSECONDS_PER_MINUTE = MICROSECONDS_PER_SECOND * SECONDS_PE
R_MINUTE; | |
| 9 static const int MICROSECONDS_PER_HOUR = MICROSECONDS_PER_MINUTE * MINUTES_PER_
HOUR; | |
| 10 static const int MICROSECONDS_PER_DAY = MICROSECONDS_PER_HOUR * HOURS_PER_DAY; | |
| 11 static const int MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * SECONDS_PE
R_MINUTE; | |
| 12 static const int MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * MINUTES_PER_
HOUR; | |
| 13 static const int MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * HOURS_PER_DAY; | |
| 14 static const int SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR; | |
| 15 static const int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; | |
| 16 static const int MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY; | |
| 17 static const Duration ZERO = const Duration(seconds: 0); | |
| 18 final int _duration; | |
| 19 const Duration({ | |
| 20 int days : 0, int hours : 0, int minutes : 0, int seconds : 0, int millisecond
s : 0, int microseconds : 0} | |
| 21 ) : this._microseconds(days * MICROSECONDS_PER_DAY + hours * MICROSECONDS_PER_HO
UR + minutes * MICROSECONDS_PER_MINUTE + seconds * MICROSECONDS_PER_SECOND + mil
liseconds * MICROSECONDS_PER_MILLISECOND + microseconds); | |
| 22 const Duration._microseconds(this._duration); | |
| 23 Duration operator +(Duration other) { | |
| 24 return new Duration._microseconds(_duration + other._duration); | |
| 25 } | |
| 26 Duration operator -(Duration other) { | |
| 27 return new Duration._microseconds(_duration - other._duration); | |
| 28 } | |
| 29 Duration operator *(num factor) { | |
| 30 return new Duration._microseconds((_duration * factor).round()); | |
| 31 } | |
| 32 Duration operator ~/(int quotient) { | |
| 33 if (quotient == 0) throw new IntegerDivisionByZeroException(); | |
| 34 return new Duration._microseconds(_duration ~/ quotient); | |
| 35 } | |
| 36 bool operator <(Duration other) => this._duration < other._duration; | |
| 37 bool operator >(Duration other) => this._duration > other._duration; | |
| 38 bool operator <=(Duration other) => this._duration <= other._duration; | |
| 39 bool operator >=(Duration other) => this._duration >= other._duration; | |
| 40 int get inDays => _duration ~/ Duration.MICROSECONDS_PER_DAY; | |
| 41 int get inHours => _duration ~/ Duration.MICROSECONDS_PER_HOUR; | |
| 42 int get inMinutes => _duration ~/ Duration.MICROSECONDS_PER_MINUTE; | |
| 43 int get inSeconds => _duration ~/ Duration.MICROSECONDS_PER_SECOND; | |
| 44 int get inMilliseconds => _duration ~/ Duration.MICROSECONDS_PER_MILLISECOND; | |
| 45 int get inMicroseconds => _duration; | |
| 46 bool operator ==(other) { | |
| 47 if (other is! Duration) return false; | |
| 48 return _duration == other._duration; | |
| 49 } | |
| 50 int get hashCode => _duration.hashCode; | |
| 51 int compareTo(Duration other) => _duration.compareTo(other._duration); | |
| 52 String toString() { | |
| 53 String sixDigits(int n) { | |
| 54 if (n >= 100000) return "$n"; | |
| 55 if (n >= 10000) return "0$n"; | |
| 56 if (n >= 1000) return "00$n"; | |
| 57 if (n >= 100) return "000$n"; | |
| 58 if (n >= 10) return "0000$n"; | |
| 59 return "00000$n"; | |
| 60 } | |
| 61 String twoDigits(int n) { | |
| 62 if (n >= 10) return "$n"; | |
| 63 return "0$n"; | |
| 64 } | |
| 65 if (inMicroseconds < 0) { | |
| 66 return "-${-this}"; | |
| 67 } | |
| 68 String twoDigitMinutes = twoDigits(((__x0) => DEVC$RT.cast(__x0, num, int, "I
mplicitCast", """line 258, column 40 of dart:core/duration.dart: """, __x0 is in
t, true))(inMinutes.remainder(MINUTES_PER_HOUR))); | |
| 69 String twoDigitSeconds = twoDigits(((__x1) => DEVC$RT.cast(__x1, num, int, "I
mplicitCast", """line 259, column 40 of dart:core/duration.dart: """, __x1 is in
t, true))(inSeconds.remainder(SECONDS_PER_MINUTE))); | |
| 70 String sixDigitUs = sixDigits(((__x2) => DEVC$RT.cast(__x2, num, int, "Implic
itCast", """line 261, column 19 of dart:core/duration.dart: """, __x2 is int, tr
ue))(inMicroseconds.remainder(MICROSECONDS_PER_SECOND))); | |
| 71 return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs"; | |
| 72 } | |
| 73 bool get isNegative => _duration < 0; | |
| 74 Duration abs() => new Duration._microseconds(_duration.abs()); | |
| 75 Duration operator -() => new Duration._microseconds(-_duration); | |
| 76 } | |
| OLD | NEW |