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

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: Added to changelog Created 5 years 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 | « CHANGELOG.md ('k') | 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 28ece3fc8289e80cf2a9bd00f23375ff3ba7d5fb..e44e419ec522e2e394059f197928c1ab3f9c65a3 100644
--- a/sdk/lib/core/date_time.dart
+++ b/sdk/lib/core/date_time.dart
@@ -371,6 +371,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`
+ * 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,
+ 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 | « CHANGELOG.md ('k') | tests/corelib/date_time_replace_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698