From 1d3fbbed7c06ab984a76f289012a8b7f6e61d84a Mon Sep 17 00:00:00 2001 From: David Morgan Date: Mon, 22 Jun 2020 10:29:15 +0000 Subject: [PATCH] Revert "Fix duration.toString() to conform the description" This reverts commit 038e981f89d6e26d44db155202517df7901ce153. Reason for revert: Breaks some tests; visible changes to some web UIs. Original change's description: > Fix duration.toString() to conform the description > > Duration.toString() should return in a format of "HH:MM:SS.mmmmmm". > But when `hours` is less than 10, toString() doesn't have the leading > zero, which is "H:MM:SS.mmmmmm". > > The corresponding co19 issue: https://github.com/dart-lang/co19/issues/733 > > Bug: https://github.com/dart-lang/sdk/issues/41737 > Change-Id: I2264171b2b37e89056695f7f821125a5f78d87fb > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151163 > Commit-Queue: Zichang Guo > Reviewed-by: Lasse R.H. Nielsen TBR=lrn@google.com,zichangguo@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: https://github.com/dart-lang/sdk/issues/41737 Change-Id: I4d7ef5de9807e8e2b2a77c2171d1693b7527f671 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151848 Reviewed-by: David Morgan Commit-Queue: David Morgan --- CHANGELOG.md | 6 ----- .../tool/dartdevc_nnbd_sdk_error_golden.txt | 8 +++--- runtime/vm/isolate_reload_test.cc | 4 +-- sdk/lib/core/duration.dart | 3 +-- tests/corelib/duration_test.dart | 26 +++++++++---------- tests/corelib_2/duration_test.dart | 26 +++++++++---------- 6 files changed, 33 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8a844bb63c..b58c4a0b64b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,6 @@ ### Core libraries -#### `dart:core` - -* `toString()` of Class `Duration` will strictly follow the format of - `HH:MM:SS.mmmmmm`. Previously when `hours` is less than 10, it will output - a single digit `H`. - #### `dart:io` * [#42006][]: The signature of `exit` has been changed to return the diff --git a/pkg/dev_compiler/tool/dartdevc_nnbd_sdk_error_golden.txt b/pkg/dev_compiler/tool/dartdevc_nnbd_sdk_error_golden.txt index f07fb91837b..a4e5f6e3760 100644 --- a/pkg/dev_compiler/tool/dartdevc_nnbd_sdk_error_golden.txt +++ b/pkg/dev_compiler/tool/dartdevc_nnbd_sdk_error_golden.txt @@ -1,8 +1,8 @@ -ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|3724|5|94|Const constructors can't throw exceptions. -ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|7914|5|97|Const constructors can't throw exceptions. +ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|3723|5|94|Const constructors can't throw exceptions. +ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|7913|5|97|Const constructors can't throw exceptions. ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|940|5|95|Const constructors can't throw exceptions. ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|973|5|94|Const constructors can't throw exceptions. -ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|3722|3|5|Only redirecting factory constructors can be declared to be 'const'. -ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|7912|3|5|Only redirecting factory constructors can be declared to be 'const'. +ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|3721|3|5|Only redirecting factory constructors can be declared to be 'const'. +ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|7911|3|5|Only redirecting factory constructors can be declared to be 'const'. ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|938|3|5|Only redirecting factory constructors can be declared to be 'const'. ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|971|3|5|Only redirecting factory constructors can be declared to be 'const'. diff --git a/runtime/vm/isolate_reload_test.cc b/runtime/vm/isolate_reload_test.cc index 25702c1a826..f22bcc102db 100644 --- a/runtime/vm/isolate_reload_test.cc +++ b/runtime/vm/isolate_reload_test.cc @@ -3429,7 +3429,7 @@ TEST_CASE(IsolateReload_ConstFieldUpdate) { Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); EXPECT_VALID(lib); - EXPECT_STREQ("value=00:00:01.000000", SimpleInvokeStr(lib, "main")); + EXPECT_STREQ("value=0:00:01.000000", SimpleInvokeStr(lib, "main")); const char* kReloadScript = "const value = const Duration(seconds: 2);\n" @@ -3439,7 +3439,7 @@ TEST_CASE(IsolateReload_ConstFieldUpdate) { lib = TestCase::ReloadTestScript(kReloadScript); EXPECT_VALID(lib); - EXPECT_STREQ("value=00:00:02.000000", SimpleInvokeStr(lib, "main")); + EXPECT_STREQ("value=0:00:02.000000", SimpleInvokeStr(lib, "main")); } TEST_CASE(IsolateReload_RunNewFieldInitializers) { diff --git a/sdk/lib/core/duration.dart b/sdk/lib/core/duration.dart index 935b74413e3..2a1f406c35d 100644 --- a/sdk/lib/core/duration.dart +++ b/sdk/lib/core/duration.dart @@ -264,8 +264,7 @@ class Duration implements Comparable { twoDigits(inSeconds.remainder(secondsPerMinute) as int); String sixDigitUs = sixDigits(inMicroseconds.remainder(microsecondsPerSecond) as int); - String twoDigitHours = twoDigits(inHours); - return "$twoDigitHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs"; + return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs"; } /** diff --git a/tests/corelib/duration_test.dart b/tests/corelib/duration_test.dart index 1d1803a405b..842f4b05d70 100644 --- a/tests/corelib/duration_test.dart +++ b/tests/corelib/duration_test.dart @@ -243,43 +243,43 @@ main() { // Regression test for http://dartbug.com/15678 d = const Duration(microseconds: 1); - Expect.equals("00:00:00.000001", d.toString()); + Expect.equals("0:00:00.000001", d.toString()); d = const Duration(microseconds: 9); - Expect.equals("00:00:00.000009", d.toString()); + Expect.equals("0:00:00.000009", d.toString()); d = const Duration(microseconds: 10); - Expect.equals("00:00:00.000010", d.toString()); + Expect.equals("0:00:00.000010", d.toString()); d = const Duration(microseconds: 99); - Expect.equals("00:00:00.000099", d.toString()); + Expect.equals("0:00:00.000099", d.toString()); d = const Duration(microseconds: 100); - Expect.equals("00:00:00.000100", d.toString()); + Expect.equals("0:00:00.000100", d.toString()); d = const Duration(microseconds: 999); - Expect.equals("00:00:00.000999", d.toString()); + Expect.equals("0:00:00.000999", d.toString()); d = const Duration(microseconds: 1000); - Expect.equals("00:00:00.001000", d.toString()); + Expect.equals("0:00:00.001000", d.toString()); d = const Duration(microseconds: 9999); - Expect.equals("00:00:00.009999", d.toString()); + Expect.equals("0:00:00.009999", d.toString()); d = const Duration(microseconds: 10000); - Expect.equals("00:00:00.010000", d.toString()); + Expect.equals("0:00:00.010000", d.toString()); d = const Duration(microseconds: 99999); - Expect.equals("00:00:00.099999", d.toString()); + Expect.equals("0:00:00.099999", d.toString()); d = const Duration(microseconds: 100000); - Expect.equals("00:00:00.100000", d.toString()); + Expect.equals("0:00:00.100000", d.toString()); d = const Duration(microseconds: 999999); - Expect.equals("00:00:00.999999", d.toString()); + Expect.equals("0:00:00.999999", d.toString()); d = const Duration(microseconds: 1000000); - Expect.equals("00:00:01.000000", d.toString()); + Expect.equals("0:00:01.000000", d.toString()); d1 = const Duration(hours: 1); d2 = const Duration(hours: -1); diff --git a/tests/corelib_2/duration_test.dart b/tests/corelib_2/duration_test.dart index 1d1803a405b..842f4b05d70 100644 --- a/tests/corelib_2/duration_test.dart +++ b/tests/corelib_2/duration_test.dart @@ -243,43 +243,43 @@ main() { // Regression test for http://dartbug.com/15678 d = const Duration(microseconds: 1); - Expect.equals("00:00:00.000001", d.toString()); + Expect.equals("0:00:00.000001", d.toString()); d = const Duration(microseconds: 9); - Expect.equals("00:00:00.000009", d.toString()); + Expect.equals("0:00:00.000009", d.toString()); d = const Duration(microseconds: 10); - Expect.equals("00:00:00.000010", d.toString()); + Expect.equals("0:00:00.000010", d.toString()); d = const Duration(microseconds: 99); - Expect.equals("00:00:00.000099", d.toString()); + Expect.equals("0:00:00.000099", d.toString()); d = const Duration(microseconds: 100); - Expect.equals("00:00:00.000100", d.toString()); + Expect.equals("0:00:00.000100", d.toString()); d = const Duration(microseconds: 999); - Expect.equals("00:00:00.000999", d.toString()); + Expect.equals("0:00:00.000999", d.toString()); d = const Duration(microseconds: 1000); - Expect.equals("00:00:00.001000", d.toString()); + Expect.equals("0:00:00.001000", d.toString()); d = const Duration(microseconds: 9999); - Expect.equals("00:00:00.009999", d.toString()); + Expect.equals("0:00:00.009999", d.toString()); d = const Duration(microseconds: 10000); - Expect.equals("00:00:00.010000", d.toString()); + Expect.equals("0:00:00.010000", d.toString()); d = const Duration(microseconds: 99999); - Expect.equals("00:00:00.099999", d.toString()); + Expect.equals("0:00:00.099999", d.toString()); d = const Duration(microseconds: 100000); - Expect.equals("00:00:00.100000", d.toString()); + Expect.equals("0:00:00.100000", d.toString()); d = const Duration(microseconds: 999999); - Expect.equals("00:00:00.999999", d.toString()); + Expect.equals("0:00:00.999999", d.toString()); d = const Duration(microseconds: 1000000); - Expect.equals("00:00:01.000000", d.toString()); + Expect.equals("0:00:01.000000", d.toString()); d1 = const Duration(hours: 1); d2 = const Duration(hours: -1);