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

Side by Side 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: 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 unified diff | Download patch
« sdk/lib/core/date_time.dart ('K') | « sdk/lib/core/date_time.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 import "package:expect/expect.dart";
6
7 testReplace(DateTime original,
8 int year, int month, int day, int hour,
9 int minute, int second, int millisecond,
10 bool isUtc) {
11 var result = original.replace(year: year, month: month, day: day,
12 hour: hour, minute: minute, second: second,
13 millisecond: millisecond, isUtc: isUtc);
14 var expected = isUtc
15 ? new DateTime.utc(
16 year ?? original.year,
17 month ?? original.month,
18 day ?? original.day,
19 hour ?? original.hour,
20 minute ?? original.minute,
21 second ?? original.second,
22 millisecond ?? original.millisecond)
23 : new DateTime(
24 year ?? original.year,
25 month ?? original.month,
26 day ?? original.day,
27 hour ?? original.hour,
28 minute ?? original.minute,
29 second ?? original.second,
30 millisecond ?? original.millisecond);
31
32 Expect.equals(expected, result);
33 }
34
35 main() {
36 var epoch = DateTime.parse("1970-01-01");
37 var dst = DateTime.parse("2015-07-07T12:12:24Z");
38 var leap = DateTime.parse("2012-02-28T12:12:24");
39
40 for (var year in [null, -100, 1917, 2012]) {
41 for (var month in [null, -1, 1, 12, 14]) {
42 for (var day in [null, -1, 1, 28, 29, 30, 31, 32]) {
43 for (var hour in [null, -1, 0, 23, 25]) {
44 for (var minute in [null, -1, 1, 59, 61]) {
45 for (var second in [null, -1, 1, 59, 61]) {
46 for (var millisecond in [null, -1, 1, 999, 1001]) {
47 for (var isUtc in [false, true]) {
48 for (var base in [epoch, dst, leap]) {
49 testReplace(base, year, month, day,
50 hour, minute, second, millisecond, isUtc);
51 }
52 }
53 }
54 }
55 }
56 }
57 }
58 }
59 }
60 }
OLDNEW
« sdk/lib/core/date_time.dart ('K') | « sdk/lib/core/date_time.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698