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

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: rebase 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;
Lasse Reichstein Nielsen 2012/06/19 14:32:18 Are there definitions for JAN...DEC? Preferably on
floitsch 2012/06/20 08:25:24 one line below?
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.
42 */ 44 */
43 // TODO(floitsch): the spec allows default values in interfaces, but our 45 // TODO(floitsch): the spec allows default values in interfaces, but our
44 // tools don't yet. Eventually we want to have default values here. 46 // tools don't yet. Eventually we want to have default values here.
45 Date(int year, 47 Date(int year,
46 [int month, 48 [int month,
Lasse Reichstein Nielsen 2012/06/19 14:32:18 Is "month" zero or one-based? Are overflowing valu
floitsch 2012/06/20 08:25:24 1-based (added comment).
47 int day, 49 int day,
Lasse Reichstein Nielsen 2012/06/19 14:32:18 Should month and day really be optional? It makes
floitsch 2012/06/20 08:25:24 See http://dartbug/2582. Apparently requiring mont
48 int hours, 50 int hour,
49 int minutes, 51 int minute,
50 int seconds, 52 int second,
51 int milliseconds, 53 int millisecond,
52 bool isUtc]); 54 bool isUtc]);
53 55
54 /** 56 /**
55 * Constructs a new [Date] instance with current date time value in the 57 * Constructs a new [Date] instance with current date time value in the
56 * local time zone. 58 * local time zone.
57 */ 59 */
58 Date.now(); 60 Date.now();
59 61
60 /** 62 /**
61 * Constructs a new [Date] instance based on [formattedString]. 63 * Constructs a new [Date] instance based on [formattedString].
62 */ 64 */
63 Date.fromString(String formattedString); 65 Date.fromString(String formattedString);
64 66
65 /** 67 /**
66 * Constructs a new [Date] instance with the given [value]. If [isUtc] is 68 * Constructs a new [Date] instance with the given [millisecondsSinceEpoch].
67 * false then the date is in the local time zone. 69 * If [isUtc] is false then the date is in the local time zone.
68 * 70 *
69 * The constructed [Date] represents 1970-01-01T00:00:00Z + [value]ms in 71 * The constructed [Date] represents
70 * the given time zone (local or UTC). 72 * 1970-01-01T00:00:00Z + [millisecondsSinceEpoch]ms in the given
73 * time zone (local or UTC).
71 */ 74 */
72 // TODO(floitsch): the spec allows default values in interfaces, but our 75 // TODO(floitsch): the spec allows default values in interfaces, but our
73 // tools don't yet. Eventually we want to have default values here. 76 // tools don't yet. Eventually we want to have default values here.
74 Date.fromEpoch(int value, [bool isUtc]); 77 Date.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, [bool isUtc]);
75 78
76 /** 79 /**
77 * Returns true if [this] occurs at the same time as [other]. The 80 * 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 81 * comparison is independent of whether the time is utc or in the local
79 * time zone. 82 * time zone.
80 */ 83 */
81 bool operator ==(Date other); 84 bool operator ==(Date other);
82 /** 85 /**
83 * Returns true if [this] occurs before [other]. The comparison is independent 86 * Returns true if [this] occurs before [other]. The comparison is independent
84 * of whether the time is utc or in the local time zone. 87 * 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 102 * 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 103 * comparison is independent of whether the time is utc or in the local
101 * time zone. 104 * time zone.
102 */ 105 */
103 bool operator >=(Date other); 106 bool operator >=(Date other);
104 107
105 108
106 /** 109 /**
107 * Returns [this] in the local time zone. Returns itself if it is already in 110 * 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 111 * the local time zone. Otherwise, this method is equivalent to
109 * [:new Date.fromEpoch(this.value, isUtc: false):]. 112 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, false):].
110 */ 113 */
111 Date toLocal(); 114 Date toLocal();
112 115
113 /** 116 /**
114 * Returns [this] in UTC. Returns itself if it is already in UTC. Otherwise, 117 * Returns [this] in UTC. Returns itself if it is already in UTC. Otherwise,
115 * this method is equivalent to 118 * this method is equivalent to
116 * [:new Date.fromEpoch(this.value, isUtc: true):]. 119 * [:new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, true):].
117 */ 120 */
118 Date toUtc(); 121 Date toUtc();
119 122
120 /** 123 /**
121 * Returns the abbreviated time-zone name. 124 * Returns the abbreviated time-zone name.
122 * 125 *
123 * Examples: [:"CET":] or [:"CEST":]. 126 * Examples: [:"CET":] or [:"CEST":].
124 */ 127 */
125 String get timeZoneName(); 128 String get timeZoneName();
126 129
(...skipping 16 matching lines...) Expand all
143 * Returns the month in the year [1..12]. 146 * Returns the month in the year [1..12].
144 */ 147 */
145 int get month(); 148 int get month();
146 149
147 /** 150 /**
148 * Returns the day in the month [1..31]. 151 * Returns the day in the month [1..31].
149 */ 152 */
150 int get day(); 153 int get day();
151 154
152 /** 155 /**
153 * Returns the number of hours [0..23]. 156 * Returns the hour in the day [0..23].
Lasse Reichstein Nielsen 2012/06/19 14:32:18 "in" -> "into". There are always 24 hours in the d
floitsch 2012/06/20 08:25:24 Done.
154 */ 157 */
155 int get hours(); 158 int get hour();
156 159
157 /** 160 /**
158 * Returns the number of minutes [0...59]. 161 * Returns the minute in the hour [0...59].
Lasse Reichstein Nielsen 2012/06/19 14:32:18 "in" -> "into" again.
floitsch 2012/06/20 08:25:24 Done.
159 */ 162 */
160 int get minutes(); 163 int get minute();
161 164
162 /** 165 /**
163 * Returns the number of seconds [0...59]. 166 * Returns the second in the minute [0...59].
Lasse Reichstein Nielsen 2012/06/19 14:32:18 And again. We are absolutely certain we won't need
floitsch 2012/06/20 08:25:24 I think so. If leap-seconds are an issue some syst
164 */ 167 */
165 int get seconds(); 168 int get second();
166 169
167 /** 170 /**
168 * Returns the number of milliseconds [0...999]. 171 * Returns the millisecond in the second [0...999].
Lasse Reichstein Nielsen 2012/06/19 14:32:18 And again.
floitsch 2012/06/20 08:25:24 Done.
169 */ 172 */
170 int get milliseconds(); 173 int get millisecond();
171 174
172 /** 175 /**
173 * Returns the week day [MON..SUN] 176 * Returns the week day [MON..SUN]. In accordance with ISO 8601
177 * a week starts with Monday which has the value 1.
174 */ 178 */
175 int get weekday(); 179 int get weekday();
176 180
177 /** 181 /**
178 * Returns milliseconds from 1970-01-01T00:00:00Z (UTC). 182 * The milliseconds since 1970-01-01T00:00:00Z (UTC). This value is
183 * independent of the time zone.
179 * 184 *
180 * Note that this value is independent of the time zone. 185 * See [Stopwatch] for means to measure time-spans.
181 */ 186 */
182 final int value; 187 int get millisecondsSinceEpoch();
183 188
184 /** 189 /**
185 * Returns true if this [Date] is set to UTC time. 190 * True if this [Date] is set to UTC time.
186 */ 191 */
187 bool isUtc(); 192 bool get isUtc();
188 193
189 /** 194 /**
190 * Returns a human readable string for this instance. 195 * Returns a human readable string for this instance.
191 * The returned string is constructed for the time zone of this instance. 196 * The returned string is constructed for the time zone of this instance.
192 */ 197 */
193 String toString(); 198 String toString();
194 199
195 /** 200 /**
196 * Returns a new [Date] with the [duration] added to this instance. 201 * Returns a new [Date] with the [duration] added to this instance.
197 */ 202 */
198 Date add(Duration duration); 203 Date add(Duration duration);
199 204
200 /** 205 /**
201 * Returns a new [Date] with the [duration] subtracted from this instance. 206 * Returns a new [Date] with the [duration] subtracted from this instance.
202 */ 207 */
203 Date subtract(Duration duration); 208 Date subtract(Duration duration);
204 209
205 /** 210 /**
206 * Returns a [Duration] with the difference of [:this:] and [other]. 211 * Returns a [Duration] with the difference of [:this:] and [other].
207 */ 212 */
208 Duration difference(Date other); 213 Duration difference(Date other);
209 } 214 }
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