OLD | NEW |
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 * An instant in time, such as July 20, 1969, 8:18pm GMT. | 8 * An instant in time, such as July 20, 1969, 8:18pm GMT. |
9 * | 9 * |
10 * Create a DateTime object by using one of the constructors | 10 * Create a DateTime object by using one of the constructors |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 DateTime._withValue(this._value, {this.isUtc}) { | 364 DateTime._withValue(this._value, {this.isUtc}) { |
365 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH || | 365 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH || |
366 (millisecondsSinceEpoch.abs() == _MAX_MILLISECONDS_SINCE_EPOCH && | 366 (millisecondsSinceEpoch.abs() == _MAX_MILLISECONDS_SINCE_EPOCH && |
367 microsecond != 0)) { | 367 microsecond != 0)) { |
368 throw new ArgumentError(millisecondsSinceEpoch); | 368 throw new ArgumentError(millisecondsSinceEpoch); |
369 } | 369 } |
370 if (isUtc == null) throw new ArgumentError(isUtc); | 370 if (isUtc == null) throw new ArgumentError(isUtc); |
371 } | 371 } |
372 | 372 |
373 /** | 373 /** |
| 374 * Replaces specific parts of a date or time while keeping the rest. |
| 375 * |
| 376 * Equivalent to createing a new `DateTime` using `new DateTime` |
| 377 * with the values specified as arguments to this method, and taking |
| 378 * the values of the this `DateTime` object for arguments that were omitted. |
| 379 * |
| 380 * # Example |
| 381 * |
| 382 * var dt = new DateTime(1969, 7, 20, 20, 18); |
| 383 * var ut = dt.replace(day: 21, hour: 17, minute: 54); |
| 384 * Expect.equals("1969-07-21T17:54:00.000", "$ut"); |
| 385 * |
| 386 */ |
| 387 DateTime replace({int year, |
| 388 int month, |
| 389 int day, |
| 390 int hour, |
| 391 int minute, |
| 392 int second, |
| 393 int millisecond, |
| 394 bool isUtc}) { |
| 395 return new DateTime._internal(year ?? this.year, |
| 396 month ?? this.month, |
| 397 day ?? this.day, |
| 398 hour ?? this.hour, |
| 399 minute ?? this.minute, |
| 400 second ?? this.second, |
| 401 millisecond ?? this.millisecond, |
| 402 isUtc ?? this.isUtc); |
| 403 } |
| 404 |
| 405 /** |
374 * Returns true if [other] is a [DateTime] at the same moment and in the | 406 * Returns true if [other] is a [DateTime] at the same moment and in the |
375 * same time zone (UTC or local). | 407 * same time zone (UTC or local). |
376 * | 408 * |
377 * DateTime dDayUtc = new DateTime.utc(1944, DateTime.JUNE, 6); | 409 * DateTime dDayUtc = new DateTime.utc(1944, DateTime.JUNE, 6); |
378 * DateTime dDayLocal = new DateTime(1944, DateTime.JUNE, 6); | 410 * DateTime dDayLocal = new DateTime(1944, DateTime.JUNE, 6); |
379 * | 411 * |
380 * assert(dDayUtc.isAtSameMomentAs(dDayLocal) == false); | 412 * assert(dDayUtc.isAtSameMomentAs(dDayLocal) == false); |
381 * | 413 * |
382 * See [isAtSameMomentAs] for a comparison that adjusts for time zone. | 414 * See [isAtSameMomentAs] for a comparison that adjusts for time zone. |
383 */ | 415 */ |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 * In accordance with ISO 8601 | 784 * In accordance with ISO 8601 |
753 * a week starts with Monday, which has the value 1. | 785 * a week starts with Monday, which has the value 1. |
754 * | 786 * |
755 * DateTime moonLanding = DateTime.parse("1969-07-20 20:18:00"); | 787 * DateTime moonLanding = DateTime.parse("1969-07-20 20:18:00"); |
756 * assert(moonLanding.weekday == 7); | 788 * assert(moonLanding.weekday == 7); |
757 * assert(moonLanding.weekday == DateTime.SUNDAY); | 789 * assert(moonLanding.weekday == DateTime.SUNDAY); |
758 * | 790 * |
759 */ | 791 */ |
760 external int get weekday; | 792 external int get weekday; |
761 } | 793 } |
OLD | NEW |