| 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 /** | 7 /** |
| 8 * Date is the public interface to a point in time. | 8 * Date is the public interface to a point in time. |
| 9 */ | 9 */ |
| 10 interface Date extends Comparable, Hashable default DateImplementation { | 10 interface Date extends Comparable, Hashable default DateImplementation { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 static final int MAY = 5; | 26 static final int MAY = 5; |
| 27 static final int JUN = 6; | 27 static final int JUN = 6; |
| 28 static final int JUL = 7; | 28 static final int JUL = 7; |
| 29 static final int AUG = 8; | 29 static final int AUG = 8; |
| 30 static final int SEP = 9; | 30 static final int SEP = 9; |
| 31 static final int OCT = 10; | 31 static final int OCT = 10; |
| 32 static final int NOV = 11; | 32 static final int NOV = 11; |
| 33 static final int DEC = 12; | 33 static final int DEC = 12; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Constructs a [Date] instance based on the individual parts, in the | 36 * Constructs a [Date] instance based on the individual parts. The date is |
| 37 * local time-zone. | 37 * in the local time-zone if [isUtc] is false. |
| 38 */ | 38 */ |
| 39 // TODO(floitsch): the spec allows default values in interfaces, but our | 39 // TODO(floitsch): the spec allows default values in interfaces, but our |
| 40 // tools don't yet. Eventually we want to have default values here. | 40 // tools don't yet. Eventually we want to have default values here. |
| 41 Date(int year, | 41 Date(int year, |
| 42 [int month, | 42 [int month, |
| 43 int day, | 43 int day, |
| 44 int hours, | 44 int hours, |
| 45 int minutes, | 45 int minutes, |
| 46 int seconds, | 46 int seconds, |
| 47 int milliseconds]); | 47 int milliseconds, |
| 48 bool isUtc]); |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * Constructs a [Date] instance based on the individual parts. | 51 * Constructs a [Date] instance based on the individual parts. |
| 51 * [timeZone] may not be [:null:]. | 52 * [timeZone] may not be [:null:]. |
| 53 * |
| 54 * *DEPRECATED* |
| 52 */ | 55 */ |
| 53 Date.withTimeZone(int year, | 56 Date.withTimeZone(int year, |
| 54 int month, | 57 int month, |
| 55 int day, | 58 int day, |
| 56 int hours, | 59 int hours, |
| 57 int minutes, | 60 int minutes, |
| 58 int seconds, | 61 int seconds, |
| 59 int milliseconds, | 62 int milliseconds, |
| 60 TimeZone timeZone); | 63 TimeZone timeZone); |
| 61 | 64 |
| 62 /** | 65 /** |
| 63 * Constructs a new [Date] instance with current date time value. | 66 * Constructs a new [Date] instance with current date time value in the |
| 64 * The [timeZone] of this instance is set to the local time-zone. | 67 * local time zone. |
| 65 */ | 68 */ |
| 66 Date.now(); | 69 Date.now(); |
| 67 | 70 |
| 68 /** | 71 /** |
| 69 * Constructs a new [Date] instance based on [formattedString]. | 72 * Constructs a new [Date] instance based on [formattedString]. |
| 70 */ | 73 */ |
| 71 Date.fromString(String formattedString); | 74 Date.fromString(String formattedString); |
| 72 | 75 |
| 73 /** | 76 /** |
| 74 * Constructs a new [Date] instance with the given time zone. The given | 77 * Constructs a new [Date] instance with the given [value]. If [isUtc] is |
| 75 * [timeZone] must not be [:null:]. | 78 * false then the date is in the local time-zone. |
| 76 * | |
| 77 * This constructor is the only one that doesn't need to be computations and | |
| 78 * which can therefore be [:const:]. | |
| 79 * | 79 * |
| 80 * The constructed [Date] represents 1970-01-01T00:00:00Z + [value]ms in | 80 * The constructed [Date] represents 1970-01-01T00:00:00Z + [value]ms in |
| 81 * the given [timeZone]. | 81 * the given time-zone (local or UTC). |
| 82 */ | 82 */ |
| 83 const Date.fromEpoch(int value, TimeZone timeZone); | 83 // TODO(floitsch): the spec allows default values in interfaces, but our |
| 84 // tools don't yet. Eventually we want to have default values here. |
| 85 Date.fromEpoch(int value, [bool isUtc]); |
| 84 | 86 |
| 85 /** | 87 /** |
| 88 * Returns true if [this] occurs at the same time as [other]. The |
| 89 * comparison is independent of whether the time is utc or in the local |
| 90 * time zone. |
| 91 */ |
| 92 bool operator ==(Date other); |
| 93 /** |
| 86 * Returns true if [this] occurs before [other]. The comparison is independent | 94 * Returns true if [this] occurs before [other]. The comparison is independent |
| 87 * of the timezone the [Date] is in. | 95 * of whether the time is utc or in the local time zone. |
| 88 */ | 96 */ |
| 89 bool operator <(Date other); | 97 bool operator <(Date other); |
| 90 /** | 98 /** |
| 91 * Returns true if [this] occurs at the same time or before [other]. The | 99 * Returns true if [this] occurs at the same time or before [other]. The |
| 92 * comparison is independent of the timezone the [Date] is in. | 100 * comparison is independent of whether the time is utc or in the local |
| 101 * time zone. |
| 93 */ | 102 */ |
| 94 bool operator <=(Date other); | 103 bool operator <=(Date other); |
| 95 /** | 104 /** |
| 96 * Returns true if [this] occurs after [other]. The comparison is independent | 105 * Returns true if [this] occurs after [other]. The comparison is independent |
| 97 * of the timezone the [Date] is in. | 106 * of whether the time is utc or in the local time zone. |
| 98 */ | 107 */ |
| 99 bool operator >(Date other); | 108 bool operator >(Date other); |
| 100 /** | 109 /** |
| 101 * Returns true if [this] occurs at the same time or after [other]. The | 110 * Returns true if [this] occurs at the same time or after [other]. The |
| 102 * comparison is independent of the timezone the [Date] is in. | 111 * comparison is independent of whether the time is utc or in the local |
| 112 * time zone. |
| 103 */ | 113 */ |
| 104 bool operator >=(Date other); | 114 bool operator >=(Date other); |
| 105 | 115 |
| 116 |
| 117 /** |
| 118 * Returns [this] in the local time-zone. Returns itself if it is already in |
| 119 * the local time zone. Otherwise, this method is equivalent to |
| 120 * [:new Date.fromEpoch(this.value, isUtc: false):]. |
| 121 */ |
| 122 Date toLocal(); |
| 123 |
| 124 /** |
| 125 * Returns [this] in UTC. Returns itself if it is already in UTC. Otherwise, |
| 126 * this method is equivalent to |
| 127 * [:new Date.fromEpoch(this.value, isUtc: true):]. |
| 128 */ |
| 129 Date toUtc(); |
| 130 |
| 106 /** | 131 /** |
| 107 * Returns a new [Date] in the given [targetTimeZone] time zone. The | 132 * Returns a new [Date] in the given [targetTimeZone] time zone. The |
| 108 * [value] of the new instance is equal to [:this.value:]. | 133 * [value] of the new instance is equal to [:this.value:]. |
| 109 * | 134 * |
| 110 * This call is equivalent to | 135 * This call is equivalent to |
| 111 * [:new Date.fromEpoch(this.value, targetTimeZone):]. | 136 * [:new Date.fromEpoch(this.value, targetTimeZone):]. |
| 137 * |
| 138 * *DEPRECATED* |
| 112 */ | 139 */ |
| 113 Date changeTimeZone(TimeZone targetTimeZone); | 140 Date changeTimeZone(TimeZone targetTimeZone); |
| 114 | 141 |
| 115 /** | 142 /** |
| 116 * Returns the abbreviated time-zone name. | 143 * Returns the abbreviated time-zone name. |
| 117 * | 144 * |
| 118 * Examples: [:"CET":] or [:"CEST":]. | 145 * Examples: [:"CET":] or [:"CEST":]. |
| 119 */ | 146 */ |
| 120 String get timeZoneName(); | 147 String get timeZoneName(); |
| 121 | 148 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 int get milliseconds(); | 192 int get milliseconds(); |
| 166 | 193 |
| 167 /** | 194 /** |
| 168 * Returns the week day [MON..SUN] | 195 * Returns the week day [MON..SUN] |
| 169 */ | 196 */ |
| 170 int get weekday(); | 197 int get weekday(); |
| 171 | 198 |
| 172 /** | 199 /** |
| 173 * Returns milliseconds from 1970-01-01T00:00:00Z (UTC). | 200 * Returns milliseconds from 1970-01-01T00:00:00Z (UTC). |
| 174 * | 201 * |
| 175 * Note that this value is independent of [timeZone]. | 202 * Note that this value is independent of the time zone. |
| 176 */ | 203 */ |
| 177 final int value; | 204 final int value; |
| 178 | 205 |
| 179 /** | 206 /** |
| 180 * Returns the timeZone of this instance. | |
| 181 */ | |
| 182 final TimeZone timeZone; | |
| 183 | |
| 184 /** | |
| 185 * Returns true if this [Date] is set to local time. | |
| 186 */ | |
| 187 bool isLocalTime(); | |
| 188 | |
| 189 /** | |
| 190 * Returns true if this [Date] is set to UTC time. | 207 * Returns true if this [Date] is set to UTC time. |
| 191 * This is equivalent to [:this.timeZone.isUtc():]. | |
| 192 */ | 208 */ |
| 193 bool isUtc(); | 209 bool isUtc(); |
| 194 | 210 |
| 195 /** | 211 /** |
| 196 * Returns a human readable string for this instance. | 212 * Returns a human readable string for this instance. |
| 197 * The returned string is constructed for the [timeZone] of this instance. | 213 * The returned string is constructed for the time zone of this instance. |
| 198 */ | 214 */ |
| 199 String toString(); | 215 String toString(); |
| 200 | 216 |
| 201 /** | 217 /** |
| 202 * Returns a new [Date] with the [duration] added to this instance. | 218 * Returns a new [Date] with the [duration] added to this instance. |
| 203 */ | 219 */ |
| 204 Date add(Duration duration); | 220 Date add(Duration duration); |
| 205 | 221 |
| 206 /** | 222 /** |
| 207 * Returns a new [Date] with the [duration] subtracted from this instance. | 223 * Returns a new [Date] with the [duration] subtracted from this instance. |
| 208 */ | 224 */ |
| 209 Date subtract(Duration duration); | 225 Date subtract(Duration duration); |
| 210 | 226 |
| 211 /** | 227 /** |
| 212 * Returns a [Duration] with the difference of [:this:] and [other]. | 228 * Returns a [Duration] with the difference of [:this:] and [other]. |
| 213 */ | 229 */ |
| 214 Duration difference(Date other); | 230 Duration difference(Date other); |
| 215 } | 231 } |
| OLD | NEW |