| 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 * It can represent time values that are at a distance of at most | 10 * It can represent time values that are at a distance of at most |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 static const int JUN = 6; | 33 static const int JUN = 6; |
| 34 static const int JUL = 7; | 34 static const int JUL = 7; |
| 35 static const int AUG = 8; | 35 static const int AUG = 8; |
| 36 static const int SEP = 9; | 36 static const int SEP = 9; |
| 37 static const int OCT = 10; | 37 static const int OCT = 10; |
| 38 static const int NOV = 11; | 38 static const int NOV = 11; |
| 39 static const int DEC = 12; | 39 static const int DEC = 12; |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Constructs a [Date] instance based on the individual parts. The date is | 42 * Constructs a [Date] instance based on the individual parts. The date is |
| 43 * in the local time zone if [isUtc] is false. | 43 * in the local time zone. |
| 44 * | 44 * |
| 45 * [month] and [day] are one-based. For example | 45 * [month] and [day] are one-based. For example |
| 46 * [:new Date(1938, 1, 10)] represents the 10th of January 1938. | 46 * [:new Date(1938, 1, 10):] represents the 10th of January 1938. |
| 47 */ | 47 */ |
| 48 factory Date(int year, | 48 factory Date(int year, |
| 49 [int month = 1, | 49 [int month = 1, |
| 50 int day = 1, | 50 int day = 1, |
| 51 int hour = 0, | 51 int hour = 0, |
| 52 int minute = 0, | 52 int minute = 0, |
| 53 int second = 0, | 53 int second = 0, |
| 54 int millisecond = 0, | 54 int millisecond = 0]) { |
| 55 bool isUtc = false]) { | |
| 56 return new DateImplementation(year, month, day, | 55 return new DateImplementation(year, month, day, |
| 57 hour, minute, second, | 56 hour, minute, second, |
| 58 millisecond, isUtc); | 57 millisecond, false); |
| 58 } |
| 59 |
| 60 /** |
| 61 * Constructs a [Date] instance based on the individual parts. The date is |
| 62 * in the UTC time zone. |
| 63 * |
| 64 * [month] and [day] are one-based. For example |
| 65 * [:new Date.utc(1938, 1, 10):] represents the 10th of January 1938 in |
| 66 * Coordinated Universal Time. |
| 67 */ |
| 68 factory Date.utc(int year, |
| 69 [int month = 1, |
| 70 int day = 1, |
| 71 int hour = 0, |
| 72 int minute = 0, |
| 73 int second = 0, |
| 74 int millisecond = 0]) { |
| 75 return new DateImplementation(year, month, day, |
| 76 hour, minute, second, |
| 77 millisecond, true); |
| 59 } | 78 } |
| 60 | 79 |
| 61 /** | 80 /** |
| 62 * Constructs a new [Date] instance with current date time value in the | 81 * Constructs a new [Date] instance with current date time value in the |
| 63 * local time zone. | 82 * local time zone. |
| 64 */ | 83 */ |
| 65 factory Date.now() => new DateImplementation.now(); | 84 factory Date.now() => new DateImplementation.now(); |
| 66 | 85 |
| 67 /** | 86 /** |
| 68 * Constructs a new [Date] instance based on [formattedString]. | 87 * Constructs a new [Date] instance based on [formattedString]. |
| 69 */ | 88 */ |
| 70 factory Date.fromString(String formattedString) | 89 factory Date.fromString(String formattedString) |
| 71 => new DateImplementation.fromString(formattedString); | 90 => new DateImplementation.fromString(formattedString); |
| 72 | 91 |
| 73 /** | 92 /** |
| 74 * Constructs a new [Date] instance with the given [millisecondsSinceEpoch]. | 93 * Constructs a new [Date] instance with the given [millisecondsSinceEpoch]. |
| 75 * If [isUtc] is false then the date is in the local time zone. | 94 * If [isUtc] is false then the date is in the local time zone. |
| 76 * | 95 * |
| 77 * The constructed [Date] represents | 96 * The constructed [Date] represents |
| 78 * 1970-01-01T00:00:00Z + [millisecondsSinceEpoch]ms in the given | 97 * 1970-01-01T00:00:00Z + [millisecondsSinceEpoch]ms in the given |
| 79 * time zone (local or UTC). | 98 * time zone (local or UTC). |
| 80 */ | 99 */ |
| 81 // TODO(floitsch): the spec allows default values in interfaces, but our | 100 // TODO(floitsch): the spec allows default values in interfaces, but our |
| 82 // tools don't yet. Eventually we want to have default values here. | 101 // tools don't yet. Eventually we want to have default values here. |
| 83 // TODO(lrn): Have two constructors instead of taking an optional bool. | 102 // TODO(lrn): Have two constructors instead of taking an optional bool. |
| 84 factory Date.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, | 103 factory Date.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, |
| 85 [bool isUtc = false]) { | 104 {bool isUtc: false}) { |
| 86 return new DateImplementation.fromMillisecondsSinceEpoch( | 105 return new DateImplementation.fromMillisecondsSinceEpoch( |
| 87 millisecondsSinceEpoch, isUtc); | 106 millisecondsSinceEpoch, isUtc); |
| 88 } | 107 } |
| 89 | 108 |
| 90 /** | 109 /** |
| 91 * Returns true if [this] occurs at the same time as [other]. The | 110 * Returns true if [this] occurs at the same time as [other]. The |
| 92 * comparison is independent of whether the time is utc or in the local | 111 * comparison is independent of whether the time is utc or in the local |
| 93 * time zone. | 112 * time zone. |
| 94 */ | 113 */ |
| 95 bool operator ==(Date other); | 114 bool operator ==(Date other); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 113 * Returns true if [this] occurs at the same time or after [other]. The | 132 * Returns true if [this] occurs at the same time or after [other]. The |
| 114 * comparison is independent of whether the time is utc or in the local | 133 * comparison is independent of whether the time is utc or in the local |
| 115 * time zone. | 134 * time zone. |
| 116 */ | 135 */ |
| 117 bool operator >=(Date other); | 136 bool operator >=(Date other); |
| 118 | 137 |
| 119 | 138 |
| 120 /** | 139 /** |
| 121 * Returns [this] in the local time zone. Returns itself if it is already in | 140 * Returns [this] in the local time zone. Returns itself if it is already in |
| 122 * the local time zone. Otherwise, this method is equivalent to | 141 * the local time zone. Otherwise, this method is equivalent to |
| 123 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, false):]. | 142 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
| 143 * isUtc: false):]. |
| 124 */ | 144 */ |
| 125 Date toLocal(); | 145 Date toLocal(); |
| 126 | 146 |
| 127 /** | 147 /** |
| 128 * Returns [this] in UTC. Returns itself if it is already in UTC. Otherwise, | 148 * Returns [this] in UTC. Returns itself if it is already in UTC. Otherwise, |
| 129 * this method is equivalent to | 149 * this method is equivalent to |
| 130 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, true):]. | 150 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, |
| 151 * isUtc: true):]. |
| 131 */ | 152 */ |
| 132 Date toUtc(); | 153 Date toUtc(); |
| 133 | 154 |
| 134 /** | 155 /** |
| 135 * Returns the abbreviated time-zone name. | 156 * Returns the abbreviated time-zone name. |
| 136 * | 157 * |
| 137 * Examples: [:"CET":] or [:"CEST":]. | 158 * Examples: [:"CET":] or [:"CEST":]. |
| 138 */ | 159 */ |
| 139 String get timeZoneName; | 160 String get timeZoneName; |
| 140 | 161 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 /** | 237 /** |
| 217 * Returns a new [Date] with the [duration] subtracted from this instance. | 238 * Returns a new [Date] with the [duration] subtracted from this instance. |
| 218 */ | 239 */ |
| 219 Date subtract(Duration duration); | 240 Date subtract(Duration duration); |
| 220 | 241 |
| 221 /** | 242 /** |
| 222 * Returns a [Duration] with the difference of [:this:] and [other]. | 243 * Returns a [Duration] with the difference of [:this:] and [other]. |
| 223 */ | 244 */ |
| 224 Duration difference(Date other); | 245 Duration difference(Date other); |
| 225 } | 246 } |
| OLD | NEW |