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

Unified Diff: tests/corelib/date_time_replace_test.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 | « sdk/lib/core/date_time.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/date_time_replace_test.dart
diff --git a/tests/corelib/date_time_replace_test.dart b/tests/corelib/date_time_replace_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4d1a775d6a351ff99efbe92790e7c9f773cac057
--- /dev/null
+++ b/tests/corelib/date_time_replace_test.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "package:expect/expect.dart";
+
+testReplace(DateTime original,
+ int year, int month, int day, int hour,
+ int minute, int second, int millisecond,
+ bool isUtc) {
+ var result = original.replace(year: year, month: month, day: day,
+ hour: hour, minute: minute, second: second,
+ millisecond: millisecond, isUtc: isUtc);
+ var expected = isUtc
+ ? new DateTime.utc(
+ year ?? original.year,
+ month ?? original.month,
+ day ?? original.day,
+ hour ?? original.hour,
+ minute ?? original.minute,
+ second ?? original.second,
+ millisecond ?? original.millisecond)
+ : new DateTime(
+ year ?? original.year,
+ month ?? original.month,
+ day ?? original.day,
+ hour ?? original.hour,
+ minute ?? original.minute,
+ second ?? original.second,
+ millisecond ?? original.millisecond);
+
+ Expect.equals(expected, result);
+}
+
+main() {
+ var epoch = DateTime.parse("1970-01-01");
+ var dst = DateTime.parse("2015-07-07T12:12:24Z");
+ var leap = DateTime.parse("2012-02-28T12:12:24");
+
+ for (var year in [null, -100, 1917, 2012]) {
+ for (var month in [null, -1, 1, 12, 14]) {
+ for (var day in [null, -1, 1, 28, 29, 30, 31, 32]) {
+ for (var hour in [null, -1, 0, 23, 25]) {
+ for (var minute in [null, -1, 1, 59, 61]) {
+ for (var second in [null, -1, 1, 59, 61]) {
+ for (var millisecond in [null, -1, 1, 999, 1001]) {
+ for (var isUtc in [false, true]) {
+ for (var base in [epoch, dst, leap]) {
+ testReplace(base, year, month, day,
+ hour, minute, second, millisecond, isUtc);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
« no previous file with comments | « sdk/lib/core/date_time.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698