| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Dart core library. | |
| 6 | |
| 7 /** | |
| 8 * Date is the public interface to a point in time. | |
| 9 * | |
| 10 * It can represent time values that are at a distance of at most | |
| 11 * 8,640,000,000,000,000ms (100,000,000 days) from epoch (1970-01-01 UTC). In | |
| 12 * other words: [:millisecondsSinceEpoch.abs() <= 8640000000000000:]. | |
| 13 * | |
| 14 * Also see [Stopwatch] for means to measure time-spans. | |
| 15 */ | |
| 16 interface Date extends Comparable, Hashable default DateImplementation { | |
| 17 // Weekday constants that are returned by [weekday] method: | |
| 18 static final int MON = 1; | |
| 19 static final int TUE = 2; | |
| 20 static final int WED = 3; | |
| 21 static final int THU = 4; | |
| 22 static final int FRI = 5; | |
| 23 static final int SAT = 6; | |
| 24 static final int SUN = 7; | |
| 25 static final int DAYS_IN_WEEK = 7; | |
| 26 | |
| 27 // Month constants that are returned by the [month] getter. | |
| 28 static final int JAN = 1; | |
| 29 static final int FEB = 2; | |
| 30 static final int MAR = 3; | |
| 31 static final int APR = 4; | |
| 32 static final int MAY = 5; | |
| 33 static final int JUN = 6; | |
| 34 static final int JUL = 7; | |
| 35 static final int AUG = 8; | |
| 36 static final int SEP = 9; | |
| 37 static final int OCT = 10; | |
| 38 static final int NOV = 11; | |
| 39 static final int DEC = 12; | |
| 40 | |
| 41 /** | |
| 42 * Constructs a [Date] instance based on the individual parts. The date is | |
| 43 * in the local time zone if [isUtc] is false. | |
| 44 * | |
| 45 * [month] and [day] are one-based. For example | |
| 46 * [:new Date(1938, 1, 10)] represents the 10th of January 1938. | |
| 47 */ | |
| 48 // TODO(floitsch): the spec allows default values in interfaces, but our | |
| 49 // tools don't yet. Eventually we want to have default values here. | |
| 50 Date(int year, | |
| 51 [int month, | |
| 52 int day, | |
| 53 int hour, | |
| 54 int minute, | |
| 55 int second, | |
| 56 int millisecond, | |
| 57 bool isUtc]); | |
| 58 | |
| 59 /** | |
| 60 * Constructs a new [Date] instance with current date time value in the | |
| 61 * local time zone. | |
| 62 */ | |
| 63 Date.now(); | |
| 64 | |
| 65 /** | |
| 66 * Constructs a new [Date] instance based on [formattedString]. | |
| 67 */ | |
| 68 Date.fromString(String formattedString); | |
| 69 | |
| 70 /** | |
| 71 * Constructs a new [Date] instance with the given [millisecondsSinceEpoch]. | |
| 72 * If [isUtc] is false then the date is in the local time zone. | |
| 73 * | |
| 74 * The constructed [Date] represents | |
| 75 * 1970-01-01T00:00:00Z + [millisecondsSinceEpoch]ms in the given | |
| 76 * time zone (local or UTC). | |
| 77 */ | |
| 78 // TODO(floitsch): the spec allows default values in interfaces, but our | |
| 79 // tools don't yet. Eventually we want to have default values here. | |
| 80 Date.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, [bool isUtc]); | |
| 81 | |
| 82 /** | |
| 83 * Returns true if [this] occurs at the same time as [other]. The | |
| 84 * comparison is independent of whether the time is utc or in the local | |
| 85 * time zone. | |
| 86 */ | |
| 87 bool operator ==(Date other); | |
| 88 /** | |
| 89 * Returns true if [this] occurs before [other]. The comparison is independent | |
| 90 * of whether the time is utc or in the local time zone. | |
| 91 */ | |
| 92 bool operator <(Date other); | |
| 93 /** | |
| 94 * Returns true if [this] occurs at the same time or before [other]. The | |
| 95 * comparison is independent of whether the time is utc or in the local | |
| 96 * time zone. | |
| 97 */ | |
| 98 bool operator <=(Date other); | |
| 99 /** | |
| 100 * Returns true if [this] occurs after [other]. The comparison is independent | |
| 101 * of whether the time is utc or in the local time zone. | |
| 102 */ | |
| 103 bool operator >(Date other); | |
| 104 /** | |
| 105 * Returns true if [this] occurs at the same time or after [other]. The | |
| 106 * comparison is independent of whether the time is utc or in the local | |
| 107 * time zone. | |
| 108 */ | |
| 109 bool operator >=(Date other); | |
| 110 | |
| 111 | |
| 112 /** | |
| 113 * Returns [this] in the local time zone. Returns itself if it is already in | |
| 114 * the local time zone. Otherwise, this method is equivalent to | |
| 115 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, false):]. | |
| 116 */ | |
| 117 Date toLocal(); | |
| 118 | |
| 119 /** | |
| 120 * Returns [this] in UTC. Returns itself if it is already in UTC. Otherwise, | |
| 121 * this method is equivalent to | |
| 122 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, true):]. | |
| 123 */ | |
| 124 Date toUtc(); | |
| 125 | |
| 126 /** | |
| 127 * Returns the abbreviated time-zone name. | |
| 128 * | |
| 129 * Examples: [:"CET":] or [:"CEST":]. | |
| 130 */ | |
| 131 String get timeZoneName(); | |
| 132 | |
| 133 /** | |
| 134 * The time-zone offset is the difference between local time and UTC. That is, | |
| 135 * the offset is positive for time zones west of UTC. | |
| 136 * | |
| 137 * Note, that JavaScript, Python and C return the difference between UTC and | |
| 138 * local time. Java, C# and Ruby return the difference between local time and | |
| 139 * UTC. | |
| 140 */ | |
| 141 Duration get timeZoneOffset(); | |
| 142 | |
| 143 /** | |
| 144 * Returns the year. | |
| 145 */ | |
| 146 int get year(); | |
| 147 | |
| 148 /** | |
| 149 * Returns the month into the year [1..12]. | |
| 150 */ | |
| 151 int get month(); | |
| 152 | |
| 153 /** | |
| 154 * Returns the day into the month [1..31]. | |
| 155 */ | |
| 156 int get day(); | |
| 157 | |
| 158 /** | |
| 159 * Returns the hour into the day [0..23]. | |
| 160 */ | |
| 161 int get hour(); | |
| 162 | |
| 163 /** | |
| 164 * Returns the minute into the hour [0...59]. | |
| 165 */ | |
| 166 int get minute(); | |
| 167 | |
| 168 /** | |
| 169 * Returns the second into the minute [0...59]. | |
| 170 */ | |
| 171 int get second(); | |
| 172 | |
| 173 /** | |
| 174 * Returns the millisecond into the second [0...999]. | |
| 175 */ | |
| 176 int get millisecond(); | |
| 177 | |
| 178 /** | |
| 179 * Returns the week day [MON..SUN]. In accordance with ISO 8601 | |
| 180 * a week starts with Monday which has the value 1. | |
| 181 */ | |
| 182 int get weekday(); | |
| 183 | |
| 184 /** | |
| 185 * The milliseconds since 1970-01-01T00:00:00Z (UTC). This value is | |
| 186 * independent of the time zone. | |
| 187 * | |
| 188 * See [Stopwatch] for means to measure time-spans. | |
| 189 */ | |
| 190 int get millisecondsSinceEpoch(); | |
| 191 | |
| 192 /** | |
| 193 * True if this [Date] is set to UTC time. | |
| 194 */ | |
| 195 bool get isUtc(); | |
| 196 | |
| 197 /** | |
| 198 * Returns a human readable string for this instance. | |
| 199 * The returned string is constructed for the time zone of this instance. | |
| 200 */ | |
| 201 String toString(); | |
| 202 | |
| 203 /** | |
| 204 * Returns a new [Date] with the [duration] added to this instance. | |
| 205 */ | |
| 206 Date add(Duration duration); | |
| 207 | |
| 208 /** | |
| 209 * Returns a new [Date] with the [duration] subtracted from this instance. | |
| 210 */ | |
| 211 Date subtract(Duration duration); | |
| 212 | |
| 213 /** | |
| 214 * Returns a [Duration] with the difference of [:this:] and [other]. | |
| 215 */ | |
| 216 Duration difference(Date other); | |
| 217 } | |
| OLD | NEW |