Chromium Code Reviews| 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 // Dart core library. | 4 // Dart core library. |
| 5 | 5 |
| 6 class TimeZoneImplementation implements TimeZone { | 6 class TimeZoneImplementation implements TimeZone { |
| 7 const TimeZoneImplementation.utc() : isUtc = true; | 7 const TimeZoneImplementation.utc() : isUtc = true; |
| 8 TimeZoneImplementation.local() : isUtc = false {} | 8 TimeZoneImplementation.local() : isUtc = false {} |
| 9 | 9 |
| 10 bool operator ==(Object other) { | 10 bool operator ==(Object other) { |
| 11 if (!(other is TimeZoneImplementation)) return false; | 11 if (!(other is TimeZoneImplementation)) return false; |
| 12 return isUtc == other.isUtc; | 12 return isUtc == other.isUtc; |
| 13 } | 13 } |
| 14 | 14 |
| 15 final bool isUtc; | 15 final bool isUtc; |
| 16 } | 16 } |
| 17 | 17 |
| 18 // JavaScript implementation of DateImplementation. | 18 // JavaScript implementation of DateImplementation. |
| 19 class DateImplementation implements Date { | 19 class DateImplementation implements Date { |
| 20 factory DateImplementation(int years, | 20 factory DateImplementation(int years, |
| 21 int month, | 21 [int month = 1, |
| 22 int day, | 22 int day = 1, |
| 23 int hours, | 23 int hours = 0, |
| 24 int minutes, | 24 int minutes = 0, |
| 25 int seconds, | 25 int seconds = 0, |
| 26 int milliseconds) { | 26 int milliseconds = 0]) { |
| 27 return new DateImplementation.withTimeZone( | 27 return new DateImplementation.withTimeZone( |
| 28 years, month, day, | 28 years, month, day, |
| 29 hours, minutes, seconds, milliseconds, | 29 hours, minutes, seconds, milliseconds, |
| 30 new TimeZoneImplementation.local()); | 30 new TimeZoneImplementation.local()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 DateImplementation.withTimeZone(int years, | 33 DateImplementation.withTimeZone(int years, |
| 34 int month, | 34 int month, |
| 35 int day, | 35 int day, |
| 36 int hours, | 36 int hours, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 } | 105 } |
| 106 | 106 |
| 107 const DateImplementation.fromEpoch(int this.value, | 107 const DateImplementation.fromEpoch(int this.value, |
| 108 TimeZone this.timeZone); | 108 TimeZone this.timeZone); |
| 109 | 109 |
| 110 bool operator ==(Object other) { | 110 bool operator ==(Object other) { |
| 111 if (!(other is DateImplementation)) return false; | 111 if (!(other is DateImplementation)) return false; |
| 112 return value == other.value && timeZone == other.timeZone; | 112 return value == other.value && timeZone == other.timeZone; |
| 113 } | 113 } |
| 114 | 114 |
| 115 int compareTo(Date other) => value.compareTo(other.value); | 115 int compareTo(Date other) { |
| 116 int hashCode() => value; | 116 return value.compareTo(other.value); |
|
ngeoffray
2012/05/15 12:17:35
bad mergE?
floitsch
2012/05/15 12:34:22
Done.
| |
| 117 } | |
| 117 | 118 |
| 118 Date changeTimeZone(TimeZone targetTimeZone) { | 119 Date changeTimeZone(TimeZone targetTimeZone) { |
| 119 if (targetTimeZone === null) { | 120 if (targetTimeZone === null) { |
| 120 targetTimeZone = new TimeZoneImplementation.local(); | 121 targetTimeZone = new TimeZoneImplementation.local(); |
| 121 } | 122 } |
| 122 return new Date.fromEpoch(value, targetTimeZone); | 123 return new Date.fromEpoch(value, targetTimeZone); |
| 123 } | 124 } |
| 124 | 125 |
| 125 int get year() { | 126 int get year() { |
| 126 int secondsSinceEpoch = secondsSinceEpoch_; | 127 int secondsSinceEpoch = secondsSinceEpoch_; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 String fourDigits(int n) { | 203 String fourDigits(int n) { |
| 203 int absN = n.abs(); | 204 int absN = n.abs(); |
| 204 String sign = n < 0 ? "-" : ""; | 205 String sign = n < 0 ? "-" : ""; |
| 205 if (absN >= 1000) return "$n"; | 206 if (absN >= 1000) return "$n"; |
| 206 if (absN >= 100) return "${sign}0$absN"; | 207 if (absN >= 100) return "${sign}0$absN"; |
| 207 if (absN >= 10) return "${sign}00$absN"; | 208 if (absN >= 10) return "${sign}00$absN"; |
| 208 if (absN >= 1) return "${sign}000$absN"; | 209 if (absN >= 1) return "${sign}000$absN"; |
| 209 } | 210 } |
| 210 String threeDigits(int n) { | 211 String threeDigits(int n) { |
| 211 if (n >= 100) return "${n}"; | 212 if (n >= 100) return "${n}"; |
| 212 if (n >= 10) return "0${n}"; | 213 if (n > 10) return "0${n}"; |
|
ngeoffray
2012/05/15 12:17:35
ditto?
floitsch
2012/05/15 12:34:22
Done.
| |
| 213 return "00${n}"; | 214 return "00${n}"; |
| 214 } | 215 } |
| 215 String twoDigits(int n) { | 216 String twoDigits(int n) { |
| 216 if (n >= 10) return "${n}"; | 217 if (n >= 10) return "${n}"; |
| 217 return "0${n}"; | 218 return "0${n}"; |
| 218 } | 219 } |
| 219 | 220 |
| 220 String y = fourDigits(year); | 221 String y = fourDigits(year); |
| 221 String m = twoDigits(month); | 222 String m = twoDigits(month); |
| 222 String d = twoDigits(day); | 223 String d = twoDigits(day); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 | 407 |
| 407 static int getHours_(int secondsSinceEpoch, bool isUtc) | 408 static int getHours_(int secondsSinceEpoch, bool isUtc) |
| 408 native "DateNatives_getHours"; | 409 native "DateNatives_getHours"; |
| 409 | 410 |
| 410 static int getMinutes_(int secondsSinceEpoch, bool isUtc) | 411 static int getMinutes_(int secondsSinceEpoch, bool isUtc) |
| 411 native "DateNatives_getMinutes"; | 412 native "DateNatives_getMinutes"; |
| 412 | 413 |
| 413 static int getSeconds_(int secondsSinceEpoch, bool isUtc) | 414 static int getSeconds_(int secondsSinceEpoch, bool isUtc) |
| 414 native "DateNatives_getSeconds"; | 415 native "DateNatives_getSeconds"; |
| 415 } | 416 } |
| OLD | NEW |