Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: corelib/src/date.dart

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

Powered by Google App Engine
This is Rietveld 408576698