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

Unified Diff: sdk/lib/core/date_time.dart

Issue 1472803003: Add DateTime.replace. Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/corelib/date_time_replace_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/date_time.dart
diff --git a/sdk/lib/core/date_time.dart b/sdk/lib/core/date_time.dart
index 1e89080a5f688cb8219f982dbad99b719e5febd6..f01a4f2062a5294d52a600a46467396ec608e7a4 100644
--- a/sdk/lib/core/date_time.dart
+++ b/sdk/lib/core/date_time.dart
@@ -367,6 +367,38 @@ class DateTime implements Comparable {
}
/**
+ * Replaces specific parts of a date or time while keeping the rest.
+ *
+ * Equivalent to createing a new `DateTime` using `new DateTime`
sra1 2015/11/23 21:15:14 creating
+ * with the values specified as arguments to this method, and taking
+ * the values of the this `DateTime` object for arguments that were omitted.
+ *
+ * # Example
+ *
+ * var dt = new DateTime(1969, 7, 20, 20, 18);
+ * var ut = dt.replace(day: 21, hour: 17, minute: 54);
+ * Expect.equals("1969-07-21T17:54:00.000", "$ut");
+ *
+ */
+ DateTime replace({int year,
floitsch 2015/11/23 19:11:01 I think we discussed this already on another class
sra1 2015/11/23 21:15:14 I would like to see `with` too. We should have us
+ int month,
+ int day,
+ int hour,
+ int minute,
+ int second,
+ int millisecond,
+ bool isUtc}) {
+ return new DateTime._internal(year ?? this.year,
+ month ?? this.month,
+ day ?? this.day,
+ hour ?? this.hour,
+ minute ?? this.minute,
+ second ?? this.second,
+ millisecond ?? this.millisecond,
+ isUtc ?? this.isUtc);
+ }
+
+ /**
* Returns true if [other] is a [DateTime] at the same moment and in the
* same time zone (UTC or local).
*
« no previous file with comments | « no previous file | tests/corelib/date_time_replace_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698