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

Side by Side Diff: sdk/lib/core/date_time.dart

Issue 12221094: Deprecate comparison operators of DateTime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 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 | tests/co19/co19-dart2dart.status » ('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 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * Deprecated class. Please use [DateTime] instead. 8 * Deprecated class. Please use [DateTime] instead.
9 */ 9 */
10 @deprecated 10 @deprecated
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 {bool isUtc: false}) 265 {bool isUtc: false})
266 : this.millisecondsSinceEpoch = millisecondsSinceEpoch, 266 : this.millisecondsSinceEpoch = millisecondsSinceEpoch,
267 this.isUtc = isUtc { 267 this.isUtc = isUtc {
268 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) { 268 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) {
269 throw new ArgumentError(millisecondsSinceEpoch); 269 throw new ArgumentError(millisecondsSinceEpoch);
270 } 270 }
271 if (isUtc == null) throw new ArgumentError(isUtc); 271 if (isUtc == null) throw new ArgumentError(isUtc);
272 } 272 }
273 273
274 /** 274 /**
275 * Returns true if [this] occurs at the same time as [other]. The 275 * Returns true if [other] is a [DateTime] at the same moment and in the
276 * comparison is independent of whether the time is utc or in the local 276 * same timezone (UTC or local).
277 * time zone. 277 *
278 * See [isAtSameMomentAs] for a comparison that ignores the timezone.
278 */ 279 */
279 bool operator ==(other) { 280 bool operator ==(other) {
280 if (!(other is DateTime)) return false; 281 if (!(other is DateTime)) return false;
281 return (millisecondsSinceEpoch == other.millisecondsSinceEpoch); 282 return (millisecondsSinceEpoch == other.millisecondsSinceEpoch &&
283 isUtc == other.isUtc);
282 } 284 }
283 285
284 /** 286 /**
285 * Returns true if [this] occurs before [other]. The comparison is independent 287 * Returns true if [this] occurs before [other]. The comparison is independent
286 * of whether the time is utc or in the local time zone. 288 * of whether the time is in UTC or in the local time zone.
289 *
290 * *Deprecated* Use [isBefore] instead.
287 */ 291 */
292 @deprecated
288 bool operator <(DateTime other) 293 bool operator <(DateTime other)
289 => millisecondsSinceEpoch < other.millisecondsSinceEpoch; 294 => millisecondsSinceEpoch < other.millisecondsSinceEpoch;
290 295
291 /** 296 /**
292 * Returns true if [this] occurs at the same time or before [other]. The 297 * Returns true if [this] occurs at the same time or before [other]. The
293 * comparison is independent of whether the time is utc or in the local 298 * comparison is independent of whether the time is in UTC or in the local
294 * time zone. 299 * time zone.
300 *
301 * *Deprecated* Use [isAfter] instead ([:!isAfter:]).
295 */ 302 */
303 @deprecated
296 bool operator <=(DateTime other) 304 bool operator <=(DateTime other)
297 => millisecondsSinceEpoch <= other.millisecondsSinceEpoch; 305 => millisecondsSinceEpoch <= other.millisecondsSinceEpoch;
298 306
299 /** 307 /**
300 * Returns true if [this] occurs after [other]. The comparison is independent 308 * Returns true if [this] occurs after [other]. The comparison is independent
301 * of whether the time is utc or in the local time zone. 309 * of whether the time is in UTC or in the local time zone.
310 *
311 * *Deprecated* Use [isAfter] instead.
302 */ 312 */
313 @deprecated
303 bool operator >(DateTime other) 314 bool operator >(DateTime other)
304 => millisecondsSinceEpoch > other.millisecondsSinceEpoch; 315 => millisecondsSinceEpoch > other.millisecondsSinceEpoch;
305 316
306 /** 317 /**
307 * Returns true if [this] occurs at the same time or after [other]. The 318 * Returns true if [this] occurs at the same time or after [other]. The
308 * comparison is independent of whether the time is utc or in the local 319 * comparison is independent of whether the time is in UTC or in the local
320 * time zone.
321 *
322 * *Deprecated* Use [isBefore] instead ([:!isBefore:]).
323 */
324 @deprecated
325 bool operator >=(DateTime other)
326 => millisecondsSinceEpoch >= other.millisecondsSinceEpoch;
327
328 /**
329 * Returns true if [this] occurs before [other]. The comparison is independent
330 * of whether the time is in UTC or in the local time zone.
331 */
332 bool isBefore(DateTime other) {
333 return millisecondsSinceEpoch < other.millisecondsSinceEpoch;
334 }
335
336 /**
337 * Returns true if [this] occurs after [other]. The comparison is independent
338 * of whether the time is in UTC or in the local time zone.
339 */
340 bool isAfter(DateTime other) {
341 return millisecondsSinceEpoch > other.millisecondsSinceEpoch;
342 }
343
344 /**
345 * Returns true if [this] occurs at the same moment as [other]. The
346 * comparison is independent of whether the time is in UTC or in the local
309 * time zone. 347 * time zone.
310 */ 348 */
311 bool operator >=(DateTime other) 349 bool isAtSameMomentAs(DateTime other) {
312 => millisecondsSinceEpoch >= other.millisecondsSinceEpoch; 350 return millisecondsSinceEpoch == other.millisecondsSinceEpoch;
351 }
313 352
314 int compareTo(DateTime other) 353 int compareTo(DateTime other)
315 => millisecondsSinceEpoch.compareTo(other.millisecondsSinceEpoch); 354 => millisecondsSinceEpoch.compareTo(other.millisecondsSinceEpoch);
316 355
317 int get hashCode => millisecondsSinceEpoch; 356 int get hashCode => millisecondsSinceEpoch;
318 357
319 /** 358 /**
320 * Returns [this] in the local time zone. Returns itself if it is already in 359 * Returns [this] in the local time zone. Returns itself if it is already in
321 * the local time zone. Otherwise, this method is equivalent to 360 * the local time zone. Otherwise, this method is equivalent to
322 * 361 *
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 * Returns the millisecond into the second [0...999]. 507 * Returns the millisecond into the second [0...999].
469 */ 508 */
470 external int get millisecond; 509 external int get millisecond;
471 510
472 /** 511 /**
473 * Returns the week day [MON..SUN]. In accordance with ISO 8601 512 * Returns the week day [MON..SUN]. In accordance with ISO 8601
474 * a week starts with Monday which has the value 1. 513 * a week starts with Monday which has the value 1.
475 */ 514 */
476 external int get weekday; 515 external int get weekday;
477 } 516 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698