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

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

Issue 10384149: Refactor Date. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 8 years, 7 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
« no previous file with comments | « no previous file | corelib/src/time_zone.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Returns the local time-zone as defined in the official zone.tab file.
9 *
10 * Examples: [:"Europe/Andorra":], [:"America/Los_Angeles":] or
11 * [:"Europe/Paris":].
12 *
13 * If the underlying implementation is unable to get the timezone string
14 * returns the offset to UTC prefixed with "GMT". Examples: [:"GMT+03":],
15 * [:"GMT-02":], or [:"GTM+04:30":].
16 */
17 String get timeZoneName() => DateImplementation.timeZoneName();
18
19 /** Returns the current local time-zone's offset to UTC. */
20 Duration get timeZoneOffset() => DateImplementation.timeZoneOffset();
21
22 /**
8 * Date is the public interface to a point in time. 23 * Date is the public interface to a point in time.
9 */ 24 */
10 interface Date extends Comparable, Hashable default DateImplementation { 25 interface Date extends Comparable, Hashable default DateImplementation {
11 // Weekday constants that are returned by [weekday] method: 26 // Weekday constants that are returned by [weekday] method:
12 static final int MON = 0; 27 static final int MON = 0;
13 static final int TUE = 1; 28 static final int TUE = 1;
14 static final int WED = 2; 29 static final int WED = 2;
15 static final int THU = 3; 30 static final int THU = 3;
16 static final int FRI = 4; 31 static final int FRI = 4;
17 static final int SAT = 5; 32 static final int SAT = 5;
(...skipping 22 matching lines...) Expand all
40 // tools don't yet. Eventually we want to have default values here. 55 // tools don't yet. Eventually we want to have default values here.
41 Date(int year, 56 Date(int year,
42 [int month, 57 [int month,
43 int day, 58 int day,
44 int hours, 59 int hours,
45 int minutes, 60 int minutes,
46 int seconds, 61 int seconds,
47 int milliseconds]); 62 int milliseconds]);
48 63
49 /** 64 /**
50 * Constructs a [Date] instance based on the individual parts. 65 * Constructs a new [Date] instance with current date time value in the
51 * [timeZone] may not be [:null:]. 66 * local time-zone.
52 */
53 Date.withTimeZone(int year,
54 int month,
55 int day,
56 int hours,
57 int minutes,
58 int seconds,
59 int milliseconds,
60 TimeZone timeZone);
61
62 /**
63 * Constructs a new [Date] instance with current date time value.
64 * The [timeZone] of this instance is set to the local time-zone.
65 */ 67 */
66 Date.now(); 68 Date.now();
67 69
68 /** 70 /**
69 * Constructs a new [Date] instance based on [formattedString]. 71 * Constructs a new [Date] instance based on [formattedString].
70 */ 72 */
71 Date.fromString(String formattedString); 73 Date.fromString(String formattedString);
72 74
73 /** 75 /**
74 * Constructs a new [Date] instance with the given time zone. The given 76 * Constructs a new [Date] instance in the local time-zone.
75 * [timeZone] must not be [:null:].
76 * 77 *
77 * This constructor is the only one that doesn't need to be computations and 78 * This constructor is the only one that doesn't need to be computations and
78 * which can therefore be [:const:]. 79 * which can therefore be [:const:].
79 * 80 *
80 * The constructed [Date] represents 1970-01-01T00:00:00Z + [value]ms in 81 * The constructed [Date] represents 1970-01-01T00:00:00Z + [value]ms in
81 * the given [timeZone]. 82 * the local time-zone.
82 */ 83 */
83 const Date.fromEpoch(int value, TimeZone timeZone); 84 const Date.fromEpoch(int value);
84 85
85 /** 86 /**
86 * Returns true if [this] occurs before [other]. The comparison is independent 87 * Returns true if [this] occurs before [other]. The comparison is independent
87 * of the timezone the [Date] is in. 88 * of the timezone the [Date] is in.
88 */ 89 */
89 bool operator <(Date other); 90 bool operator <(Date other);
90 /** 91 /**
91 * Returns true if [this] occurs at the same time or before [other]. The 92 * Returns true if [this] occurs at the same time or before [other]. The
92 * comparison is independent of the timezone the [Date] is in. 93 * comparison is independent of the timezone the [Date] is in.
93 */ 94 */
94 bool operator <=(Date other); 95 bool operator <=(Date other);
95 /** 96 /**
96 * Returns true if [this] occurs after [other]. The comparison is independent 97 * Returns true if [this] occurs after [other]. The comparison is independent
97 * of the timezone the [Date] is in. 98 * of the timezone the [Date] is in.
98 */ 99 */
99 bool operator >(Date other); 100 bool operator >(Date other);
100 /** 101 /**
101 * 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
102 * comparison is independent of the timezone the [Date] is in. 103 * comparison is independent of the timezone the [Date] is in.
103 */ 104 */
104 bool operator >=(Date other); 105 bool operator >=(Date other);
105 106
106 /** 107 /**
107 * Returns a new [Date] in the given [targetTimeZone] time zone. The
108 * [value] of the new instance is equal to [:this.value:].
109 *
110 * This call is equivalent to
111 * [:new Date.fromEpoch(this.value, targetTimeZone):].
112 */
113 Date changeTimeZone(TimeZone targetTimeZone);
114
115 /**
116 * Returns the year. 108 * Returns the year.
117 */ 109 */
118 int get year(); 110 int get year();
119 111
120 /** 112 /**
121 * Returns the month in the year [1..12]. 113 * Returns the month in the year [1..12].
122 */ 114 */
123 int get month(); 115 int get month();
124 116
125 /** 117 /**
(...skipping 22 matching lines...) Expand all
148 int get milliseconds(); 140 int get milliseconds();
149 141
150 /** 142 /**
151 * Returns the week day [MON..SUN] 143 * Returns the week day [MON..SUN]
152 */ 144 */
153 int get weekday(); 145 int get weekday();
154 146
155 /** 147 /**
156 * Returns milliseconds from 1970-01-01T00:00:00Z (UTC). 148 * Returns milliseconds from 1970-01-01T00:00:00Z (UTC).
157 * 149 *
158 * Note that this value is independent of [timeZone]. 150 * Note that this value is independent of any time-zone.
159 */ 151 */
160 final int value; 152 final int value;
161 153
162 /** 154 /**
163 * Returns the timeZone of this instance. 155 * Returns a human readable string for this instance. The returned string
164 */ 156 * is constructed in the local time-zone and does not have any time-zone
165 final TimeZone timeZone; 157 * indication. Example: [:2012-05-14 14:20:25.442:]
166
167 /**
168 * Returns true if this [Date] is set to local time.
169 */
170 bool isLocalTime();
171
172 /**
173 * Returns true if this [Date] is set to UTC time.
174 * This is equivalent to [:this.timeZone.isUtc():].
175 */
176 bool isUtc();
177
178 /**
179 * Returns a human readable string for this instance.
180 * The returned string is constructed for the [timeZone] of this instance.
181 */ 158 */
182 String toString(); 159 String toString();
183 160
184 /** 161 /**
162 * Returns a human readable string for this instance in UTC time-zone.
163 * Example: [:2012-05-14 12:21:04.989Z:]
164 */
165 String toUtcString();
166
167 /**
185 * Returns a new [Date] with the [duration] added to this instance. 168 * Returns a new [Date] with the [duration] added to this instance.
186 */ 169 */
187 Date add(Duration duration); 170 Date add(Duration duration);
188 171
189 /** 172 /**
190 * Returns a new [Date] with the [duration] subtracted from this instance. 173 * Returns a new [Date] with the [duration] subtracted from this instance.
191 */ 174 */
192 Date subtract(Duration duration); 175 Date subtract(Duration duration);
193 176
194 /** 177 /**
195 * Returns a [Duration] with the difference of [:this:] and [other]. 178 * Returns a [Duration] with the difference of [:this:] and [other].
196 */ 179 */
197 Duration difference(Date other); 180 Duration difference(Date other);
198 } 181 }
OLDNEW
« no previous file with comments | « no previous file | corelib/src/time_zone.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698