From 3c2d3614cfb51a9f97c025c7e02664692ac2f54b Mon Sep 17 00:00:00 2001 From: Justin Fagnani Date: Wed, 14 Aug 2013 12:13:02 -0700 Subject: [PATCH 01/89] Initial commit --- pkgs/clock/LICENSE | 0 pkgs/clock/README.md | 3 +++ 2 files changed, 3 insertions(+) create mode 100644 pkgs/clock/LICENSE create mode 100644 pkgs/clock/README.md diff --git a/pkgs/clock/LICENSE b/pkgs/clock/LICENSE new file mode 100644 index 000000000..e69de29bb diff --git a/pkgs/clock/README.md b/pkgs/clock/README.md new file mode 100644 index 000000000..4125d69a3 --- /dev/null +++ b/pkgs/clock/README.md @@ -0,0 +1,3 @@ +This is a dummy commit generated when extracting `clock` from Quiver. + +See https://github.com/google/quiver-dart for the original history of this code. From 4160b465f1198e5a45a880d5fb9eb0355837fb59 Mon Sep 17 00:00:00 2001 From: Justin Fagnani Date: Wed, 14 Aug 2013 20:57:47 -0700 Subject: [PATCH 02/89] Initial commit of project and iterables.dart --- pkgs/clock/LICENSE | 202 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/pkgs/clock/LICENSE b/pkgs/clock/LICENSE index e69de29bb..7a4a3ea24 100644 --- a/pkgs/clock/LICENSE +++ b/pkgs/clock/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file From 969d99b21fe262eba4b835a40a6ca1120eb14018 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Tue, 20 Aug 2013 15:41:13 -0700 Subject: [PATCH 03/89] Test-friendy time providers and utilities --- pkgs/clock/lib/clock.dart | 151 +++++++++++++++++++++++++++ pkgs/clock/test/clock_test.dart | 175 ++++++++++++++++++++++++++++++++ 2 files changed, 326 insertions(+) create mode 100644 pkgs/clock/lib/clock.dart create mode 100644 pkgs/clock/test/clock_test.dart diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart new file mode 100644 index 000000000..4285587b3 --- /dev/null +++ b/pkgs/clock/lib/clock.dart @@ -0,0 +1,151 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +part of quiver.time; + +/// Provides current time +abstract class TimeProvider { + DateTime call(); +} + +class _SystemTimeProvider implements TimeProvider { + const _SystemTimeProvider(); + DateTime call() => new DateTime.now(); +} + +/// Same as [TimeProvider] but in the form of a function. +typedef DateTime TimeFunction(); + +/// Time provider that gets time from a function. +class FunctionTimeProvider implements TimeProvider { + final TimeFunction _timeFunction; + FunctionTimeProvider(DateTime this._timeFunction()); + DateTime call() => _timeFunction(); +} + +/// Always returns time provided by user. Useful in unit-tests. +class FixedTimeProvider implements TimeProvider { + DateTime time; + FixedTimeProvider(this.time); + DateTime call() => time; +} + +/// Uses system clock to obtain current time +const TimeProvider SYSTEM_TIME = const _SystemTimeProvider(); + +/// Provides points in time relative to the current point in time. The current +/// point in time is defined by a [TimeProvider] (see constructors for how to +/// supply time providers). +class Clock { + + final TimeProvider _time; + + /// Creates [Clock] based on the system clock. + Clock() : _time = SYSTEM_TIME; + + /// Creates [Clock] based on user-defined [TypeProvider]. + Clock.custom(this._time); + + /// Creates [Clock] that uses the time provided by the user as the current + /// time. + Clock.fixed(DateTime time) : _time = new FixedTimeProvider(time); + + /// Create [Clock] that gets time from a function. + Clock.fromFunc(TimeFunction func) : _time = new FunctionTimeProvider(func); + + /// Returns current time. + DateTime now() => _time(); + + /// Returns the point in time [Duration] amount of time ago. + DateTime ago(Duration duration) => now().subtract(duration); + + /// Returns the point in time [Duration] amount of time from now. + DateTime fromNow(Duration duration) => now().add(duration); + + /// Return the point in time [micros] microseconds ago. + DateTime microsAgo(int micros) => ago(new Duration(microseconds: micros)); + + /// Return the point in time [micros] microseconds from now. + DateTime microsFromNow(int micros) => microsAgo(-micros); + + /// Return the point in time [millis] milliseconds ago. + DateTime millisAgo(int millis) => ago(new Duration(milliseconds: millis)); + + /// Return the point in time [millis] milliseconds from now. + DateTime millisFromNow(int millis) => millisAgo(-millis); + + /// Return the point in time [seconds] ago. + DateTime secondsAgo(int seconds) => ago(new Duration(seconds: seconds)); + + /// Return the point in time [seconds] from now. + DateTime secondsFromNow(int seconds) => secondsAgo(-seconds); + + /// Return the point in time [minutes] ago. + DateTime minutesAgo(int minutes) => ago(new Duration(minutes: minutes)); + + /// Return the point in time [minutes] from now. + DateTime minutesFromNow(int minutes) => minutesAgo(-minutes); + + /// Return the point in time [hours] ago. + DateTime hoursAgo(int hours) => ago(new Duration(hours: hours)); + + /// Return the point in time [hours] from now. + DateTime hoursFromNow(int hours) => hoursAgo(-hours); + + /// Return the point in time [days] ago. + DateTime daysAgo(int days) => ago(new Duration(days: days)); + + /// Return the point in time [days] from now. + DateTime daysFromNow(int days) => daysAgo(-days); + + /// Return the point in time [weeks] ago. + DateTime weeksAgo(int weeks) => ago(new Duration(days: 7 * weeks)); + + /// Return the point in time [weeks] from now. + DateTime weeksFromNow(int weeks) => weeksAgo(-weeks); + + /// Return the point in time [months] ago on the same date. + DateTime monthsAgo(int months) { + var time = now(); + return new DateTime( + time.year, + time.month - months, + time.day, + time.hour, + time.minute, + time.second, + time.millisecond + ); + } + + /// Return the point in time [months] from now on the same date. + DateTime monthsFromNow(int months) => monthsAgo(-months); + + /// Return the point in time [years] ago on the same date. + DateTime yearsAgo(int years) { + var time = now(); + return new DateTime( + time.year - years, + time.month, + time.day, + time.hour, + time.minute, + time.second, + time.millisecond + ); + } + + /// Return the point in time [years] from now on the same date. + DateTime yearsFromNow(int years) => yearsAgo(-years); +} diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart new file mode 100644 index 000000000..614a9e902 --- /dev/null +++ b/pkgs/clock/test/clock_test.dart @@ -0,0 +1,175 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +library quiver.iterables.merge_test; + +import 'package:unittest/unittest.dart'; +import 'package:quiver/time.dart'; + +main() { + group('clock', () { + var subject = new Clock.fixed(new DateTime(2013)); + + test("should return time based on system time and not fail", () { + expect(new Clock(), isNotNull); + }); + + test("should return time provided by custom TimeProvider", () { + var fixedTimeProvider = new FixedTimeProvider(new DateTime(2013)); + var fixedClock = new Clock.custom(fixedTimeProvider); + expect(fixedClock.now(), new DateTime(2013)); + + fixedTimeProvider.time = new DateTime(2014); + expect(fixedClock.now(), new DateTime(2014)); + }); + + test("should return fixed time", () { + expect(new Clock.fixed(new DateTime(2013)).now(), new DateTime(2013)); + }); + + test("should return time provided by custom TimeFunction", () { + expect(new Clock.fromFunc(() => new DateTime(2013)).now(), + new DateTime(2013)); + }); + + test("should return time Duration ago", () { + expect(subject.ago(new Duration(days: 366)), new DateTime(2012)); + }); + + test("should return time Duration from now", () { + expect(subject.fromNow(new Duration(days: 365)), new DateTime(2014)); + }); + + test("should return time micros ago", () { + expect(subject.microsAgo(1000), + new DateTime(2012, 12, 31, 23, 59, 59, 999)); + }); + + test("should return time micros from now", () { + expect(subject.microsFromNow(1000), + new DateTime(2013, 1, 1, 0, 0, 0, 1)); + }); + + test("should return time millis ago", () { + expect(subject.millisAgo(1000), + new DateTime(2012, 12, 31, 23, 59, 59, 000)); + }); + + test("should return time millis from now", () { + expect(subject.millisFromNow(3), + new DateTime(2013, 1, 1, 0, 0, 0, 3)); + }); + + test("should return time seconds ago", () { + expect(subject.secondsAgo(10), + new DateTime(2012, 12, 31, 23, 59, 50, 000)); + }); + + test("should return time seconds from now", () { + expect(subject.secondsFromNow(3), + new DateTime(2013, 1, 1, 0, 0, 3, 0)); + }); + + test("should return time minutes ago", () { + expect(subject.minutesAgo(10), + new DateTime(2012, 12, 31, 23, 50, 0, 000)); + }); + + test("should return time minutes from now", () { + expect(subject.minutesFromNow(3), + new DateTime(2013, 1, 1, 0, 3, 0, 0)); + }); + + test("should return time hours ago", () { + expect(subject.hoursAgo(10), + new DateTime(2012, 12, 31, 14, 0, 0, 000)); + }); + + test("should return time hours from now", () { + expect(subject.hoursFromNow(3), + new DateTime(2013, 1, 1, 3, 0, 0, 0)); + }); + + test("should return time days ago", () { + expect(subject.daysAgo(10), + new DateTime(2012, 12, 22, 0, 0, 0, 000)); + }); + + test("should return time days from now", () { + expect(subject.daysFromNow(3), + new DateTime(2013, 1, 4, 0, 0, 0, 0)); + }); + + test("should return time months ago on the same date", () { + expect(subject.monthsAgo(1), + new DateTime(2012, 12, 1, 0, 0, 0, 000)); + expect(subject.monthsAgo(2), + new DateTime(2012, 11, 1, 0, 0, 0, 000)); + expect(subject.monthsAgo(3), + new DateTime(2012, 10, 1, 0, 0, 0, 000)); + expect(subject.monthsAgo(4), + new DateTime(2012, 9, 1, 0, 0, 0, 000)); + }); + + test("should return time months from now on the same date", () { + expect(subject.monthsFromNow(1), + new DateTime(2013, 2, 1, 0, 0, 0, 0)); + expect(subject.monthsFromNow(2), + new DateTime(2013, 3, 1, 0, 0, 0, 0)); + expect(subject.monthsFromNow(3), + new DateTime(2013, 4, 1, 0, 0, 0, 0)); + expect(subject.monthsFromNow(4), + new DateTime(2013, 5, 1, 0, 0, 0, 0)); + }); + + test("should return time years ago on the same date", () { + expect(subject.yearsAgo(1), + new DateTime(2012, 1, 1, 0, 0, 0, 000)); // leap year + expect(subject.yearsAgo(2), + new DateTime(2011, 1, 1, 0, 0, 0, 000)); + expect(subject.yearsAgo(3), + new DateTime(2010, 1, 1, 0, 0, 0, 000)); + expect(subject.yearsAgo(4), + new DateTime(2009, 1, 1, 0, 0, 0, 000)); + expect(subject.yearsAgo(5), + new DateTime(2008, 1, 1, 0, 0, 0, 000)); // leap year + expect(subject.yearsAgo(6), + new DateTime(2007, 1, 1, 0, 0, 0, 000)); + expect(subject.yearsAgo(30), + new DateTime(1983, 1, 1, 0, 0, 0, 000)); + expect(subject.yearsAgo(2013), + new DateTime(0, 1, 1, 0, 0, 0, 000)); + }); + + test("should return time years from now on the same date", () { + expect(subject.yearsFromNow(1), + new DateTime(2014, 1, 1, 0, 0, 0, 0)); + expect(subject.yearsFromNow(2), + new DateTime(2015, 1, 1, 0, 0, 0, 0)); + expect(subject.yearsFromNow(3), + new DateTime(2016, 1, 1, 0, 0, 0, 0)); + expect(subject.yearsFromNow(4), + new DateTime(2017, 1, 1, 0, 0, 0, 0)); + expect(subject.yearsFromNow(5), + new DateTime(2018, 1, 1, 0, 0, 0, 0)); + expect(subject.yearsFromNow(6), + new DateTime(2019, 1, 1, 0, 0, 0, 0)); + expect(subject.yearsFromNow(30), + new DateTime(2043, 1, 1, 0, 0, 0, 0)); + expect(subject.yearsFromNow(1000), + new DateTime(3013, 1, 1, 0, 0, 0, 0)); + }); + + }); +} From ce0efb7a965853693884d2287ecf5d2afc3404e1 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Tue, 20 Aug 2013 15:46:09 -0700 Subject: [PATCH 04/89] Make time tests consistent with other tests --- pkgs/clock/test/clock_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 614a9e902..b3dbfacc5 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -library quiver.iterables.merge_test; +library quiver.time.clock_test; import 'package:unittest/unittest.dart'; import 'package:quiver/time.dart'; From 12bc5c2fee95c9977af6359cc9bfa060cdc5da8d Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 21 Aug 2013 09:16:59 -0700 Subject: [PATCH 05/89] Remove TimeProvider --- pkgs/clock/lib/clock.dart | 56 ++++++++++----------------------- pkgs/clock/test/clock_test.dart | 13 +++----- 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 4285587b3..8578a729c 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -14,55 +14,31 @@ part of quiver.time; -/// Provides current time -abstract class TimeProvider { - DateTime call(); -} - -class _SystemTimeProvider implements TimeProvider { - const _SystemTimeProvider(); - DateTime call() => new DateTime.now(); -} - -/// Same as [TimeProvider] but in the form of a function. +/// Returns current time. typedef DateTime TimeFunction(); -/// Time provider that gets time from a function. -class FunctionTimeProvider implements TimeProvider { - final TimeFunction _timeFunction; - FunctionTimeProvider(DateTime this._timeFunction()); - DateTime call() => _timeFunction(); -} - -/// Always returns time provided by user. Useful in unit-tests. -class FixedTimeProvider implements TimeProvider { - DateTime time; - FixedTimeProvider(this.time); - DateTime call() => time; -} - -/// Uses system clock to obtain current time -const TimeProvider SYSTEM_TIME = const _SystemTimeProvider(); - -/// Provides points in time relative to the current point in time. The current -/// point in time is defined by a [TimeProvider] (see constructors for how to -/// supply time providers). +/// Provides points in time relative to the current point in time, for example: +/// now, 2 days ago, 4 weeks from now, etc. +/// +/// This class is designed with testability in mind. The current point in time +/// (or [now()]) is defined by a [TimeFunction]. By supplying your own time +/// function or by using fixed clock (see constructors), you can control +/// exactly what time a [Clock] returns and base your test expectations on +/// that. See specific constructors for how to supply time functions. class Clock { - final TimeProvider _time; + final TimeFunction _time; /// Creates [Clock] based on the system clock. - Clock() : _time = SYSTEM_TIME; + Clock() : _time = (() => new DateTime.now()); - /// Creates [Clock] based on user-defined [TypeProvider]. + /// Creates [Clock] based on user-defined [TimeFunction]. For example, in + /// unit-tests you might want to control what time it is now and set date and + /// time expectations. Clock.custom(this._time); - /// Creates [Clock] that uses the time provided by the user as the current - /// time. - Clock.fixed(DateTime time) : _time = new FixedTimeProvider(time); - - /// Create [Clock] that gets time from a function. - Clock.fromFunc(TimeFunction func) : _time = new FunctionTimeProvider(func); + /// Creates [Clock] that returns fixed [time] value. Useful in unit-tests. + Clock.fixed(DateTime time) : _time = (() => time); /// Returns current time. DateTime now() => _time(); diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index b3dbfacc5..c4ac0edff 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -25,12 +25,12 @@ main() { expect(new Clock(), isNotNull); }); - test("should return time provided by custom TimeProvider", () { - var fixedTimeProvider = new FixedTimeProvider(new DateTime(2013)); - var fixedClock = new Clock.custom(fixedTimeProvider); + test("should return time provided by custom TimeFunction", () { + var time = new DateTime(2013); + var fixedClock = new Clock.custom(() => time); expect(fixedClock.now(), new DateTime(2013)); - fixedTimeProvider.time = new DateTime(2014); + time = new DateTime(2014); expect(fixedClock.now(), new DateTime(2014)); }); @@ -38,11 +38,6 @@ main() { expect(new Clock.fixed(new DateTime(2013)).now(), new DateTime(2013)); }); - test("should return time provided by custom TimeFunction", () { - expect(new Clock.fromFunc(() => new DateTime(2013)).now(), - new DateTime(2013)); - }); - test("should return time Duration ago", () { expect(subject.ago(new Duration(days: 366)), new DateTime(2012)); }); From 4eb2acd1feafdbc5862428a0ba5710c55a926d97 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 21 Aug 2013 09:47:29 -0700 Subject: [PATCH 06/89] Part-based ago/fromNow methods; Duration-based agoBy/fromNowBy methods --- pkgs/clock/lib/clock.dart | 64 ++++++++++++++++++++++++--------- pkgs/clock/test/clock_test.dart | 24 +++++++++++-- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 8578a729c..a9fbd2a84 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -44,52 +44,84 @@ class Clock { DateTime now() => _time(); /// Returns the point in time [Duration] amount of time ago. - DateTime ago(Duration duration) => now().subtract(duration); + DateTime agoBy(Duration duration) => now().subtract(duration); /// Returns the point in time [Duration] amount of time from now. - DateTime fromNow(Duration duration) => now().add(duration); + DateTime fromNowBy(Duration duration) => now().add(duration); + + /// Returns the point in time that's given amount of time ago. The + /// amount of time is the sum of individual parts. Parts are compatible with + /// ones defined in [Duration]. + DateTime ago({int days: 0, + int hours: 0, + int minutes: 0, + int seconds: 0, + int milliseconds: 0, + int microseconds: 0}) => + agoBy(new Duration(days: days, + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds)); + + /// Returns the point in time that's given amount of time from now. The + /// amount of time is the sum of individual parts. Parts are compatible with + /// ones defined in [Duration]. + DateTime fromNow({int days: 0, + int hours: 0, + int minutes: 0, + int seconds: 0, + int milliseconds: 0, + int microseconds: 0}) => + fromNowBy(new Duration(days: days, + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds)); /// Return the point in time [micros] microseconds ago. - DateTime microsAgo(int micros) => ago(new Duration(microseconds: micros)); + DateTime microsAgo(int micros) => ago(microseconds: micros); /// Return the point in time [micros] microseconds from now. - DateTime microsFromNow(int micros) => microsAgo(-micros); + DateTime microsFromNow(int micros) => fromNow(microseconds: micros); /// Return the point in time [millis] milliseconds ago. - DateTime millisAgo(int millis) => ago(new Duration(milliseconds: millis)); + DateTime millisAgo(int millis) => ago(milliseconds: millis); /// Return the point in time [millis] milliseconds from now. - DateTime millisFromNow(int millis) => millisAgo(-millis); + DateTime millisFromNow(int millis) => fromNow(milliseconds: millis); /// Return the point in time [seconds] ago. - DateTime secondsAgo(int seconds) => ago(new Duration(seconds: seconds)); + DateTime secondsAgo(int seconds) => ago(seconds: seconds); /// Return the point in time [seconds] from now. - DateTime secondsFromNow(int seconds) => secondsAgo(-seconds); + DateTime secondsFromNow(int seconds) => fromNow(seconds: seconds); /// Return the point in time [minutes] ago. - DateTime minutesAgo(int minutes) => ago(new Duration(minutes: minutes)); + DateTime minutesAgo(int minutes) => ago(minutes: minutes); /// Return the point in time [minutes] from now. - DateTime minutesFromNow(int minutes) => minutesAgo(-minutes); + DateTime minutesFromNow(int minutes) => fromNow(minutes: minutes); /// Return the point in time [hours] ago. - DateTime hoursAgo(int hours) => ago(new Duration(hours: hours)); + DateTime hoursAgo(int hours) => ago(hours: hours); /// Return the point in time [hours] from now. - DateTime hoursFromNow(int hours) => hoursAgo(-hours); + DateTime hoursFromNow(int hours) => fromNow(hours: hours); /// Return the point in time [days] ago. - DateTime daysAgo(int days) => ago(new Duration(days: days)); + DateTime daysAgo(int days) => ago(days: days); /// Return the point in time [days] from now. - DateTime daysFromNow(int days) => daysAgo(-days); + DateTime daysFromNow(int days) => fromNow(days: days); /// Return the point in time [weeks] ago. - DateTime weeksAgo(int weeks) => ago(new Duration(days: 7 * weeks)); + DateTime weeksAgo(int weeks) => ago(days: 7 * weeks); /// Return the point in time [weeks] from now. - DateTime weeksFromNow(int weeks) => weeksAgo(-weeks); + DateTime weeksFromNow(int weeks) => fromNow(days: 7 * weeks); /// Return the point in time [months] ago on the same date. DateTime monthsAgo(int months) { diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index c4ac0edff..cfdf5d86d 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -39,11 +39,31 @@ main() { }); test("should return time Duration ago", () { - expect(subject.ago(new Duration(days: 366)), new DateTime(2012)); + expect(subject.agoBy(new Duration(days: 366)), new DateTime(2012)); }); test("should return time Duration from now", () { - expect(subject.fromNow(new Duration(days: 365)), new DateTime(2014)); + expect(subject.fromNowBy(new Duration(days: 365)), new DateTime(2014)); + }); + + test("should return time parts ago", () { + expect(subject.ago( + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1000), new DateTime(2012, 12, 30, 22, 58, 58, 998)); + }); + + test("should return time parts from now", () { + expect(subject.fromNow( + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1000), new DateTime(2013, 1, 2, 1, 1, 1, 2)); }); test("should return time micros ago", () { From 3ff3884b7db1a32b6d18a08f649ef3a9ec8e1e4e Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 21 Aug 2013 10:46:14 -0700 Subject: [PATCH 07/89] Better unit-tests for system clock --- pkgs/clock/test/clock_test.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index cfdf5d86d..0c7651f70 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -21,8 +21,17 @@ main() { group('clock', () { var subject = new Clock.fixed(new DateTime(2013)); - test("should return time based on system time and not fail", () { - expect(new Clock(), isNotNull); + test("should return a non-null value from system clock", () { + expect(new Clock().now(), isNotNull); + }); + + // This test may be flaky on certain systems. I ran it over 10 million + // cycles on my machine without any failures, but that's no guarantee. + test("should be close enough to system clock", () { + var testValue = new Clock().now(); + var now = new DateTime.now(); + // I picked 2ms because 1ms was starting to get flaky. + expect(now.difference(testValue).inMilliseconds.abs(), lessThan(2)); }); test("should return time provided by custom TimeFunction", () { From 449a9f036d30e6b80251277dabeb34c4d8a45926 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 21 Aug 2013 11:17:23 -0700 Subject: [PATCH 08/89] Merge custom constructor into default using optional params --- pkgs/clock/lib/clock.dart | 20 +++++++++++++------- pkgs/clock/test/clock_test.dart | 13 +++++++++---- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index a9fbd2a84..66f6b39f9 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -17,6 +17,11 @@ part of quiver.time; /// Returns current time. typedef DateTime TimeFunction(); +DateTime _systemTime() => new DateTime.now(); + +/// A predefined instance of [Clock] that's based on system clock. +const SYSTEM_CLOCK = const Clock(); + /// Provides points in time relative to the current point in time, for example: /// now, 2 days ago, 4 weeks from now, etc. /// @@ -29,13 +34,14 @@ class Clock { final TimeFunction _time; - /// Creates [Clock] based on the system clock. - Clock() : _time = (() => new DateTime.now()); - - /// Creates [Clock] based on user-defined [TimeFunction]. For example, in - /// unit-tests you might want to control what time it is now and set date and - /// time expectations. - Clock.custom(this._time); + /// Creates a clock based on the given [timeFunc]. + /// + /// If [timeFunc] is not provided, creates [Clock] based on system clock. + /// + /// Custom [timeFunc] can be useful in unit-tests. For example, you might + /// want to control what time it is now and set date and time expectations in + /// your test cases. + const Clock([TimeFunction timeFunc = _systemTime]) : _time = timeFunc; /// Creates [Clock] that returns fixed [time] value. Useful in unit-tests. Clock.fixed(DateTime time) : _time = (() => time); diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 0c7651f70..a9e3bc60a 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -23,20 +23,25 @@ main() { test("should return a non-null value from system clock", () { expect(new Clock().now(), isNotNull); + expect(SYSTEM_CLOCK.now(), isNotNull); }); // This test may be flaky on certain systems. I ran it over 10 million // cycles on my machine without any failures, but that's no guarantee. test("should be close enough to system clock", () { - var testValue = new Clock().now(); - var now = new DateTime.now(); // I picked 2ms because 1ms was starting to get flaky. - expect(now.difference(testValue).inMilliseconds.abs(), lessThan(2)); + var epsilon = 2; + expect(new DateTime.now().difference( + new Clock().now()).inMilliseconds.abs(), + lessThan(epsilon)); + expect(new DateTime.now().difference( + SYSTEM_CLOCK.now()).inMilliseconds.abs(), + lessThan(epsilon)); }); test("should return time provided by custom TimeFunction", () { var time = new DateTime(2013); - var fixedClock = new Clock.custom(() => time); + var fixedClock = new Clock(() => time); expect(fixedClock.now(), new DateTime(2013)); time = new DateTime(2014); From 4e5357fd69bde93942eb37b1dd38576ed1847d18 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 21 Aug 2013 11:36:52 -0700 Subject: [PATCH 09/89] Make _systemTime() a public systemTime() function --- pkgs/clock/lib/clock.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 66f6b39f9..933dee893 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -17,7 +17,8 @@ part of quiver.time; /// Returns current time. typedef DateTime TimeFunction(); -DateTime _systemTime() => new DateTime.now(); +/// Return current system time. +DateTime systemTime() => new DateTime.now(); /// A predefined instance of [Clock] that's based on system clock. const SYSTEM_CLOCK = const Clock(); @@ -41,7 +42,7 @@ class Clock { /// Custom [timeFunc] can be useful in unit-tests. For example, you might /// want to control what time it is now and set date and time expectations in /// your test cases. - const Clock([TimeFunction timeFunc = _systemTime]) : _time = timeFunc; + const Clock([TimeFunction timeFunc = systemTime]) : _time = timeFunc; /// Creates [Clock] that returns fixed [time] value. Useful in unit-tests. Clock.fixed(DateTime time) : _time = (() => time); From 724ab1c16e260b391ffc2cc12443f0a8d108f2c9 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 4 Sep 2013 09:10:53 -0700 Subject: [PATCH 10/89] Clamp dates when going from long months to short months --- pkgs/clock/lib/clock.dart | 37 +++++++++++++++++++++++++++++---- pkgs/clock/test/clock_test.dart | 36 +++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 933dee893..e2b4ea6ae 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -23,6 +23,18 @@ DateTime systemTime() => new DateTime.now(); /// A predefined instance of [Clock] that's based on system clock. const SYSTEM_CLOCK = const Clock(); +/// Days in a month. This array uses 1-based month numbers, i.e. January is +/// the 1-st element in the array, not the 0-th. +const _DAYS_IN_MONTH = + const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + +int _daysInMonth(int year, int month) => + (month == DateTime.FEBRUARY && _isLeapYear(year)) + ? 29 : _DAYS_IN_MONTH[month]; + +bool _isLeapYear(int year) => + (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); + /// Provides points in time relative to the current point in time, for example: /// now, 2 days ago, 4 weeks from now, etc. /// @@ -133,10 +145,13 @@ class Clock { /// Return the point in time [months] ago on the same date. DateTime monthsAgo(int months) { var time = now(); + var m = (time.month - months - 1) % 12 + 1; + var y = time.year - (months + 12 - time.month) ~/ 12; + var d = time.day.clamp(1, _daysInMonth(y, m)); return new DateTime( - time.year, - time.month - months, - time.day, + y, + m, + d, time.hour, time.minute, time.second, @@ -145,7 +160,21 @@ class Clock { } /// Return the point in time [months] from now on the same date. - DateTime monthsFromNow(int months) => monthsAgo(-months); + DateTime monthsFromNow(int months) { + var time = now(); + var m = (time.month + months - 1) % 12 + 1; + var y = time.year + (months + time.month - 1) ~/ 12; + var d = time.day.clamp(1, _daysInMonth(y, m)); + return new DateTime( + y, + m, + d, + time.hour, + time.minute, + time.second, + time.millisecond + ); + } /// Return the point in time [years] ago on the same date. DateTime yearsAgo(int years) { diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index a9e3bc60a..bacb8e30c 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -17,9 +17,19 @@ library quiver.time.clock_test; import 'package:unittest/unittest.dart'; import 'package:quiver/time.dart'; +Clock from(int y, int m, int d) => new Clock.fixed(new DateTime(y, m, d)); + +expectDate(DateTime date, int y, int m, int d) { + expect(date, new DateTime(y, m, d)); +} + main() { group('clock', () { - var subject = new Clock.fixed(new DateTime(2013)); + Clock subject; + + setUp(() { + subject = new Clock.fixed(new DateTime(2013)); + }); test("should return a non-null value from system clock", () { expect(new Clock().now(), isNotNull); @@ -162,6 +172,30 @@ main() { new DateTime(2013, 5, 1, 0, 0, 0, 0)); }); + test("should go from 2013-05-31 to 2012-11-30", () { + expectDate(from(2013, 5, 31).monthsAgo(6), 2012, 11, 30); + }); + + test("should go from 2013-03-31 to 2013-02-28 (common year)", () { + expectDate(from(2013, 3, 31).monthsAgo(1), 2013, 2, 28); + }); + + test("should go from 2013-05-31 to 2013-02-28 (common year)", () { + expectDate(from(2013, 5, 31).monthsAgo(3), 2013, 2, 28); + }); + + test("should go from 2004-03-31 to 2004-02-29 (leap year)", () { + expectDate(from(2004, 3, 31).monthsAgo(1), 2004, 2, 29); + }); + + test("should go from 2013-03-31 to 2013-06-30", () { + expectDate(from(2013, 3, 31).monthsFromNow(3), 2013, 6, 30); + }); + + test("should go from 2003-12-31 to 2004-02-29 (common to leap)", () { + expectDate(from(2003, 12, 31).monthsFromNow(2), 2004, 2, 29); + }); + test("should return time years ago on the same date", () { expect(subject.yearsAgo(1), new DateTime(2012, 1, 1, 0, 0, 0, 000)); // leap year From e62e45bd048eafe926d166be240ba0c198f71093 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 4 Sep 2013 09:15:56 -0700 Subject: [PATCH 11/89] Remove hours, minutes, seconds and millis in tests that don't need them --- pkgs/clock/test/clock_test.dart | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index bacb8e30c..495f74d6d 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -142,34 +142,34 @@ main() { test("should return time days ago", () { expect(subject.daysAgo(10), - new DateTime(2012, 12, 22, 0, 0, 0, 000)); + new DateTime(2012, 12, 22)); }); test("should return time days from now", () { expect(subject.daysFromNow(3), - new DateTime(2013, 1, 4, 0, 0, 0, 0)); + new DateTime(2013, 1, 4)); }); test("should return time months ago on the same date", () { expect(subject.monthsAgo(1), - new DateTime(2012, 12, 1, 0, 0, 0, 000)); + new DateTime(2012, 12, 1)); expect(subject.monthsAgo(2), - new DateTime(2012, 11, 1, 0, 0, 0, 000)); + new DateTime(2012, 11, 1)); expect(subject.monthsAgo(3), - new DateTime(2012, 10, 1, 0, 0, 0, 000)); + new DateTime(2012, 10, 1)); expect(subject.monthsAgo(4), - new DateTime(2012, 9, 1, 0, 0, 0, 000)); + new DateTime(2012, 9, 1)); }); test("should return time months from now on the same date", () { expect(subject.monthsFromNow(1), - new DateTime(2013, 2, 1, 0, 0, 0, 0)); + new DateTime(2013, 2, 1)); expect(subject.monthsFromNow(2), - new DateTime(2013, 3, 1, 0, 0, 0, 0)); + new DateTime(2013, 3, 1)); expect(subject.monthsFromNow(3), - new DateTime(2013, 4, 1, 0, 0, 0, 0)); + new DateTime(2013, 4, 1)); expect(subject.monthsFromNow(4), - new DateTime(2013, 5, 1, 0, 0, 0, 0)); + new DateTime(2013, 5, 1)); }); test("should go from 2013-05-31 to 2012-11-30", () { @@ -198,40 +198,40 @@ main() { test("should return time years ago on the same date", () { expect(subject.yearsAgo(1), - new DateTime(2012, 1, 1, 0, 0, 0, 000)); // leap year + new DateTime(2012, 1, 1)); // leap year expect(subject.yearsAgo(2), - new DateTime(2011, 1, 1, 0, 0, 0, 000)); + new DateTime(2011, 1, 1)); expect(subject.yearsAgo(3), - new DateTime(2010, 1, 1, 0, 0, 0, 000)); + new DateTime(2010, 1, 1)); expect(subject.yearsAgo(4), - new DateTime(2009, 1, 1, 0, 0, 0, 000)); + new DateTime(2009, 1, 1)); expect(subject.yearsAgo(5), - new DateTime(2008, 1, 1, 0, 0, 0, 000)); // leap year + new DateTime(2008, 1, 1)); // leap year expect(subject.yearsAgo(6), - new DateTime(2007, 1, 1, 0, 0, 0, 000)); + new DateTime(2007, 1, 1)); expect(subject.yearsAgo(30), - new DateTime(1983, 1, 1, 0, 0, 0, 000)); + new DateTime(1983, 1, 1)); expect(subject.yearsAgo(2013), - new DateTime(0, 1, 1, 0, 0, 0, 000)); + new DateTime(0, 1, 1)); }); test("should return time years from now on the same date", () { expect(subject.yearsFromNow(1), - new DateTime(2014, 1, 1, 0, 0, 0, 0)); + new DateTime(2014, 1, 1)); expect(subject.yearsFromNow(2), - new DateTime(2015, 1, 1, 0, 0, 0, 0)); + new DateTime(2015, 1, 1)); expect(subject.yearsFromNow(3), - new DateTime(2016, 1, 1, 0, 0, 0, 0)); + new DateTime(2016, 1, 1)); expect(subject.yearsFromNow(4), - new DateTime(2017, 1, 1, 0, 0, 0, 0)); + new DateTime(2017, 1, 1)); expect(subject.yearsFromNow(5), - new DateTime(2018, 1, 1, 0, 0, 0, 0)); + new DateTime(2018, 1, 1)); expect(subject.yearsFromNow(6), - new DateTime(2019, 1, 1, 0, 0, 0, 0)); + new DateTime(2019, 1, 1)); expect(subject.yearsFromNow(30), - new DateTime(2043, 1, 1, 0, 0, 0, 0)); + new DateTime(2043, 1, 1)); expect(subject.yearsFromNow(1000), - new DateTime(3013, 1, 1, 0, 0, 0, 0)); + new DateTime(3013, 1, 1)); }); }); From d6b99a81092962d0967f2b66899bc15ff0b43816 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 4 Sep 2013 09:17:36 -0700 Subject: [PATCH 12/89] Increase epsilon to 10ms; at 2ms the test is flaky --- pkgs/clock/test/clock_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 495f74d6d..78f7ba154 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -39,8 +39,8 @@ main() { // This test may be flaky on certain systems. I ran it over 10 million // cycles on my machine without any failures, but that's no guarantee. test("should be close enough to system clock", () { - // I picked 2ms because 1ms was starting to get flaky. - var epsilon = 2; + // At 10ms the test doesn't seem to be flaky. + var epsilon = 10; expect(new DateTime.now().difference( new Clock().now()).inMilliseconds.abs(), lessThan(epsilon)); From 848770ea2536530e2046b9e03510d90afd1c4600 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 4 Sep 2013 09:24:53 -0700 Subject: [PATCH 13/89] Convert all date tests to use expectDate --- pkgs/clock/test/clock_test.dart | 80 +++++++++++---------------------- 1 file changed, 27 insertions(+), 53 deletions(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 78f7ba154..d14b5cdc4 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -19,7 +19,7 @@ import 'package:quiver/time.dart'; Clock from(int y, int m, int d) => new Clock.fixed(new DateTime(y, m, d)); -expectDate(DateTime date, int y, int m, int d) { +expectDate(DateTime date, int y, [int m = 1, int d = 1]) { expect(date, new DateTime(y, m, d)); } @@ -141,35 +141,25 @@ main() { }); test("should return time days ago", () { - expect(subject.daysAgo(10), - new DateTime(2012, 12, 22)); + expectDate(subject.daysAgo(10), 2012, 12, 22); }); test("should return time days from now", () { - expect(subject.daysFromNow(3), - new DateTime(2013, 1, 4)); + expectDate(subject.daysFromNow(3), 2013, 1, 4); }); test("should return time months ago on the same date", () { - expect(subject.monthsAgo(1), - new DateTime(2012, 12, 1)); - expect(subject.monthsAgo(2), - new DateTime(2012, 11, 1)); - expect(subject.monthsAgo(3), - new DateTime(2012, 10, 1)); - expect(subject.monthsAgo(4), - new DateTime(2012, 9, 1)); + expectDate(subject.monthsAgo(1), 2012, 12, 1); + expectDate(subject.monthsAgo(2), 2012, 11, 1); + expectDate(subject.monthsAgo(3), 2012, 10, 1); + expectDate(subject.monthsAgo(4), 2012, 9, 1); }); test("should return time months from now on the same date", () { - expect(subject.monthsFromNow(1), - new DateTime(2013, 2, 1)); - expect(subject.monthsFromNow(2), - new DateTime(2013, 3, 1)); - expect(subject.monthsFromNow(3), - new DateTime(2013, 4, 1)); - expect(subject.monthsFromNow(4), - new DateTime(2013, 5, 1)); + expectDate(subject.monthsFromNow(1), 2013, 2, 1); + expectDate(subject.monthsFromNow(2), 2013, 3, 1); + expectDate(subject.monthsFromNow(3), 2013, 4, 1); + expectDate(subject.monthsFromNow(4), 2013, 5, 1); }); test("should go from 2013-05-31 to 2012-11-30", () { @@ -197,41 +187,25 @@ main() { }); test("should return time years ago on the same date", () { - expect(subject.yearsAgo(1), - new DateTime(2012, 1, 1)); // leap year - expect(subject.yearsAgo(2), - new DateTime(2011, 1, 1)); - expect(subject.yearsAgo(3), - new DateTime(2010, 1, 1)); - expect(subject.yearsAgo(4), - new DateTime(2009, 1, 1)); - expect(subject.yearsAgo(5), - new DateTime(2008, 1, 1)); // leap year - expect(subject.yearsAgo(6), - new DateTime(2007, 1, 1)); - expect(subject.yearsAgo(30), - new DateTime(1983, 1, 1)); - expect(subject.yearsAgo(2013), - new DateTime(0, 1, 1)); + expectDate(subject.yearsAgo(1), 2012, 1, 1); // leap year + expectDate(subject.yearsAgo(2), 2011, 1, 1); + expectDate(subject.yearsAgo(3), 2010, 1, 1); + expectDate(subject.yearsAgo(4), 2009, 1, 1); + expectDate(subject.yearsAgo(5), 2008, 1, 1); // leap year + expectDate(subject.yearsAgo(6), 2007, 1, 1); + expectDate(subject.yearsAgo(30), 1983, 1, 1); + expectDate(subject.yearsAgo(2013), 0, 1, 1); }); test("should return time years from now on the same date", () { - expect(subject.yearsFromNow(1), - new DateTime(2014, 1, 1)); - expect(subject.yearsFromNow(2), - new DateTime(2015, 1, 1)); - expect(subject.yearsFromNow(3), - new DateTime(2016, 1, 1)); - expect(subject.yearsFromNow(4), - new DateTime(2017, 1, 1)); - expect(subject.yearsFromNow(5), - new DateTime(2018, 1, 1)); - expect(subject.yearsFromNow(6), - new DateTime(2019, 1, 1)); - expect(subject.yearsFromNow(30), - new DateTime(2043, 1, 1)); - expect(subject.yearsFromNow(1000), - new DateTime(3013, 1, 1)); + expectDate(subject.yearsFromNow(1), 2014, 1, 1); + expectDate(subject.yearsFromNow(2), 2015, 1, 1); + expectDate(subject.yearsFromNow(3), 2016, 1, 1); + expectDate(subject.yearsFromNow(4), 2017, 1, 1); + expectDate(subject.yearsFromNow(5), 2018, 1, 1); + expectDate(subject.yearsFromNow(6), 2019, 1, 1); + expectDate(subject.yearsFromNow(30), 2043, 1, 1); + expectDate(subject.yearsFromNow(1000), 3013, 1, 1); }); }); From 5c9dbbb42a9db5a91ce990503a28b24bd0d74423 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 4 Sep 2013 09:32:37 -0700 Subject: [PATCH 14/89] Clamp date when jumping from leap to common year --- pkgs/clock/lib/clock.dart | 6 ++++-- pkgs/clock/test/clock_test.dart | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index e2b4ea6ae..4ddfe78b9 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -179,10 +179,12 @@ class Clock { /// Return the point in time [years] ago on the same date. DateTime yearsAgo(int years) { var time = now(); + var y = time.year - years; + var d = time.day.clamp(1, _daysInMonth(y, time.month)); return new DateTime( - time.year - years, + y, time.month, - time.day, + d, time.hour, time.minute, time.second, diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index d14b5cdc4..0fc44a1bd 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -186,6 +186,22 @@ main() { expectDate(from(2003, 12, 31).monthsFromNow(2), 2004, 2, 29); }); + test("should go from 2004-02-29 to 2003-02-28 by year", () { + expectDate(from(2004, 2, 29).yearsAgo(1), 2003, 2, 28); + }); + + test("should go from 2004-02-29 to 2003-02-28 by month", () { + expectDate(from(2004, 2, 29).monthsAgo(12), 2003, 2, 28); + }); + + test("should go from 2004-02-29 to 2005-02-28 by year", () { + expectDate(from(2004, 2, 29).yearsFromNow(1), 2005, 2, 28); + }); + + test("should go from 2004-02-29 to 2005-02-28 by month", () { + expectDate(from(2004, 2, 29).monthsFromNow(12), 2005, 2, 28); + }); + test("should return time years ago on the same date", () { expectDate(subject.yearsAgo(1), 2012, 1, 1); // leap year expectDate(subject.yearsAgo(2), 2011, 1, 1); From b24c9a2c4a71bb9d108d360633a987ad4b363eba Mon Sep 17 00:00:00 2001 From: yjbanov Date: Wed, 4 Sep 2013 09:33:33 -0700 Subject: [PATCH 15/89] Consistent quotes --- pkgs/clock/test/clock_test.dart | 72 ++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 0fc44a1bd..73cdeb4a8 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -1,13 +1,13 @@ // Copyright 2013 Google Inc. All Rights Reserved. // -// Licensed under the Apache License, Version 2.0 (the "License"); +// Licensed under the Apache License, Version 2.0 (the 'License'); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, +// distributed under the License is distributed on an 'AS IS' BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. @@ -31,14 +31,14 @@ main() { subject = new Clock.fixed(new DateTime(2013)); }); - test("should return a non-null value from system clock", () { + test('should return a non-null value from system clock', () { expect(new Clock().now(), isNotNull); expect(SYSTEM_CLOCK.now(), isNotNull); }); // This test may be flaky on certain systems. I ran it over 10 million // cycles on my machine without any failures, but that's no guarantee. - test("should be close enough to system clock", () { + test('should be close enough to system clock', () { // At 10ms the test doesn't seem to be flaky. var epsilon = 10; expect(new DateTime.now().difference( @@ -49,7 +49,7 @@ main() { lessThan(epsilon)); }); - test("should return time provided by custom TimeFunction", () { + test('should return time provided by custom TimeFunction', () { var time = new DateTime(2013); var fixedClock = new Clock(() => time); expect(fixedClock.now(), new DateTime(2013)); @@ -58,19 +58,19 @@ main() { expect(fixedClock.now(), new DateTime(2014)); }); - test("should return fixed time", () { + test('should return fixed time', () { expect(new Clock.fixed(new DateTime(2013)).now(), new DateTime(2013)); }); - test("should return time Duration ago", () { + test('should return time Duration ago', () { expect(subject.agoBy(new Duration(days: 366)), new DateTime(2012)); }); - test("should return time Duration from now", () { + test('should return time Duration from now', () { expect(subject.fromNowBy(new Duration(days: 365)), new DateTime(2014)); }); - test("should return time parts ago", () { + test('should return time parts ago', () { expect(subject.ago( days: 1, hours: 1, @@ -80,7 +80,7 @@ main() { microseconds: 1000), new DateTime(2012, 12, 30, 22, 58, 58, 998)); }); - test("should return time parts from now", () { + test('should return time parts from now', () { expect(subject.fromNow( days: 1, hours: 1, @@ -90,119 +90,119 @@ main() { microseconds: 1000), new DateTime(2013, 1, 2, 1, 1, 1, 2)); }); - test("should return time micros ago", () { + test('should return time micros ago', () { expect(subject.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999)); }); - test("should return time micros from now", () { + test('should return time micros from now', () { expect(subject.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1)); }); - test("should return time millis ago", () { + test('should return time millis ago', () { expect(subject.millisAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 000)); }); - test("should return time millis from now", () { + test('should return time millis from now', () { expect(subject.millisFromNow(3), new DateTime(2013, 1, 1, 0, 0, 0, 3)); }); - test("should return time seconds ago", () { + test('should return time seconds ago', () { expect(subject.secondsAgo(10), new DateTime(2012, 12, 31, 23, 59, 50, 000)); }); - test("should return time seconds from now", () { + test('should return time seconds from now', () { expect(subject.secondsFromNow(3), new DateTime(2013, 1, 1, 0, 0, 3, 0)); }); - test("should return time minutes ago", () { + test('should return time minutes ago', () { expect(subject.minutesAgo(10), new DateTime(2012, 12, 31, 23, 50, 0, 000)); }); - test("should return time minutes from now", () { + test('should return time minutes from now', () { expect(subject.minutesFromNow(3), new DateTime(2013, 1, 1, 0, 3, 0, 0)); }); - test("should return time hours ago", () { + test('should return time hours ago', () { expect(subject.hoursAgo(10), new DateTime(2012, 12, 31, 14, 0, 0, 000)); }); - test("should return time hours from now", () { + test('should return time hours from now', () { expect(subject.hoursFromNow(3), new DateTime(2013, 1, 1, 3, 0, 0, 0)); }); - test("should return time days ago", () { + test('should return time days ago', () { expectDate(subject.daysAgo(10), 2012, 12, 22); }); - test("should return time days from now", () { + test('should return time days from now', () { expectDate(subject.daysFromNow(3), 2013, 1, 4); }); - test("should return time months ago on the same date", () { + test('should return time months ago on the same date', () { expectDate(subject.monthsAgo(1), 2012, 12, 1); expectDate(subject.monthsAgo(2), 2012, 11, 1); expectDate(subject.monthsAgo(3), 2012, 10, 1); expectDate(subject.monthsAgo(4), 2012, 9, 1); }); - test("should return time months from now on the same date", () { + test('should return time months from now on the same date', () { expectDate(subject.monthsFromNow(1), 2013, 2, 1); expectDate(subject.monthsFromNow(2), 2013, 3, 1); expectDate(subject.monthsFromNow(3), 2013, 4, 1); expectDate(subject.monthsFromNow(4), 2013, 5, 1); }); - test("should go from 2013-05-31 to 2012-11-30", () { + test('should go from 2013-05-31 to 2012-11-30', () { expectDate(from(2013, 5, 31).monthsAgo(6), 2012, 11, 30); }); - test("should go from 2013-03-31 to 2013-02-28 (common year)", () { + test('should go from 2013-03-31 to 2013-02-28 (common year)', () { expectDate(from(2013, 3, 31).monthsAgo(1), 2013, 2, 28); }); - test("should go from 2013-05-31 to 2013-02-28 (common year)", () { + test('should go from 2013-05-31 to 2013-02-28 (common year)', () { expectDate(from(2013, 5, 31).monthsAgo(3), 2013, 2, 28); }); - test("should go from 2004-03-31 to 2004-02-29 (leap year)", () { + test('should go from 2004-03-31 to 2004-02-29 (leap year)', () { expectDate(from(2004, 3, 31).monthsAgo(1), 2004, 2, 29); }); - test("should go from 2013-03-31 to 2013-06-30", () { + test('should go from 2013-03-31 to 2013-06-30', () { expectDate(from(2013, 3, 31).monthsFromNow(3), 2013, 6, 30); }); - test("should go from 2003-12-31 to 2004-02-29 (common to leap)", () { + test('should go from 2003-12-31 to 2004-02-29 (common to leap)', () { expectDate(from(2003, 12, 31).monthsFromNow(2), 2004, 2, 29); }); - test("should go from 2004-02-29 to 2003-02-28 by year", () { + test('should go from 2004-02-29 to 2003-02-28 by year', () { expectDate(from(2004, 2, 29).yearsAgo(1), 2003, 2, 28); }); - test("should go from 2004-02-29 to 2003-02-28 by month", () { + test('should go from 2004-02-29 to 2003-02-28 by month', () { expectDate(from(2004, 2, 29).monthsAgo(12), 2003, 2, 28); }); - test("should go from 2004-02-29 to 2005-02-28 by year", () { + test('should go from 2004-02-29 to 2005-02-28 by year', () { expectDate(from(2004, 2, 29).yearsFromNow(1), 2005, 2, 28); }); - test("should go from 2004-02-29 to 2005-02-28 by month", () { + test('should go from 2004-02-29 to 2005-02-28 by month', () { expectDate(from(2004, 2, 29).monthsFromNow(12), 2005, 2, 28); }); - test("should return time years ago on the same date", () { + test('should return time years ago on the same date', () { expectDate(subject.yearsAgo(1), 2012, 1, 1); // leap year expectDate(subject.yearsAgo(2), 2011, 1, 1); expectDate(subject.yearsAgo(3), 2010, 1, 1); @@ -213,7 +213,7 @@ main() { expectDate(subject.yearsAgo(2013), 0, 1, 1); }); - test("should return time years from now on the same date", () { + test('should return time years from now on the same date', () { expectDate(subject.yearsFromNow(1), 2014, 1, 1); expectDate(subject.yearsFromNow(2), 2015, 1, 1); expectDate(subject.yearsFromNow(3), 2016, 1, 1); From 822b79153254b2c763c8789f7b438b5554bedfb5 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Thu, 5 Sep 2013 10:46:06 -0700 Subject: [PATCH 16/89] Extract date clamping into a method and document it --- pkgs/clock/lib/clock.dart | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 4ddfe78b9..f3327f78e 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -35,6 +35,23 @@ int _daysInMonth(int year, int month) => bool _isLeapYear(int year) => (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); +/// Takes a [date] that may be outside the allowed range of dates for a given +/// [month] in a given [year] and returns the closest date that is within the +/// allowed range. +/// +/// For example: +/// +/// February 31, 2013 => February 28, 2013 +/// +/// When jumping from month to month or from leap year to common year we may +/// end up in a month that has fewer days than the month we are jumping from. +/// In that case it is impossible to preserve the exact date. So we "clamp" the +/// date value to fit within the month. For example, jumping from March 31 one +/// month back takes us to February 28 (or 29 during a leap year), as February +/// doesn't have 31-st date. +int _clampDate(int date, int year, int month) => + date.clamp(1, _daysInMonth(year, month)); + /// Provides points in time relative to the current point in time, for example: /// now, 2 days ago, 4 weeks from now, etc. /// @@ -147,7 +164,7 @@ class Clock { var time = now(); var m = (time.month - months - 1) % 12 + 1; var y = time.year - (months + 12 - time.month) ~/ 12; - var d = time.day.clamp(1, _daysInMonth(y, m)); + var d = _clampDate(time.day, y, m); return new DateTime( y, m, @@ -164,7 +181,7 @@ class Clock { var time = now(); var m = (time.month + months - 1) % 12 + 1; var y = time.year + (months + time.month - 1) ~/ 12; - var d = time.day.clamp(1, _daysInMonth(y, m)); + var d = _clampDate(time.day, y, m); return new DateTime( y, m, @@ -180,7 +197,7 @@ class Clock { DateTime yearsAgo(int years) { var time = now(); var y = time.year - years; - var d = time.day.clamp(1, _daysInMonth(y, time.month)); + var d = _clampDate(time.day, y, time.month); return new DateTime( y, time.month, From 87168e2201217472396a0bd5196cb94f83816095 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 11 Jun 2014 09:47:20 -0700 Subject: [PATCH 17/89] Remove SYSTEM_CLOCK. Use const Clock() instead. --- pkgs/clock/lib/clock.dart | 3 --- pkgs/clock/test/clock_test.dart | 5 ++--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index f3327f78e..ddef5a7b1 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -20,9 +20,6 @@ typedef DateTime TimeFunction(); /// Return current system time. DateTime systemTime() => new DateTime.now(); -/// A predefined instance of [Clock] that's based on system clock. -const SYSTEM_CLOCK = const Clock(); - /// Days in a month. This array uses 1-based month numbers, i.e. January is /// the 1-st element in the array, not the 0-th. const _DAYS_IN_MONTH = diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 73cdeb4a8..09ea39918 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -32,8 +32,7 @@ main() { }); test('should return a non-null value from system clock', () { - expect(new Clock().now(), isNotNull); - expect(SYSTEM_CLOCK.now(), isNotNull); + expect(const Clock().now(), isNotNull); }); // This test may be flaky on certain systems. I ran it over 10 million @@ -45,7 +44,7 @@ main() { new Clock().now()).inMilliseconds.abs(), lessThan(epsilon)); expect(new DateTime.now().difference( - SYSTEM_CLOCK.now()).inMilliseconds.abs(), + const Clock().now()).inMilliseconds.abs(), lessThan(epsilon)); }); From d10f07579e2d54b316c72804f6c13e9b3b616f5f Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 4 Feb 2015 23:17:19 -0800 Subject: [PATCH 18/89] Reformat with dartformat --- pkgs/clock/lib/clock.dart | 77 ++++++++++----------------------- pkgs/clock/test/clock_test.dart | 50 +++++++++------------ 2 files changed, 44 insertions(+), 83 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index ddef5a7b1..dcc8a2c10 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -23,11 +23,10 @@ DateTime systemTime() => new DateTime.now(); /// Days in a month. This array uses 1-based month numbers, i.e. January is /// the 1-st element in the array, not the 0-th. const _DAYS_IN_MONTH = - const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + const [ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; -int _daysInMonth(int year, int month) => - (month == DateTime.FEBRUARY && _isLeapYear(year)) - ? 29 : _DAYS_IN_MONTH[month]; +int _daysInMonth(int year, int month) => (month == DateTime.FEBRUARY && + _isLeapYear(year)) ? 29 : _DAYS_IN_MONTH[month]; bool _isLeapYear(int year) => (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); @@ -58,7 +57,6 @@ int _clampDate(int date, int year, int month) => /// exactly what time a [Clock] returns and base your test expectations on /// that. See specific constructors for how to supply time functions. class Clock { - final TimeFunction _time; /// Creates a clock based on the given [timeFunc]. @@ -85,34 +83,26 @@ class Clock { /// Returns the point in time that's given amount of time ago. The /// amount of time is the sum of individual parts. Parts are compatible with /// ones defined in [Duration]. - DateTime ago({int days: 0, - int hours: 0, - int minutes: 0, - int seconds: 0, - int milliseconds: 0, - int microseconds: 0}) => - agoBy(new Duration(days: days, - hours: hours, - minutes: minutes, - seconds: seconds, - milliseconds: milliseconds, - microseconds: microseconds)); + DateTime ago({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, + int milliseconds: 0, int microseconds: 0}) => agoBy(new Duration( + days: days, + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds)); /// Returns the point in time that's given amount of time from now. The /// amount of time is the sum of individual parts. Parts are compatible with /// ones defined in [Duration]. - DateTime fromNow({int days: 0, - int hours: 0, - int minutes: 0, - int seconds: 0, - int milliseconds: 0, - int microseconds: 0}) => - fromNowBy(new Duration(days: days, - hours: hours, - minutes: minutes, - seconds: seconds, - milliseconds: milliseconds, - microseconds: microseconds)); + DateTime fromNow({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, + int milliseconds: 0, int microseconds: 0}) => fromNowBy(new Duration( + days: days, + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds)); /// Return the point in time [micros] microseconds ago. DateTime microsAgo(int micros) => ago(microseconds: micros); @@ -163,14 +153,7 @@ class Clock { var y = time.year - (months + 12 - time.month) ~/ 12; var d = _clampDate(time.day, y, m); return new DateTime( - y, - m, - d, - time.hour, - time.minute, - time.second, - time.millisecond - ); + y, m, d, time.hour, time.minute, time.second, time.millisecond); } /// Return the point in time [months] from now on the same date. @@ -180,14 +163,7 @@ class Clock { var y = time.year + (months + time.month - 1) ~/ 12; var d = _clampDate(time.day, y, m); return new DateTime( - y, - m, - d, - time.hour, - time.minute, - time.second, - time.millisecond - ); + y, m, d, time.hour, time.minute, time.second, time.millisecond); } /// Return the point in time [years] ago on the same date. @@ -195,15 +171,8 @@ class Clock { var time = now(); var y = time.year - years; var d = _clampDate(time.day, y, time.month); - return new DateTime( - y, - time.month, - d, - time.hour, - time.minute, - time.second, - time.millisecond - ); + return new DateTime(y, time.month, d, time.hour, time.minute, time.second, + time.millisecond); } /// Return the point in time [years] from now on the same date. diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 09ea39918..0e123574a 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -40,12 +40,11 @@ main() { test('should be close enough to system clock', () { // At 10ms the test doesn't seem to be flaky. var epsilon = 10; - expect(new DateTime.now().difference( - new Clock().now()).inMilliseconds.abs(), - lessThan(epsilon)); - expect(new DateTime.now().difference( - const Clock().now()).inMilliseconds.abs(), - lessThan(epsilon)); + expect( + new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(), + lessThan(epsilon)); + expect(new DateTime.now().difference(const Clock().now()).inMilliseconds + .abs(), lessThan(epsilon)); }); test('should return time provided by custom TimeFunction', () { @@ -90,53 +89,47 @@ main() { }); test('should return time micros ago', () { - expect(subject.microsAgo(1000), - new DateTime(2012, 12, 31, 23, 59, 59, 999)); + expect( + subject.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999)); }); test('should return time micros from now', () { - expect(subject.microsFromNow(1000), - new DateTime(2013, 1, 1, 0, 0, 0, 1)); + expect(subject.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1)); }); test('should return time millis ago', () { - expect(subject.millisAgo(1000), - new DateTime(2012, 12, 31, 23, 59, 59, 000)); + expect( + subject.millisAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 000)); }); test('should return time millis from now', () { - expect(subject.millisFromNow(3), - new DateTime(2013, 1, 1, 0, 0, 0, 3)); + expect(subject.millisFromNow(3), new DateTime(2013, 1, 1, 0, 0, 0, 3)); }); test('should return time seconds ago', () { - expect(subject.secondsAgo(10), - new DateTime(2012, 12, 31, 23, 59, 50, 000)); + expect( + subject.secondsAgo(10), new DateTime(2012, 12, 31, 23, 59, 50, 000)); }); test('should return time seconds from now', () { - expect(subject.secondsFromNow(3), - new DateTime(2013, 1, 1, 0, 0, 3, 0)); + expect(subject.secondsFromNow(3), new DateTime(2013, 1, 1, 0, 0, 3, 0)); }); test('should return time minutes ago', () { - expect(subject.minutesAgo(10), - new DateTime(2012, 12, 31, 23, 50, 0, 000)); + expect( + subject.minutesAgo(10), new DateTime(2012, 12, 31, 23, 50, 0, 000)); }); test('should return time minutes from now', () { - expect(subject.minutesFromNow(3), - new DateTime(2013, 1, 1, 0, 3, 0, 0)); + expect(subject.minutesFromNow(3), new DateTime(2013, 1, 1, 0, 3, 0, 0)); }); test('should return time hours ago', () { - expect(subject.hoursAgo(10), - new DateTime(2012, 12, 31, 14, 0, 0, 000)); + expect(subject.hoursAgo(10), new DateTime(2012, 12, 31, 14, 0, 0, 000)); }); test('should return time hours from now', () { - expect(subject.hoursFromNow(3), - new DateTime(2013, 1, 1, 3, 0, 0, 0)); + expect(subject.hoursFromNow(3), new DateTime(2013, 1, 1, 3, 0, 0, 0)); }); test('should return time days ago', () { @@ -202,11 +195,11 @@ main() { }); test('should return time years ago on the same date', () { - expectDate(subject.yearsAgo(1), 2012, 1, 1); // leap year + expectDate(subject.yearsAgo(1), 2012, 1, 1); // leap year expectDate(subject.yearsAgo(2), 2011, 1, 1); expectDate(subject.yearsAgo(3), 2010, 1, 1); expectDate(subject.yearsAgo(4), 2009, 1, 1); - expectDate(subject.yearsAgo(5), 2008, 1, 1); // leap year + expectDate(subject.yearsAgo(5), 2008, 1, 1); // leap year expectDate(subject.yearsAgo(6), 2007, 1, 1); expectDate(subject.yearsAgo(30), 1983, 1, 1); expectDate(subject.yearsAgo(2013), 0, 1, 1); @@ -222,6 +215,5 @@ main() { expectDate(subject.yearsFromNow(30), 2043, 1, 1); expectDate(subject.yearsFromNow(1000), 3013, 1, 1); }); - }); } From e85c148843418230f2d7b77bc466b5e87c81aa99 Mon Sep 17 00:00:00 2001 From: zoechi Date: Fri, 8 May 2015 19:13:04 +0200 Subject: [PATCH 19/89] Update to new test package and new matcher. --- pkgs/clock/test/clock_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 0e123574a..bf6a55cf2 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -14,7 +14,7 @@ library quiver.time.clock_test; -import 'package:unittest/unittest.dart'; +import 'package:test/test.dart'; import 'package:quiver/time.dart'; Clock from(int y, int m, int d) => new Clock.fixed(new DateTime(y, m, d)); From 9eb27d53bc82af66dae67de28eb8afed43f566ac Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Nov 2016 10:50:56 -0700 Subject: [PATCH 20/89] Use Duration const constructor where possible (dart-lang/clock#316) --- pkgs/clock/test/clock_test.dart | 44 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index bf6a55cf2..08c026ad0 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -43,8 +43,12 @@ main() { expect( new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(), lessThan(epsilon)); - expect(new DateTime.now().difference(const Clock().now()).inMilliseconds - .abs(), lessThan(epsilon)); + expect( + new DateTime.now() + .difference(const Clock().now()) + .inMilliseconds + .abs(), + lessThan(epsilon)); }); test('should return time provided by custom TimeFunction', () { @@ -61,31 +65,35 @@ main() { }); test('should return time Duration ago', () { - expect(subject.agoBy(new Duration(days: 366)), new DateTime(2012)); + expect(subject.agoBy(const Duration(days: 366)), new DateTime(2012)); }); test('should return time Duration from now', () { - expect(subject.fromNowBy(new Duration(days: 365)), new DateTime(2014)); + expect(subject.fromNowBy(const Duration(days: 365)), new DateTime(2014)); }); test('should return time parts ago', () { - expect(subject.ago( - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1000), new DateTime(2012, 12, 30, 22, 58, 58, 998)); + expect( + subject.ago( + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1000), + new DateTime(2012, 12, 30, 22, 58, 58, 998)); }); test('should return time parts from now', () { - expect(subject.fromNow( - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1000), new DateTime(2013, 1, 2, 1, 1, 1, 2)); + expect( + subject.fromNow( + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1000), + new DateTime(2013, 1, 2, 1, 1, 1, 2)); }); test('should return time micros ago', () { From 58bf42a194adc7ed10f255085c7969a7f016e4ec Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 16 Nov 2016 09:40:49 -0800 Subject: [PATCH 21/89] Apply dartfmt 0.2.11+1 (dart-lang/clock#327) --- pkgs/clock/lib/clock.dart | 45 +++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index dcc8a2c10..f9879be2e 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -22,11 +22,26 @@ DateTime systemTime() => new DateTime.now(); /// Days in a month. This array uses 1-based month numbers, i.e. January is /// the 1-st element in the array, not the 0-th. -const _DAYS_IN_MONTH = - const [ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; - -int _daysInMonth(int year, int month) => (month == DateTime.FEBRUARY && - _isLeapYear(year)) ? 29 : _DAYS_IN_MONTH[month]; +const _DAYS_IN_MONTH = const [ + 0, + 31, + 28, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31 +]; + +int _daysInMonth(int year, int month) => + (month == DateTime.FEBRUARY && _isLeapYear(year)) + ? 29 + : _DAYS_IN_MONTH[month]; bool _isLeapYear(int year) => (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); @@ -83,8 +98,14 @@ class Clock { /// Returns the point in time that's given amount of time ago. The /// amount of time is the sum of individual parts. Parts are compatible with /// ones defined in [Duration]. - DateTime ago({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, - int milliseconds: 0, int microseconds: 0}) => agoBy(new Duration( + DateTime ago( + {int days: 0, + int hours: 0, + int minutes: 0, + int seconds: 0, + int milliseconds: 0, + int microseconds: 0}) => + agoBy(new Duration( days: days, hours: hours, minutes: minutes, @@ -95,8 +116,14 @@ class Clock { /// Returns the point in time that's given amount of time from now. The /// amount of time is the sum of individual parts. Parts are compatible with /// ones defined in [Duration]. - DateTime fromNow({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, - int milliseconds: 0, int microseconds: 0}) => fromNowBy(new Duration( + DateTime fromNow( + {int days: 0, + int hours: 0, + int minutes: 0, + int seconds: 0, + int milliseconds: 0, + int microseconds: 0}) => + fromNowBy(new Duration( days: days, hours: hours, minutes: minutes, From 64838f05a53d21730acc03c9dff6b8937aa73d37 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 1 Nov 2017 13:54:54 -0700 Subject: [PATCH 22/89] Add isLeapYear, daysInMonth, clampDayOfMonth (dart-lang/clock#381) This change extracts these functions to a new file, util.dart, applies a bit of minor renaming and cleanup and makes them public. --- pkgs/clock/lib/clock.dart | 49 +++------------------------------------ 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index f9879be2e..640a20feb 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -20,49 +20,6 @@ typedef DateTime TimeFunction(); /// Return current system time. DateTime systemTime() => new DateTime.now(); -/// Days in a month. This array uses 1-based month numbers, i.e. January is -/// the 1-st element in the array, not the 0-th. -const _DAYS_IN_MONTH = const [ - 0, - 31, - 28, - 31, - 30, - 31, - 30, - 31, - 31, - 30, - 31, - 30, - 31 -]; - -int _daysInMonth(int year, int month) => - (month == DateTime.FEBRUARY && _isLeapYear(year)) - ? 29 - : _DAYS_IN_MONTH[month]; - -bool _isLeapYear(int year) => - (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); - -/// Takes a [date] that may be outside the allowed range of dates for a given -/// [month] in a given [year] and returns the closest date that is within the -/// allowed range. -/// -/// For example: -/// -/// February 31, 2013 => February 28, 2013 -/// -/// When jumping from month to month or from leap year to common year we may -/// end up in a month that has fewer days than the month we are jumping from. -/// In that case it is impossible to preserve the exact date. So we "clamp" the -/// date value to fit within the month. For example, jumping from March 31 one -/// month back takes us to February 28 (or 29 during a leap year), as February -/// doesn't have 31-st date. -int _clampDate(int date, int year, int month) => - date.clamp(1, _daysInMonth(year, month)); - /// Provides points in time relative to the current point in time, for example: /// now, 2 days ago, 4 weeks from now, etc. /// @@ -178,7 +135,7 @@ class Clock { var time = now(); var m = (time.month - months - 1) % 12 + 1; var y = time.year - (months + 12 - time.month) ~/ 12; - var d = _clampDate(time.day, y, m); + var d = clampDayOfMonth(year: y, month: m, day: time.day); return new DateTime( y, m, d, time.hour, time.minute, time.second, time.millisecond); } @@ -188,7 +145,7 @@ class Clock { var time = now(); var m = (time.month + months - 1) % 12 + 1; var y = time.year + (months + time.month - 1) ~/ 12; - var d = _clampDate(time.day, y, m); + var d = clampDayOfMonth(year: y, month: m, day: time.day); return new DateTime( y, m, d, time.hour, time.minute, time.second, time.millisecond); } @@ -197,7 +154,7 @@ class Clock { DateTime yearsAgo(int years) { var time = now(); var y = time.year - years; - var d = _clampDate(time.day, y, time.month); + var d = clampDayOfMonth(year: y, month: time.month, day: time.day); return new DateTime(y, time.month, d, time.hour, time.minute, time.second, time.millisecond); } From c7818d1b0e84cadf241f7274a4d15dd7c6cd185b Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 5 Mar 2018 17:58:16 -0800 Subject: [PATCH 23/89] Add initial files for the standalone release of clock --- pkgs/clock/.gitignore | 5 + pkgs/clock/.travis.yml | 33 +++++ pkgs/clock/AUTHORS | 6 + pkgs/clock/CHANGELOG.md | 3 + pkgs/clock/CONTRIBUTING.md | 53 ++++++++ pkgs/clock/LICENSE | 202 +++++++++++++++++++++++++++++++ pkgs/clock/README.md | 48 ++++++++ pkgs/clock/analysis_options.yaml | 2 + pkgs/clock/pubspec.yaml | 8 ++ 9 files changed, 360 insertions(+) create mode 100644 pkgs/clock/.gitignore create mode 100644 pkgs/clock/.travis.yml create mode 100644 pkgs/clock/AUTHORS create mode 100644 pkgs/clock/CHANGELOG.md create mode 100644 pkgs/clock/CONTRIBUTING.md create mode 100644 pkgs/clock/LICENSE create mode 100644 pkgs/clock/README.md create mode 100644 pkgs/clock/analysis_options.yaml create mode 100644 pkgs/clock/pubspec.yaml diff --git a/pkgs/clock/.gitignore b/pkgs/clock/.gitignore new file mode 100644 index 000000000..63fe85d83 --- /dev/null +++ b/pkgs/clock/.gitignore @@ -0,0 +1,5 @@ +.packages +.pub/ +.dart_tool/ +build/ +pubspec.lock diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml new file mode 100644 index 000000000..9124e035b --- /dev/null +++ b/pkgs/clock/.travis.yml @@ -0,0 +1,33 @@ +language: dart + +# By default, builds are run in containers. +# https://docs.travis-ci.com/user/getting-started/#Selecting-infrastructure-(optional) +# Set `sudo: true` to disable containers if you need to use sudo in your scripts. +# sudo: true + +dart: +- dev +- stable + +# See https://docs.travis-ci.com/user/languages/dart/ for details. +dart_task: +- test: --platform vm +# Uncomment this line to run tests on the browser. +# - test: --platform firefox + +# Only run one instance of the formatter and the analyzer, rather than running +# them against each Dart version. +matrix: + include: + - dart: stable + dart_task: dartfmt + - dart: dev + dart_task: dartanalyzer + +# Only building master means that we don't run two builds for each pull request. +branches: + only: [master] + +cache: + directories: + - $HOME/.pub-cache diff --git a/pkgs/clock/AUTHORS b/pkgs/clock/AUTHORS new file mode 100644 index 000000000..e8063a8cd --- /dev/null +++ b/pkgs/clock/AUTHORS @@ -0,0 +1,6 @@ +# Below is a list of people and organizations that have contributed +# to the project. Names should be added to the list like so: +# +# Name/Organization + +Google Inc. diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md new file mode 100644 index 000000000..5b26ad30f --- /dev/null +++ b/pkgs/clock/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +* Initial version. diff --git a/pkgs/clock/CONTRIBUTING.md b/pkgs/clock/CONTRIBUTING.md new file mode 100644 index 000000000..615b92ff9 --- /dev/null +++ b/pkgs/clock/CONTRIBUTING.md @@ -0,0 +1,53 @@ +Want to contribute? Great! First, read this page (including the small print at +the end). + +### Before you contribute + +Before we can use your code, you must sign the +[Google Individual Contributor License Agreement][CLA] (CLA), which you can do +online. The CLA is necessary mainly because you own the copyright to your +changes, even after your contribution becomes part of our codebase, so we need +your permission to use and distribute your code. We also need to be sure of +various other things—for instance that you'll tell us if you know that your code +infringes on other people's patents. You don't have to sign the CLA until after +you've submitted your code for review and a member has approved it, but you must +do it before we can put your code into our codebase. + +Before you start working on a larger contribution, you should get in touch with +us first through the issue tracker with your idea so that we can help out and +possibly guide you. Coordinating up front makes it much easier to avoid +frustration later on. + +[CLA]: https://cla.developers.google.com/about/google-individual + +### Code reviews + +All submissions, including submissions by project members, require review. We +recommend [forking the repository][fork], making changes in your fork, and +[sending us a pull request][pr] so we can review the changes and merge them into +this repository. + +[fork]: https://help.github.com/articles/about-forks/ +[pr]: https://help.github.com/articles/creating-a-pull-request/ + +Functional changes will require tests to be added or changed. The tests live in +the `test/` directory, and are run with `pub run test`. If you need to create +new tests, use the existing tests as a guideline for what they should look like. + +Before you send your pull request, make sure all the tests pass! + +### File headers + +All files in the project must start with the following header. + + // Copyright (c) 2017, 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. + +### The small print + +Contributions made by corporations are covered by a different agreement than the +one above, the +[Software Grant and Corporate Contributor License Agreement][CCLA]. + +[CCLA]: https://developers.google.com/open-source/cla/corporate diff --git a/pkgs/clock/LICENSE b/pkgs/clock/LICENSE new file mode 100644 index 000000000..7a4a3ea24 --- /dev/null +++ b/pkgs/clock/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/pkgs/clock/README.md b/pkgs/clock/README.md new file mode 100644 index 000000000..905f3b3b1 --- /dev/null +++ b/pkgs/clock/README.md @@ -0,0 +1,48 @@ +This package provides a [`Clock`][] class which encapsulates the notion of the +"current time" and provides easy access to points relative to the current time. +Different `Clock`s can have a different notion of the current time, and the +default top-level [`clock`][]'s notion can be swapped out to reliably test +timing-dependent code. + +[`Clock`]: https://www.dartdocs.org/documentation/clock/latest/clock/Clock-class.html +[`clock`]: https://www.dartdocs.org/documentation/clock/latest/clock/clock.html + +For example, you can use `clock` in your libraries like this: + +```dart +// run_with_timing.dart +import 'package:clock/clock.dart'; + +/// Runs [callback] and prints how long it took. +T runWithTiming(T callback()) { + var stopwatch = clock.getStopwatch()..start(); + var result = callback(); + print("It took ${stopwatch.elapsed}!"); + return result; +} +``` + +...and then test your code using the [`fake_async`][] package, which +automatically overrides the current clock: + +[`fake_async`]: https://pub.dartlang.org/packages/fake_async + +```dart +// run_with_timing_test.dart +import 'run_with_timing.dart'; + +import 'package:fake_async/fake_async.dart'; +import 'package:test/test.dart'; + +void main() { + test("runWithTiming() prints the elapsed time", () { + new FakeAsync().run((async) { + expect(() { + runWithTiming(() { + async.elapse(new Duration(seconds: 10)); + }); + }, prints("It took 0:00:10.000000!")); + }); + }); +} +``` diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml new file mode 100644 index 000000000..a10d4c5a0 --- /dev/null +++ b/pkgs/clock/analysis_options.yaml @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml new file mode 100644 index 000000000..52d25d25f --- /dev/null +++ b/pkgs/clock/pubspec.yaml @@ -0,0 +1,8 @@ +name: clock +version: 1.0.0-dev +description: A fakeable wrapper for dart:core clock APIs +author: Dart Team +homepage: https://github.com/dart-lang/clock + +environment: + sdk: '>=1.24.0 <2.0.0' From 4a6a1753c87ae71693c008690a68bf8a8c06088f Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 5 Mar 2018 21:37:52 -0800 Subject: [PATCH 24/89] Get the code running --- pkgs/clock/lib/clock.dart | 2 +- pkgs/clock/lib/src/utils.dart | 62 +++++++++++++++++++++++++++++++++ pkgs/clock/pubspec.yaml | 6 ++++ pkgs/clock/test/clock_test.dart | 3 +- 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 pkgs/clock/lib/src/utils.dart diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 640a20feb..4ee971ae5 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -part of quiver.time; +import 'src/utils.dart'; /// Returns current time. typedef DateTime TimeFunction(); diff --git a/pkgs/clock/lib/src/utils.dart b/pkgs/clock/lib/src/utils.dart new file mode 100644 index 000000000..c4f11d094 --- /dev/null +++ b/pkgs/clock/lib/src/utils.dart @@ -0,0 +1,62 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This code is copied from quiver. We don't take on an explicit dependency +// because quiver is very large and the amount of code we use from it is very +// small. + +import 'package:meta/meta.dart'; + +/// Days in a month. This array uses 1-based month numbers, i.e. January is +/// the 1-st element in the array, not the 0-th. +const _daysInMonth = const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + +/// Returns the number of days in the specified month. +/// +/// This function assumes the use of the Gregorian calendar or the proleptic +/// Gregorian calendar. +int daysInMonth(int year, int month) => + (month == DateTime.FEBRUARY && isLeapYear(year)) ? 29 : _daysInMonth[month]; + +/// Returns true if [year] is a leap year. +/// +/// This implements the Gregorian calendar leap year rules wherein a year is +/// considered to be a leap year if it is divisible by 4, excepting years +/// divisible by 100, but including years divisible by 400. +/// +/// This function assumes the use of the Gregorian calendar or the proleptic +/// Gregorian calendar. +bool isLeapYear(int year) => + (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); + +/// Takes a [date] that may be outside the allowed range of dates for a given +/// [month] in a given [year] and returns the closest date that is within the +/// allowed range. +/// +/// For example: +/// +/// February 31, 2013 => February 28, 2013 +/// +/// When jumping from month to month or from leap year to common year we may +/// end up in a month that has fewer days than the month we are jumping from. +/// In that case it is impossible to preserve the exact date. So we "clamp" the +/// date value to fit within the month. For example, jumping from March 31 one +/// month back takes us to February 28 (or 29 during a leap year), as February +/// doesn't have 31-st date. +int clampDayOfMonth({ + @required int year, + @required int month, + @required int day, +}) => + day.clamp(1, daysInMonth(year, month)); \ No newline at end of file diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 52d25d25f..5ebecf2f4 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -6,3 +6,9 @@ homepage: https://github.com/dart-lang/clock environment: sdk: '>=1.24.0 <2.0.0' + +dependencies: + meta: '>=0.9.0 <2.0.0' + +dev_dependencies: + test: '^0.12.0' diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 08c026ad0..7048c4756 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -library quiver.time.clock_test; +import 'package:clock/clock.dart'; import 'package:test/test.dart'; -import 'package:quiver/time.dart'; Clock from(int y, int m, int d) => new Clock.fixed(new DateTime(y, m, d)); From 2a1552ed31fd04244aed0d34bc7be19e1dc79d66 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 5 Mar 2018 22:07:38 -0800 Subject: [PATCH 25/89] Style changes --- pkgs/clock/lib/clock.dart | 100 ++++---- pkgs/clock/lib/src/utils.dart | 17 +- pkgs/clock/test/clock_test.dart | 400 ++++++++++++++++---------------- 3 files changed, 261 insertions(+), 256 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 4ee971ae5..7fd25205a 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -15,32 +15,30 @@ import 'src/utils.dart'; /// Returns current time. +@Deprecated("Pass around an instance of Clock instead.") typedef DateTime TimeFunction(); /// Return current system time. +@Deprecated("Use new DateTime.now() instead.") DateTime systemTime() => new DateTime.now(); -/// Provides points in time relative to the current point in time, for example: -/// now, 2 days ago, 4 weeks from now, etc. +/// A class which encapsulates the notion of the "current time" and provides +/// easy access to points relative to the current time. /// /// This class is designed with testability in mind. The current point in time -/// (or [now()]) is defined by a [TimeFunction]. By supplying your own time -/// function or by using fixed clock (see constructors), you can control -/// exactly what time a [Clock] returns and base your test expectations on -/// that. See specific constructors for how to supply time functions. +/// (or [now()]) is defined by a function that returns a [DateTime]. By +/// supplying your own time function or using [new Clock.fixed], you can control +/// exactly what time a [Clock] returns and base your test expectations on that. class Clock { - final TimeFunction _time; + /// The function that's called to determine this clock's notion of the current + /// time. + final DateTime Function() _time; - /// Creates a clock based on the given [timeFunc]. - /// - /// If [timeFunc] is not provided, creates [Clock] based on system clock. - /// - /// Custom [timeFunc] can be useful in unit-tests. For example, you might - /// want to control what time it is now and set date and time expectations in - /// your test cases. - const Clock([TimeFunction timeFunc = systemTime]) : _time = timeFunc; + /// Creates a clock based on the given [currentTime], or on the system clock + /// by default. + const Clock([DateTime currentTime()]) : _time = currentTime ?? systemTime; - /// Creates [Clock] that returns fixed [time] value. Useful in unit-tests. + /// Creates [Clock] that always considers the current time to be [time]. Clock.fixed(DateTime time) : _time = (() => time); /// Returns current time. @@ -52,9 +50,9 @@ class Clock { /// Returns the point in time [Duration] amount of time from now. DateTime fromNowBy(Duration duration) => now().add(duration); - /// Returns the point in time that's given amount of time ago. The - /// amount of time is the sum of individual parts. Parts are compatible with - /// ones defined in [Duration]. + /// Returns the point in time that's given amount of time ago. + /// + /// The amount of time is the sum of the individual parts. DateTime ago( {int days: 0, int hours: 0, @@ -70,9 +68,9 @@ class Clock { milliseconds: milliseconds, microseconds: microseconds)); - /// Returns the point in time that's given amount of time from now. The - /// amount of time is the sum of individual parts. Parts are compatible with - /// ones defined in [Duration]. + /// Returns the point in time that's given amount of time from now. + /// + /// The amount of time is the sum of the individual parts. DateTime fromNow( {int days: 0, int hours: 0, @@ -88,17 +86,19 @@ class Clock { milliseconds: milliseconds, microseconds: microseconds)); - /// Return the point in time [micros] microseconds ago. - DateTime microsAgo(int micros) => ago(microseconds: micros); + /// Return the point in time [microseconds] ago. + DateTime microsAgo(int microseconds) => ago(microseconds: microseconds); - /// Return the point in time [micros] microseconds from now. - DateTime microsFromNow(int micros) => fromNow(microseconds: micros); + /// Return the point in time [microseconds] from now. + DateTime microsFromNow(int microseconds) => + fromNow(microseconds: microseconds); - /// Return the point in time [millis] milliseconds ago. - DateTime millisAgo(int millis) => ago(milliseconds: millis); + /// Return the point in time [milliseconds] ago. + DateTime millisAgo(int milliseconds) => ago(milliseconds: milliseconds); - /// Return the point in time [millis] milliseconds from now. - DateTime millisFromNow(int millis) => fromNow(milliseconds: millis); + /// Return the point in time [milliseconds] from now. + DateTime millisFromNow(int milliseconds) => + fromNow(milliseconds: milliseconds); /// Return the point in time [seconds] ago. DateTime secondsAgo(int seconds) => ago(seconds: seconds); @@ -131,34 +131,46 @@ class Clock { DateTime weeksFromNow(int weeks) => fromNow(days: 7 * weeks); /// Return the point in time [months] ago on the same date. + /// + /// If the current day of the month isn't valid in the new month, the nearest + /// valid day in the new month will be used. DateTime monthsAgo(int months) { var time = now(); - var m = (time.month - months - 1) % 12 + 1; - var y = time.year - (months + 12 - time.month) ~/ 12; - var d = clampDayOfMonth(year: y, month: m, day: time.day); - return new DateTime( - y, m, d, time.hour, time.minute, time.second, time.millisecond); + var month = (time.month - months - 1) % 12 + 1; + var year = time.year - (months + 12 - time.month) ~/ 12; + var day = clampDayOfMonth(year: year, month: month, day: time.day); + return new DateTime(year, month, day, time.hour, time.minute, time.second, + time.millisecond); } /// Return the point in time [months] from now on the same date. + /// + /// If the current day of the month isn't valid in the new month, the nearest + /// valid day in the new month will be used. DateTime monthsFromNow(int months) { var time = now(); - var m = (time.month + months - 1) % 12 + 1; - var y = time.year + (months + time.month - 1) ~/ 12; - var d = clampDayOfMonth(year: y, month: m, day: time.day); - return new DateTime( - y, m, d, time.hour, time.minute, time.second, time.millisecond); + var month = (time.month + months - 1) % 12 + 1; + var year = time.year + (months + time.month - 1) ~/ 12; + var day = clampDayOfMonth(year: year, month: month, day: time.day); + return new DateTime(year, month, day, time.hour, time.minute, time.second, + time.millisecond); } /// Return the point in time [years] ago on the same date. + /// + /// If the current day of the month isn't valid in the new year, the nearest + /// valid day in the original month will be used. DateTime yearsAgo(int years) { var time = now(); - var y = time.year - years; - var d = clampDayOfMonth(year: y, month: time.month, day: time.day); - return new DateTime(y, time.month, d, time.hour, time.minute, time.second, - time.millisecond); + var year = time.year - years; + var day = clampDayOfMonth(year: year, month: time.month, day: time.day); + return new DateTime(year, time.month, day, time.hour, time.minute, + time.second, time.millisecond); } /// Return the point in time [years] from now on the same date. + /// + /// If the current day of the month isn't valid in the new year, the nearest + /// valid day in the original month will be used. DateTime yearsFromNow(int years) => yearsAgo(-years); } diff --git a/pkgs/clock/lib/src/utils.dart b/pkgs/clock/lib/src/utils.dart index c4f11d094..48fd0be30 100644 --- a/pkgs/clock/lib/src/utils.dart +++ b/pkgs/clock/lib/src/utils.dart @@ -18,8 +18,10 @@ import 'package:meta/meta.dart'; -/// Days in a month. This array uses 1-based month numbers, i.e. January is -/// the 1-st element in the array, not the 0-th. +/// The number of days in each month. +/// +/// This array uses 1-based month numbers, i.e. January is the 1-st element in +/// the array, not the 0-th. const _daysInMonth = const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; /// Returns the number of days in the specified month. @@ -38,7 +40,7 @@ int daysInMonth(int year, int month) => /// This function assumes the use of the Gregorian calendar or the proleptic /// Gregorian calendar. bool isLeapYear(int year) => - (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); + year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); /// Takes a [date] that may be outside the allowed range of dates for a given /// [month] in a given [year] and returns the closest date that is within the @@ -54,9 +56,6 @@ bool isLeapYear(int year) => /// date value to fit within the month. For example, jumping from March 31 one /// month back takes us to February 28 (or 29 during a leap year), as February /// doesn't have 31-st date. -int clampDayOfMonth({ - @required int year, - @required int month, - @required int day, -}) => - day.clamp(1, daysInMonth(year, month)); \ No newline at end of file +int clampDayOfMonth( + {@required int year, @required int month, @required int day}) => + day.clamp(1, daysInMonth(year, month)); diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 7048c4756..633cdb990 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -16,211 +16,205 @@ import 'package:clock/clock.dart'; import 'package:test/test.dart'; -Clock from(int y, int m, int d) => new Clock.fixed(new DateTime(y, m, d)); +/// A utility function for tersely constructing a [DateTime] with no time +/// component. +DateTime _date(int year, [int month, int day]) => + new DateTime(year, month ?? 1, day ?? 1); -expectDate(DateTime date, int y, [int m = 1, int d = 1]) { - expect(date, new DateTime(y, m, d)); -} +/// Return a clock that always returns a date with the given [year], [month], +/// and [day]. +Clock _fixed(int year, [int month, int day]) => + new Clock.fixed(_date(year, month, day)); main() { - group('clock', () { - Clock subject; - - setUp(() { - subject = new Clock.fixed(new DateTime(2013)); - }); - - test('should return a non-null value from system clock', () { - expect(const Clock().now(), isNotNull); - }); - - // This test may be flaky on certain systems. I ran it over 10 million - // cycles on my machine without any failures, but that's no guarantee. - test('should be close enough to system clock', () { - // At 10ms the test doesn't seem to be flaky. - var epsilon = 10; - expect( - new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(), - lessThan(epsilon)); - expect( - new DateTime.now() - .difference(const Clock().now()) - .inMilliseconds - .abs(), - lessThan(epsilon)); - }); - - test('should return time provided by custom TimeFunction', () { - var time = new DateTime(2013); - var fixedClock = new Clock(() => time); - expect(fixedClock.now(), new DateTime(2013)); - - time = new DateTime(2014); - expect(fixedClock.now(), new DateTime(2014)); - }); - - test('should return fixed time', () { - expect(new Clock.fixed(new DateTime(2013)).now(), new DateTime(2013)); - }); - - test('should return time Duration ago', () { - expect(subject.agoBy(const Duration(days: 366)), new DateTime(2012)); - }); - - test('should return time Duration from now', () { - expect(subject.fromNowBy(const Duration(days: 365)), new DateTime(2014)); - }); - - test('should return time parts ago', () { - expect( - subject.ago( - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1000), - new DateTime(2012, 12, 30, 22, 58, 58, 998)); - }); - - test('should return time parts from now', () { - expect( - subject.fromNow( - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1000), - new DateTime(2013, 1, 2, 1, 1, 1, 2)); - }); - - test('should return time micros ago', () { - expect( - subject.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999)); - }); - - test('should return time micros from now', () { - expect(subject.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1)); - }); - - test('should return time millis ago', () { - expect( - subject.millisAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 000)); - }); - - test('should return time millis from now', () { - expect(subject.millisFromNow(3), new DateTime(2013, 1, 1, 0, 0, 0, 3)); - }); - - test('should return time seconds ago', () { - expect( - subject.secondsAgo(10), new DateTime(2012, 12, 31, 23, 59, 50, 000)); - }); - - test('should return time seconds from now', () { - expect(subject.secondsFromNow(3), new DateTime(2013, 1, 1, 0, 0, 3, 0)); - }); - - test('should return time minutes ago', () { - expect( - subject.minutesAgo(10), new DateTime(2012, 12, 31, 23, 50, 0, 000)); - }); - - test('should return time minutes from now', () { - expect(subject.minutesFromNow(3), new DateTime(2013, 1, 1, 0, 3, 0, 0)); - }); - - test('should return time hours ago', () { - expect(subject.hoursAgo(10), new DateTime(2012, 12, 31, 14, 0, 0, 000)); - }); - - test('should return time hours from now', () { - expect(subject.hoursFromNow(3), new DateTime(2013, 1, 1, 3, 0, 0, 0)); - }); - - test('should return time days ago', () { - expectDate(subject.daysAgo(10), 2012, 12, 22); - }); - - test('should return time days from now', () { - expectDate(subject.daysFromNow(3), 2013, 1, 4); - }); - - test('should return time months ago on the same date', () { - expectDate(subject.monthsAgo(1), 2012, 12, 1); - expectDate(subject.monthsAgo(2), 2012, 11, 1); - expectDate(subject.monthsAgo(3), 2012, 10, 1); - expectDate(subject.monthsAgo(4), 2012, 9, 1); - }); - - test('should return time months from now on the same date', () { - expectDate(subject.monthsFromNow(1), 2013, 2, 1); - expectDate(subject.monthsFromNow(2), 2013, 3, 1); - expectDate(subject.monthsFromNow(3), 2013, 4, 1); - expectDate(subject.monthsFromNow(4), 2013, 5, 1); - }); - - test('should go from 2013-05-31 to 2012-11-30', () { - expectDate(from(2013, 5, 31).monthsAgo(6), 2012, 11, 30); - }); - - test('should go from 2013-03-31 to 2013-02-28 (common year)', () { - expectDate(from(2013, 3, 31).monthsAgo(1), 2013, 2, 28); - }); - - test('should go from 2013-05-31 to 2013-02-28 (common year)', () { - expectDate(from(2013, 5, 31).monthsAgo(3), 2013, 2, 28); - }); - - test('should go from 2004-03-31 to 2004-02-29 (leap year)', () { - expectDate(from(2004, 3, 31).monthsAgo(1), 2004, 2, 29); - }); - - test('should go from 2013-03-31 to 2013-06-30', () { - expectDate(from(2013, 3, 31).monthsFromNow(3), 2013, 6, 30); - }); - - test('should go from 2003-12-31 to 2004-02-29 (common to leap)', () { - expectDate(from(2003, 12, 31).monthsFromNow(2), 2004, 2, 29); - }); - - test('should go from 2004-02-29 to 2003-02-28 by year', () { - expectDate(from(2004, 2, 29).yearsAgo(1), 2003, 2, 28); - }); - - test('should go from 2004-02-29 to 2003-02-28 by month', () { - expectDate(from(2004, 2, 29).monthsAgo(12), 2003, 2, 28); - }); - - test('should go from 2004-02-29 to 2005-02-28 by year', () { - expectDate(from(2004, 2, 29).yearsFromNow(1), 2005, 2, 28); - }); - - test('should go from 2004-02-29 to 2005-02-28 by month', () { - expectDate(from(2004, 2, 29).monthsFromNow(12), 2005, 2, 28); - }); - - test('should return time years ago on the same date', () { - expectDate(subject.yearsAgo(1), 2012, 1, 1); // leap year - expectDate(subject.yearsAgo(2), 2011, 1, 1); - expectDate(subject.yearsAgo(3), 2010, 1, 1); - expectDate(subject.yearsAgo(4), 2009, 1, 1); - expectDate(subject.yearsAgo(5), 2008, 1, 1); // leap year - expectDate(subject.yearsAgo(6), 2007, 1, 1); - expectDate(subject.yearsAgo(30), 1983, 1, 1); - expectDate(subject.yearsAgo(2013), 0, 1, 1); - }); - - test('should return time years from now on the same date', () { - expectDate(subject.yearsFromNow(1), 2014, 1, 1); - expectDate(subject.yearsFromNow(2), 2015, 1, 1); - expectDate(subject.yearsFromNow(3), 2016, 1, 1); - expectDate(subject.yearsFromNow(4), 2017, 1, 1); - expectDate(subject.yearsFromNow(5), 2018, 1, 1); - expectDate(subject.yearsFromNow(6), 2019, 1, 1); - expectDate(subject.yearsFromNow(30), 2043, 1, 1); - expectDate(subject.yearsFromNow(1000), 3013, 1, 1); - }); + Clock clock; + setUp(() { + clock = new Clock.fixed(_date(2013)); + }); + + test('should return a non-null value from system clock', () { + expect(const Clock().now(), isNotNull); + }); + + // This test may be flaky on certain systems. I ran it over 10 million + // cycles on my machine without any failures, but that's no guarantee. + test('should be close enough to system clock', () { + // At 10ms the test doesn't seem to be flaky. + var epsilon = 10; + expect( + new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(), + lessThan(epsilon)); + expect( + new DateTime.now().difference(const Clock().now()).inMilliseconds.abs(), + lessThan(epsilon)); + }); + + test('should return time provided by a custom function', () { + var time = _date(2013); + var fixedClock = new Clock(() => time); + expect(fixedClock.now(), _date(2013)); + + time = _date(2014); + expect(fixedClock.now(), _date(2014)); + }); + + test('should return fixed time', () { + expect(new Clock.fixed(_date(2013)).now(), _date(2013)); + }); + + test('should return time Duration ago', () { + expect(clock.agoBy(const Duration(days: 366)), _date(2012)); + }); + + test('should return time Duration from now', () { + expect(clock.fromNowBy(const Duration(days: 365)), _date(2014)); + }); + + test('should return time parts ago', () { + expect( + clock.ago( + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1000), + new DateTime(2012, 12, 30, 22, 58, 58, 998)); + }); + + test('should return time parts from now', () { + expect( + clock.fromNow( + days: 1, + hours: 1, + minutes: 1, + seconds: 1, + milliseconds: 1, + microseconds: 1000), + new DateTime(2013, 1, 2, 1, 1, 1, 2)); + }); + + test('should return time micros ago', () { + expect(clock.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999)); + }); + + test('should return time micros from now', () { + expect(clock.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1)); + }); + + test('should return time millis ago', () { + expect(clock.millisAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 000)); + }); + + test('should return time millis from now', () { + expect(clock.millisFromNow(3), new DateTime(2013, 1, 1, 0, 0, 0, 3)); + }); + + test('should return time seconds ago', () { + expect(clock.secondsAgo(10), new DateTime(2012, 12, 31, 23, 59, 50, 000)); + }); + + test('should return time seconds from now', () { + expect(clock.secondsFromNow(3), new DateTime(2013, 1, 1, 0, 0, 3, 0)); + }); + + test('should return time minutes ago', () { + expect(clock.minutesAgo(10), new DateTime(2012, 12, 31, 23, 50, 0, 000)); + }); + + test('should return time minutes from now', () { + expect(clock.minutesFromNow(3), new DateTime(2013, 1, 1, 0, 3, 0, 0)); + }); + + test('should return time hours ago', () { + expect(clock.hoursAgo(10), new DateTime(2012, 12, 31, 14, 0, 0, 000)); + }); + + test('should return time hours from now', () { + expect(clock.hoursFromNow(3), new DateTime(2013, 1, 1, 3, 0, 0, 0)); + }); + + test('should return time days ago', () { + expect(clock.daysAgo(10), _date(2012, 12, 22)); + }); + + test('should return time days from now', () { + expect(clock.daysFromNow(3), _date(2013, 1, 4)); + }); + + test('should return time months ago on the same date', () { + expect(clock.monthsAgo(1), _date(2012, 12, 1)); + expect(clock.monthsAgo(2), _date(2012, 11, 1)); + expect(clock.monthsAgo(3), _date(2012, 10, 1)); + expect(clock.monthsAgo(4), _date(2012, 9, 1)); + }); + + test('should return time months from now on the same date', () { + expect(clock.monthsFromNow(1), _date(2013, 2, 1)); + expect(clock.monthsFromNow(2), _date(2013, 3, 1)); + expect(clock.monthsFromNow(3), _date(2013, 4, 1)); + expect(clock.monthsFromNow(4), _date(2013, 5, 1)); + }); + + test('should go from 2013-05-31 to 2012-11-30', () { + expect(_fixed(2013, 5, 31).monthsAgo(6), _date(2012, 11, 30)); + }); + + test('should go from 2013-03-31 to 2013-02-28 (common year)', () { + expect(_fixed(2013, 3, 31).monthsAgo(1), _date(2013, 2, 28)); + }); + + test('should go from 2013-05-31 to 2013-02-28 (common year)', () { + expect(_fixed(2013, 5, 31).monthsAgo(3), _date(2013, 2, 28)); + }); + + test('should go from 2004-03-31 to 2004-02-29 (leap year)', () { + expect(_fixed(2004, 3, 31).monthsAgo(1), _date(2004, 2, 29)); + }); + + test('should go from 2013-03-31 to 2013-06-30', () { + expect(_fixed(2013, 3, 31).monthsFromNow(3), _date(2013, 6, 30)); + }); + + test('should go from 2003-12-31 to 2004-02-29 (common to leap)', () { + expect(_fixed(2003, 12, 31).monthsFromNow(2), _date(2004, 2, 29)); + }); + + test('should go from 2004-02-29 to 2003-02-28 by year', () { + expect(_fixed(2004, 2, 29).yearsAgo(1), _date(2003, 2, 28)); + }); + + test('should go from 2004-02-29 to 2003-02-28 by month', () { + expect(_fixed(2004, 2, 29).monthsAgo(12), _date(2003, 2, 28)); + }); + + test('should go from 2004-02-29 to 2005-02-28 by year', () { + expect(_fixed(2004, 2, 29).yearsFromNow(1), _date(2005, 2, 28)); + }); + + test('should go from 2004-02-29 to 2005-02-28 by month', () { + expect(_fixed(2004, 2, 29).monthsFromNow(12), _date(2005, 2, 28)); + }); + + test('should return time years ago on the same date', () { + expect(clock.yearsAgo(1), _date(2012, 1, 1)); // leap year + expect(clock.yearsAgo(2), _date(2011, 1, 1)); + expect(clock.yearsAgo(3), _date(2010, 1, 1)); + expect(clock.yearsAgo(4), _date(2009, 1, 1)); + expect(clock.yearsAgo(5), _date(2008, 1, 1)); // leap year + expect(clock.yearsAgo(6), _date(2007, 1, 1)); + expect(clock.yearsAgo(30), _date(1983, 1, 1)); + expect(clock.yearsAgo(2013), _date(0, 1, 1)); + }); + + test('should return time years from now on the same date', () { + expect(clock.yearsFromNow(1), _date(2014, 1, 1)); + expect(clock.yearsFromNow(2), _date(2015, 1, 1)); + expect(clock.yearsFromNow(3), _date(2016, 1, 1)); + expect(clock.yearsFromNow(4), _date(2017, 1, 1)); + expect(clock.yearsFromNow(5), _date(2018, 1, 1)); + expect(clock.yearsFromNow(6), _date(2019, 1, 1)); + expect(clock.yearsFromNow(30), _date(2043, 1, 1)); + expect(clock.yearsFromNow(1000), _date(3013, 1, 1)); }); } From 9deed46a985ad6e4da9d9a875fe7f9fbec5e3be4 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 6 Mar 2018 13:52:50 -0800 Subject: [PATCH 26/89] Code review [skip ci] --- pkgs/clock/lib/clock.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 7fd25205a..f3db69b10 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -22,8 +22,7 @@ typedef DateTime TimeFunction(); @Deprecated("Use new DateTime.now() instead.") DateTime systemTime() => new DateTime.now(); -/// A class which encapsulates the notion of the "current time" and provides -/// easy access to points relative to the current time. +/// A provider for the "current time" and points relative to the current time. /// /// This class is designed with testability in mind. The current point in time /// (or [now()]) is defined by a function that returns a [DateTime]. By From 19bcac5f70b65c86d91070cf93560e094bdbfa46 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 6 Mar 2018 15:26:35 -0800 Subject: [PATCH 27/89] Move the implementation of Clock to its own file --- pkgs/clock/lib/clock.dart | 154 +------------------------------ pkgs/clock/lib/src/clock.dart | 169 ++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 153 deletions(-) create mode 100644 pkgs/clock/lib/src/clock.dart diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index f3db69b10..8915ff7b1 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'src/utils.dart'; +export 'src/clock.dart'; /// Returns current time. @Deprecated("Pass around an instance of Clock instead.") @@ -21,155 +21,3 @@ typedef DateTime TimeFunction(); /// Return current system time. @Deprecated("Use new DateTime.now() instead.") DateTime systemTime() => new DateTime.now(); - -/// A provider for the "current time" and points relative to the current time. -/// -/// This class is designed with testability in mind. The current point in time -/// (or [now()]) is defined by a function that returns a [DateTime]. By -/// supplying your own time function or using [new Clock.fixed], you can control -/// exactly what time a [Clock] returns and base your test expectations on that. -class Clock { - /// The function that's called to determine this clock's notion of the current - /// time. - final DateTime Function() _time; - - /// Creates a clock based on the given [currentTime], or on the system clock - /// by default. - const Clock([DateTime currentTime()]) : _time = currentTime ?? systemTime; - - /// Creates [Clock] that always considers the current time to be [time]. - Clock.fixed(DateTime time) : _time = (() => time); - - /// Returns current time. - DateTime now() => _time(); - - /// Returns the point in time [Duration] amount of time ago. - DateTime agoBy(Duration duration) => now().subtract(duration); - - /// Returns the point in time [Duration] amount of time from now. - DateTime fromNowBy(Duration duration) => now().add(duration); - - /// Returns the point in time that's given amount of time ago. - /// - /// The amount of time is the sum of the individual parts. - DateTime ago( - {int days: 0, - int hours: 0, - int minutes: 0, - int seconds: 0, - int milliseconds: 0, - int microseconds: 0}) => - agoBy(new Duration( - days: days, - hours: hours, - minutes: minutes, - seconds: seconds, - milliseconds: milliseconds, - microseconds: microseconds)); - - /// Returns the point in time that's given amount of time from now. - /// - /// The amount of time is the sum of the individual parts. - DateTime fromNow( - {int days: 0, - int hours: 0, - int minutes: 0, - int seconds: 0, - int milliseconds: 0, - int microseconds: 0}) => - fromNowBy(new Duration( - days: days, - hours: hours, - minutes: minutes, - seconds: seconds, - milliseconds: milliseconds, - microseconds: microseconds)); - - /// Return the point in time [microseconds] ago. - DateTime microsAgo(int microseconds) => ago(microseconds: microseconds); - - /// Return the point in time [microseconds] from now. - DateTime microsFromNow(int microseconds) => - fromNow(microseconds: microseconds); - - /// Return the point in time [milliseconds] ago. - DateTime millisAgo(int milliseconds) => ago(milliseconds: milliseconds); - - /// Return the point in time [milliseconds] from now. - DateTime millisFromNow(int milliseconds) => - fromNow(milliseconds: milliseconds); - - /// Return the point in time [seconds] ago. - DateTime secondsAgo(int seconds) => ago(seconds: seconds); - - /// Return the point in time [seconds] from now. - DateTime secondsFromNow(int seconds) => fromNow(seconds: seconds); - - /// Return the point in time [minutes] ago. - DateTime minutesAgo(int minutes) => ago(minutes: minutes); - - /// Return the point in time [minutes] from now. - DateTime minutesFromNow(int minutes) => fromNow(minutes: minutes); - - /// Return the point in time [hours] ago. - DateTime hoursAgo(int hours) => ago(hours: hours); - - /// Return the point in time [hours] from now. - DateTime hoursFromNow(int hours) => fromNow(hours: hours); - - /// Return the point in time [days] ago. - DateTime daysAgo(int days) => ago(days: days); - - /// Return the point in time [days] from now. - DateTime daysFromNow(int days) => fromNow(days: days); - - /// Return the point in time [weeks] ago. - DateTime weeksAgo(int weeks) => ago(days: 7 * weeks); - - /// Return the point in time [weeks] from now. - DateTime weeksFromNow(int weeks) => fromNow(days: 7 * weeks); - - /// Return the point in time [months] ago on the same date. - /// - /// If the current day of the month isn't valid in the new month, the nearest - /// valid day in the new month will be used. - DateTime monthsAgo(int months) { - var time = now(); - var month = (time.month - months - 1) % 12 + 1; - var year = time.year - (months + 12 - time.month) ~/ 12; - var day = clampDayOfMonth(year: year, month: month, day: time.day); - return new DateTime(year, month, day, time.hour, time.minute, time.second, - time.millisecond); - } - - /// Return the point in time [months] from now on the same date. - /// - /// If the current day of the month isn't valid in the new month, the nearest - /// valid day in the new month will be used. - DateTime monthsFromNow(int months) { - var time = now(); - var month = (time.month + months - 1) % 12 + 1; - var year = time.year + (months + time.month - 1) ~/ 12; - var day = clampDayOfMonth(year: year, month: month, day: time.day); - return new DateTime(year, month, day, time.hour, time.minute, time.second, - time.millisecond); - } - - /// Return the point in time [years] ago on the same date. - /// - /// If the current day of the month isn't valid in the new year, the nearest - /// valid day in the original month will be used. - DateTime yearsAgo(int years) { - var time = now(); - var year = time.year - years; - var day = clampDayOfMonth(year: year, month: time.month, day: time.day); - return new DateTime(year, time.month, day, time.hour, time.minute, - time.second, time.millisecond); - } - - /// Return the point in time [years] from now on the same date. - /// - /// If the current day of the month isn't valid in the new year, the nearest - /// valid day in the original month will be used. - DateTime yearsFromNow(int years) => yearsAgo(-years); -} diff --git a/pkgs/clock/lib/src/clock.dart b/pkgs/clock/lib/src/clock.dart new file mode 100644 index 000000000..d11ed5708 --- /dev/null +++ b/pkgs/clock/lib/src/clock.dart @@ -0,0 +1,169 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'utils.dart'; + +import '../clock.dart'; + +/// A provider for the "current time" and points relative to the current time. +/// +/// This class is designed with testability in mind. The current point in time +/// (or [now()]) is defined by a function that returns a [DateTime]. By +/// supplying your own time function or using [new Clock.fixed], you can control +/// exactly what time a [Clock] returns and base your test expectations on that. +class Clock { + /// The function that's called to determine this clock's notion of the current + /// time. + final DateTime Function() _time; + + /// Creates a clock based on the given [currentTime], or on the system clock + /// by default. + const Clock([DateTime currentTime()]) : _time = currentTime ?? systemTime; + + /// Creates [Clock] that always considers the current time to be [time]. + Clock.fixed(DateTime time) : _time = (() => time); + + /// Returns current time. + DateTime now() => _time(); + + /// Returns the point in time [Duration] amount of time ago. + DateTime agoBy(Duration duration) => now().subtract(duration); + + /// Returns the point in time [Duration] amount of time from now. + DateTime fromNowBy(Duration duration) => now().add(duration); + + /// Returns the point in time that's given amount of time ago. + /// + /// The amount of time is the sum of the individual parts. + DateTime ago( + {int days: 0, + int hours: 0, + int minutes: 0, + int seconds: 0, + int milliseconds: 0, + int microseconds: 0}) => + agoBy(new Duration( + days: days, + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds)); + + /// Returns the point in time that's given amount of time from now. + /// + /// The amount of time is the sum of the individual parts. + DateTime fromNow( + {int days: 0, + int hours: 0, + int minutes: 0, + int seconds: 0, + int milliseconds: 0, + int microseconds: 0}) => + fromNowBy(new Duration( + days: days, + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds)); + + /// Return the point in time [microseconds] ago. + DateTime microsAgo(int microseconds) => ago(microseconds: microseconds); + + /// Return the point in time [microseconds] from now. + DateTime microsFromNow(int microseconds) => + fromNow(microseconds: microseconds); + + /// Return the point in time [milliseconds] ago. + DateTime millisAgo(int milliseconds) => ago(milliseconds: milliseconds); + + /// Return the point in time [milliseconds] from now. + DateTime millisFromNow(int milliseconds) => + fromNow(milliseconds: milliseconds); + + /// Return the point in time [seconds] ago. + DateTime secondsAgo(int seconds) => ago(seconds: seconds); + + /// Return the point in time [seconds] from now. + DateTime secondsFromNow(int seconds) => fromNow(seconds: seconds); + + /// Return the point in time [minutes] ago. + DateTime minutesAgo(int minutes) => ago(minutes: minutes); + + /// Return the point in time [minutes] from now. + DateTime minutesFromNow(int minutes) => fromNow(minutes: minutes); + + /// Return the point in time [hours] ago. + DateTime hoursAgo(int hours) => ago(hours: hours); + + /// Return the point in time [hours] from now. + DateTime hoursFromNow(int hours) => fromNow(hours: hours); + + /// Return the point in time [days] ago. + DateTime daysAgo(int days) => ago(days: days); + + /// Return the point in time [days] from now. + DateTime daysFromNow(int days) => fromNow(days: days); + + /// Return the point in time [weeks] ago. + DateTime weeksAgo(int weeks) => ago(days: 7 * weeks); + + /// Return the point in time [weeks] from now. + DateTime weeksFromNow(int weeks) => fromNow(days: 7 * weeks); + + /// Return the point in time [months] ago on the same date. + /// + /// If the current day of the month isn't valid in the new month, the nearest + /// valid day in the new month will be used. + DateTime monthsAgo(int months) { + var time = now(); + var month = (time.month - months - 1) % 12 + 1; + var year = time.year - (months + 12 - time.month) ~/ 12; + var day = clampDayOfMonth(year: year, month: month, day: time.day); + return new DateTime(year, month, day, time.hour, time.minute, time.second, + time.millisecond); + } + + /// Return the point in time [months] from now on the same date. + /// + /// If the current day of the month isn't valid in the new month, the nearest + /// valid day in the new month will be used. + DateTime monthsFromNow(int months) { + var time = now(); + var month = (time.month + months - 1) % 12 + 1; + var year = time.year + (months + time.month - 1) ~/ 12; + var day = clampDayOfMonth(year: year, month: month, day: time.day); + return new DateTime(year, month, day, time.hour, time.minute, time.second, + time.millisecond); + } + + /// Return the point in time [years] ago on the same date. + /// + /// If the current day of the month isn't valid in the new year, the nearest + /// valid day in the original month will be used. + DateTime yearsAgo(int years) { + var time = now(); + var year = time.year - years; + var day = clampDayOfMonth(year: year, month: time.month, day: time.day); + return new DateTime(year, time.month, day, time.hour, time.minute, + time.second, time.millisecond); + } + + /// Return the point in time [years] from now on the same date. + /// + /// If the current day of the month isn't valid in the new year, the nearest + /// valid day in the original month will be used. + DateTime yearsFromNow(int years) => yearsAgo(-years); +} From f94ceb555452b000291ca11e737d3e4debc5ddb5 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 6 Mar 2018 15:53:56 -0800 Subject: [PATCH 28/89] Add a Zone-scoped clock field --- pkgs/clock/lib/clock.dart | 1 + pkgs/clock/lib/src/clock.dart | 4 ++ pkgs/clock/lib/src/default.dart | 48 +++++++++++++++ pkgs/clock/pubspec.yaml | 2 +- pkgs/clock/test/clock_test.dart | 98 ++++++++++++++----------------- pkgs/clock/test/default_test.dart | 79 +++++++++++++++++++++++++ pkgs/clock/test/utils.dart | 25 ++++++++ 7 files changed, 203 insertions(+), 54 deletions(-) create mode 100644 pkgs/clock/lib/src/default.dart create mode 100644 pkgs/clock/test/default_test.dart create mode 100644 pkgs/clock/test/utils.dart diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 8915ff7b1..19d5efd71 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -13,6 +13,7 @@ // limitations under the License. export 'src/clock.dart'; +export 'src/default.dart'; /// Returns current time. @Deprecated("Pass around an instance of Clock instead.") diff --git a/pkgs/clock/lib/src/clock.dart b/pkgs/clock/lib/src/clock.dart index d11ed5708..e518522c2 100644 --- a/pkgs/clock/lib/src/clock.dart +++ b/pkgs/clock/lib/src/clock.dart @@ -22,6 +22,10 @@ import '../clock.dart'; /// (or [now()]) is defined by a function that returns a [DateTime]. By /// supplying your own time function or using [new Clock.fixed], you can control /// exactly what time a [Clock] returns and base your test expectations on that. +/// +/// Most users should use the top-level [clock] field, which provides access to +/// a default implementation of [Clock] which can be overridden using +/// [withClock]. class Clock { /// The function that's called to determine this clock's notion of the current /// time. diff --git a/pkgs/clock/lib/src/default.dart b/pkgs/clock/lib/src/default.dart new file mode 100644 index 000000000..b380927ae --- /dev/null +++ b/pkgs/clock/lib/src/default.dart @@ -0,0 +1,48 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'dart:async'; + +import 'clock.dart'; + +/// The key for the [Zone] value that controls the current implementation of +/// [clock]. +final _clockKey = new Object(); + +/// The key for the [Zone] value that controls whether nested zones can override +/// [clock]. +final _isFinalKey = new Object(); + +/// The default implementation of [clock] for the current [Zone]. +/// +/// This defaults to the system clock. It can be set within a zone using +/// [withClock]. +Clock get clock => Zone.current[_clockKey] ?? const Clock(); + +/// Runs [callback] with the given value for the top-level [clock] field. +/// +/// This is [Zone]-scoped, so asynchronous callbacks spawned within [callback] +/// will also use the new value for [clock]. +/// +/// If [isFinal] is `true`, calls to [withClock] within [callback] will throw a +/// [StateError]. However, this parameter is deprecated and should be avoided. +T withClock(Clock clock, T callback(), {@deprecated bool isFinal: false}) { + if (Zone.current[_isFinalKey] ?? false) { + throw new StateError( + "Cannot call withClock() within a call to withClock(isFinal: true)."); + } + + return runZoned(callback, + zoneValues: {_clockKey: clock, _isFinalKey: isFinal}); +} diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 5ebecf2f4..4d1449d5b 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -11,4 +11,4 @@ dependencies: meta: '>=0.9.0 <2.0.0' dev_dependencies: - test: '^0.12.0' + test: '^0.12.28' diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 633cdb990..3d2d1b259 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -16,20 +16,12 @@ import 'package:clock/clock.dart'; import 'package:test/test.dart'; -/// A utility function for tersely constructing a [DateTime] with no time -/// component. -DateTime _date(int year, [int month, int day]) => - new DateTime(year, month ?? 1, day ?? 1); - -/// Return a clock that always returns a date with the given [year], [month], -/// and [day]. -Clock _fixed(int year, [int month, int day]) => - new Clock.fixed(_date(year, month, day)); +import 'utils.dart'; main() { Clock clock; setUp(() { - clock = new Clock.fixed(_date(2013)); + clock = new Clock.fixed(date(2013)); }); test('should return a non-null value from system clock', () { @@ -50,24 +42,24 @@ main() { }); test('should return time provided by a custom function', () { - var time = _date(2013); + var time = date(2013); var fixedClock = new Clock(() => time); - expect(fixedClock.now(), _date(2013)); + expect(fixedClock.now(), date(2013)); - time = _date(2014); - expect(fixedClock.now(), _date(2014)); + time = date(2014); + expect(fixedClock.now(), date(2014)); }); test('should return fixed time', () { - expect(new Clock.fixed(_date(2013)).now(), _date(2013)); + expect(new Clock.fixed(date(2013)).now(), date(2013)); }); test('should return time Duration ago', () { - expect(clock.agoBy(const Duration(days: 366)), _date(2012)); + expect(clock.agoBy(const Duration(days: 366)), date(2012)); }); test('should return time Duration from now', () { - expect(clock.fromNowBy(const Duration(days: 365)), _date(2014)); + expect(clock.fromNowBy(const Duration(days: 365)), date(2014)); }); test('should return time parts ago', () { @@ -135,86 +127,86 @@ main() { }); test('should return time days ago', () { - expect(clock.daysAgo(10), _date(2012, 12, 22)); + expect(clock.daysAgo(10), date(2012, 12, 22)); }); test('should return time days from now', () { - expect(clock.daysFromNow(3), _date(2013, 1, 4)); + expect(clock.daysFromNow(3), date(2013, 1, 4)); }); test('should return time months ago on the same date', () { - expect(clock.monthsAgo(1), _date(2012, 12, 1)); - expect(clock.monthsAgo(2), _date(2012, 11, 1)); - expect(clock.monthsAgo(3), _date(2012, 10, 1)); - expect(clock.monthsAgo(4), _date(2012, 9, 1)); + expect(clock.monthsAgo(1), date(2012, 12, 1)); + expect(clock.monthsAgo(2), date(2012, 11, 1)); + expect(clock.monthsAgo(3), date(2012, 10, 1)); + expect(clock.monthsAgo(4), date(2012, 9, 1)); }); test('should return time months from now on the same date', () { - expect(clock.monthsFromNow(1), _date(2013, 2, 1)); - expect(clock.monthsFromNow(2), _date(2013, 3, 1)); - expect(clock.monthsFromNow(3), _date(2013, 4, 1)); - expect(clock.monthsFromNow(4), _date(2013, 5, 1)); + expect(clock.monthsFromNow(1), date(2013, 2, 1)); + expect(clock.monthsFromNow(2), date(2013, 3, 1)); + expect(clock.monthsFromNow(3), date(2013, 4, 1)); + expect(clock.monthsFromNow(4), date(2013, 5, 1)); }); test('should go from 2013-05-31 to 2012-11-30', () { - expect(_fixed(2013, 5, 31).monthsAgo(6), _date(2012, 11, 30)); + expect(fixed(2013, 5, 31).monthsAgo(6), date(2012, 11, 30)); }); test('should go from 2013-03-31 to 2013-02-28 (common year)', () { - expect(_fixed(2013, 3, 31).monthsAgo(1), _date(2013, 2, 28)); + expect(fixed(2013, 3, 31).monthsAgo(1), date(2013, 2, 28)); }); test('should go from 2013-05-31 to 2013-02-28 (common year)', () { - expect(_fixed(2013, 5, 31).monthsAgo(3), _date(2013, 2, 28)); + expect(fixed(2013, 5, 31).monthsAgo(3), date(2013, 2, 28)); }); test('should go from 2004-03-31 to 2004-02-29 (leap year)', () { - expect(_fixed(2004, 3, 31).monthsAgo(1), _date(2004, 2, 29)); + expect(fixed(2004, 3, 31).monthsAgo(1), date(2004, 2, 29)); }); test('should go from 2013-03-31 to 2013-06-30', () { - expect(_fixed(2013, 3, 31).monthsFromNow(3), _date(2013, 6, 30)); + expect(fixed(2013, 3, 31).monthsFromNow(3), date(2013, 6, 30)); }); test('should go from 2003-12-31 to 2004-02-29 (common to leap)', () { - expect(_fixed(2003, 12, 31).monthsFromNow(2), _date(2004, 2, 29)); + expect(fixed(2003, 12, 31).monthsFromNow(2), date(2004, 2, 29)); }); test('should go from 2004-02-29 to 2003-02-28 by year', () { - expect(_fixed(2004, 2, 29).yearsAgo(1), _date(2003, 2, 28)); + expect(fixed(2004, 2, 29).yearsAgo(1), date(2003, 2, 28)); }); test('should go from 2004-02-29 to 2003-02-28 by month', () { - expect(_fixed(2004, 2, 29).monthsAgo(12), _date(2003, 2, 28)); + expect(fixed(2004, 2, 29).monthsAgo(12), date(2003, 2, 28)); }); test('should go from 2004-02-29 to 2005-02-28 by year', () { - expect(_fixed(2004, 2, 29).yearsFromNow(1), _date(2005, 2, 28)); + expect(fixed(2004, 2, 29).yearsFromNow(1), date(2005, 2, 28)); }); test('should go from 2004-02-29 to 2005-02-28 by month', () { - expect(_fixed(2004, 2, 29).monthsFromNow(12), _date(2005, 2, 28)); + expect(fixed(2004, 2, 29).monthsFromNow(12), date(2005, 2, 28)); }); test('should return time years ago on the same date', () { - expect(clock.yearsAgo(1), _date(2012, 1, 1)); // leap year - expect(clock.yearsAgo(2), _date(2011, 1, 1)); - expect(clock.yearsAgo(3), _date(2010, 1, 1)); - expect(clock.yearsAgo(4), _date(2009, 1, 1)); - expect(clock.yearsAgo(5), _date(2008, 1, 1)); // leap year - expect(clock.yearsAgo(6), _date(2007, 1, 1)); - expect(clock.yearsAgo(30), _date(1983, 1, 1)); - expect(clock.yearsAgo(2013), _date(0, 1, 1)); + expect(clock.yearsAgo(1), date(2012, 1, 1)); // leap year + expect(clock.yearsAgo(2), date(2011, 1, 1)); + expect(clock.yearsAgo(3), date(2010, 1, 1)); + expect(clock.yearsAgo(4), date(2009, 1, 1)); + expect(clock.yearsAgo(5), date(2008, 1, 1)); // leap year + expect(clock.yearsAgo(6), date(2007, 1, 1)); + expect(clock.yearsAgo(30), date(1983, 1, 1)); + expect(clock.yearsAgo(2013), date(0, 1, 1)); }); test('should return time years from now on the same date', () { - expect(clock.yearsFromNow(1), _date(2014, 1, 1)); - expect(clock.yearsFromNow(2), _date(2015, 1, 1)); - expect(clock.yearsFromNow(3), _date(2016, 1, 1)); - expect(clock.yearsFromNow(4), _date(2017, 1, 1)); - expect(clock.yearsFromNow(5), _date(2018, 1, 1)); - expect(clock.yearsFromNow(6), _date(2019, 1, 1)); - expect(clock.yearsFromNow(30), _date(2043, 1, 1)); - expect(clock.yearsFromNow(1000), _date(3013, 1, 1)); + expect(clock.yearsFromNow(1), date(2014, 1, 1)); + expect(clock.yearsFromNow(2), date(2015, 1, 1)); + expect(clock.yearsFromNow(3), date(2016, 1, 1)); + expect(clock.yearsFromNow(4), date(2017, 1, 1)); + expect(clock.yearsFromNow(5), date(2018, 1, 1)); + expect(clock.yearsFromNow(6), date(2019, 1, 1)); + expect(clock.yearsFromNow(30), date(2043, 1, 1)); + expect(clock.yearsFromNow(1000), date(3013, 1, 1)); }); } diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart new file mode 100644 index 000000000..edcb7cd92 --- /dev/null +++ b/pkgs/clock/test/default_test.dart @@ -0,0 +1,79 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the 'License'); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an 'AS IS' BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'dart:async'; + +import 'package:clock/clock.dart'; + +import 'package:test/test.dart'; + +import 'utils.dart'; + +void main() { + test("the default clock returns the system time", () { + expect(new DateTime.now().difference(clock.now()).inMilliseconds.abs(), + lessThan(100)); + }); + + group("withClock()", () { + group("overrides the clock", () { + test("synchronously", () { + var time = date(1990, 11, 8); + withClock(new Clock(() => time), () { + expect(clock.now(), equals(time)); + time = date(2016, 6, 26); + expect(clock.now(), equals(time)); + }); + }); + + test("asynchronously", () { + var time = date(1990, 11, 8); + withClock(new Clock.fixed(time), () { + expect(new Future(() async { + expect(clock.now(), equals(time)); + }), completes); + }); + }); + + test("within another withClock() call", () { + var outerTime = date(1990, 11, 8); + withClock(new Clock.fixed(outerTime), () { + expect(clock.now(), equals(outerTime)); + + var innerTime = date(2016, 11, 8); + withClock(new Clock.fixed(innerTime), () { + expect(clock.now(), equals(innerTime)); + expect(new Future(() async { + expect(clock.now(), equals(innerTime)); + }), completes); + }); + + expect(clock.now(), equals(outerTime)); + }); + }); + }); + + test("with isFinal: true doesn't allow nested calls", () { + var outerTime = date(1990, 11, 8); + withClock(new Clock.fixed(outerTime), () { + expect(clock.now(), equals(outerTime)); + + expect( + () => withClock(fixed(2016, 11, 8), neverCalled), throwsStateError); + + expect(clock.now(), equals(outerTime)); + }, isFinal: true); + }); + }); +} diff --git a/pkgs/clock/test/utils.dart b/pkgs/clock/test/utils.dart new file mode 100644 index 000000000..17c07f34a --- /dev/null +++ b/pkgs/clock/test/utils.dart @@ -0,0 +1,25 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'package:clock/clock.dart'; + +/// A utility function for tersely constructing a [DateTime] with no time +/// component. +DateTime date(int year, [int month, int day]) => + new DateTime(year, month ?? 1, day ?? 1); + +/// Returns a clock that always returns a date with the given [year], [month], +/// and [day]. +Clock fixed(int year, [int month, int day]) => + new Clock.fixed(date(year, month, day)); From b0c2595070ef2a952d899eb3241993f8b3e24eb3 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 6 Mar 2018 17:28:52 -0800 Subject: [PATCH 29/89] Add features from the old clock package where possible --- pkgs/clock/CHANGELOG.md | 32 +++++- pkgs/clock/README.md | 2 +- pkgs/clock/lib/clock.dart | 10 +- pkgs/clock/lib/src/clock.dart | 8 ++ pkgs/clock/lib/src/stopwatch.dart | 64 +++++++++++ pkgs/clock/pubspec.yaml | 2 +- pkgs/clock/test/stopwatch_test.dart | 169 ++++++++++++++++++++++++++++ 7 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 pkgs/clock/lib/src/stopwatch.dart create mode 100644 pkgs/clock/test/stopwatch_test.dart diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 5b26ad30f..4ad290fa4 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,33 @@ ## 1.0.0 -* Initial version. +This release contains the `Clock` class that was defined in [`quiver`][]. It's +backwards-compatible with the `quiver` version, and *mostly* +backwards-compatible with the old version of the `clock` package. + +[`quiver`]: https://pub.dartlang.org/packages/quiver + +### New Features + +* A top-level `clock` field has been added that provides a default `Clock` + implementation. It can be controlled by the `withClock()` function. It should + generally be used in preference to manual dependency-injection, since it will + work with the [`fake_async`][] package. + +* A `Clock.stopwatch()` method has been added that creates a `Stopwatch` that + uses the clock as its source of time. + +[`fake_async`]: https://pub.dartlang.org/packages/fake_async + +### Changes Relative to `clock` 0.1 + +* The top-level `new` getter and `getStopwatch()` methods are deprecated. + `clock.new()` and `clock.getStopwatch()` should be used instead. + +* `Clock.getStopwatch()` is deprecated. `Clock.stopwatch()` should be used instead. + +* The `isFinal` argument to `withClock()` is deprecated. + +* `new Clock()` now takes an optional positional argument that returns the + current time as a `DateTime` instead of its old arguments. + +* `Clock.now()` is now a method rather than a getter. diff --git a/pkgs/clock/README.md b/pkgs/clock/README.md index 905f3b3b1..68bdba1ff 100644 --- a/pkgs/clock/README.md +++ b/pkgs/clock/README.md @@ -15,7 +15,7 @@ import 'package:clock/clock.dart'; /// Runs [callback] and prints how long it took. T runWithTiming(T callback()) { - var stopwatch = clock.getStopwatch()..start(); + var stopwatch = clock.stopwatch()..start(); var result = callback(); print("It took ${stopwatch.elapsed}!"); return result; diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 19d5efd71..786585fcb 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -19,6 +19,14 @@ export 'src/default.dart'; @Deprecated("Pass around an instance of Clock instead.") typedef DateTime TimeFunction(); -/// Return current system time. +/// Returns the current system time. @Deprecated("Use new DateTime.now() instead.") DateTime systemTime() => new DateTime.now(); + +/// Returns the current time as reported by [clock]. +@Deprecated("Use clock.now() instead.") +DateTime get now => clock.now(); + +/// Returns a stopwatch that uses the current time as reported by [clock]. +@Deprecated("Use clock.stopwatch() instead.") +Stopwatch getStopwatch() => clock.stopwatch(); diff --git a/pkgs/clock/lib/src/clock.dart b/pkgs/clock/lib/src/clock.dart index e518522c2..0ff29bfe8 100644 --- a/pkgs/clock/lib/src/clock.dart +++ b/pkgs/clock/lib/src/clock.dart @@ -15,6 +15,7 @@ import 'utils.dart'; import '../clock.dart'; +import 'stopwatch.dart'; /// A provider for the "current time" and points relative to the current time. /// @@ -170,4 +171,11 @@ class Clock { /// If the current day of the month isn't valid in the new year, the nearest /// valid day in the original month will be used. DateTime yearsFromNow(int years) => yearsAgo(-years); + + /// Returns a new stopwatch that uses the current time as reported by [this]. + Stopwatch stopwatch() => new ClockStopwatch(this); + + /// Returns a new stopwatch that uses the current time as reported by [this]. + @Deprecated("Use stopwatch() instead.") + Stopwatch getStopwatch() => stopwatch(); } diff --git a/pkgs/clock/lib/src/stopwatch.dart b/pkgs/clock/lib/src/stopwatch.dart new file mode 100644 index 000000000..1cf66a45c --- /dev/null +++ b/pkgs/clock/lib/src/stopwatch.dart @@ -0,0 +1,64 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'clock.dart'; + +/// The system's timer frequency in Hz. +/// +/// We can't really know how frequently the clock is updated, and that may not +/// even make sense for some implementations, so we just pretend we follow the +/// system's frequency. +final _frequency = new Stopwatch().frequency; + +/// A stopwatch that gets its notion of the current time from a [Clock]. +class ClockStopwatch implements Stopwatch { + /// The provider for this stopwatch's notion of the current time. + final Clock _clock; + + /// The number of elapsed microseconds that have been recorded from previous + /// runs of this stopwatch. + /// + /// This doesn't include the time between [_start] and the current time. + var _elapsed = 0; + + /// The point at which [start] was called most recently, or `null` if this + /// isn't active. + DateTime _start; + + ClockStopwatch(this._clock); + + int get frequency => _frequency; + int get elapsedTicks => (elapsedMicroseconds * frequency) ~/ 1000000; + Duration get elapsed => new Duration(microseconds: elapsedMicroseconds); + int get elapsedMilliseconds => elapsedMicroseconds ~/ 1000; + bool get isRunning => _start != null; + + int get elapsedMicroseconds => + _elapsed + + (_start == null ? 0 : _clock.now().difference(_start).inMicroseconds); + + void start() { + _start ??= _clock.now(); + } + + void stop() { + _elapsed = elapsedMicroseconds; + _start = null; + } + + void reset() { + _elapsed = 0; + if (_start != null) _start = _clock.now(); + } +} diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 4d1449d5b..8a79678a2 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,5 +1,5 @@ name: clock -version: 1.0.0-dev +version: 1.0.0 description: A fakeable wrapper for dart:core clock APIs author: Dart Team homepage: https://github.com/dart-lang/clock diff --git a/pkgs/clock/test/stopwatch_test.dart b/pkgs/clock/test/stopwatch_test.dart new file mode 100644 index 000000000..66f01b067 --- /dev/null +++ b/pkgs/clock/test/stopwatch_test.dart @@ -0,0 +1,169 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the 'License'); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an 'AS IS' BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'dart:async'; + +import 'package:clock/clock.dart'; + +import 'package:test/test.dart'; + +import 'utils.dart'; + +void main() { + test("returns the system frequency", () { + expect(fixed(1990, 11, 8).stopwatch().frequency, + equals(new Stopwatch().frequency)); + }); + + group("before it starts", () { + Stopwatch stopwatch; + setUp(() { + stopwatch = clock.stopwatch(); + }); + + test("is not running", () => expect(stopwatch.isRunning, isFalse)); + + test("stop() does nothing", () { + stopwatch.stop(); + expect(stopwatch.isRunning, isFalse); + expect(stopwatch.elapsed, equals(Duration.ZERO)); + }); + + group("reports no elapsed", () { + test("duration", () => expect(stopwatch.elapsed, equals(Duration.ZERO))); + test("ticks", () => expect(stopwatch.elapsedTicks, isZero)); + test("microseconds", () => expect(stopwatch.elapsedMicroseconds, isZero)); + test("milliseconds", () => expect(stopwatch.elapsedMilliseconds, isZero)); + }); + }); + + group("when 12345μs have elapsed", () { + DateTime time; + Clock clock; + Stopwatch stopwatch; + setUp(() { + time = date(1990, 11, 8); + clock = new Clock(() => time); + stopwatch = clock.stopwatch()..start(); + time = clock.microsFromNow(12345); + }); + + group("and the stopwatch is active", () { + test("is running", () { + expect(stopwatch.isRunning, isTrue); + }); + + test("reports more elapsed time", () { + time = clock.microsFromNow(54321); + expect(stopwatch.elapsedMicroseconds, equals(66666)); + }); + + test("start does nothing", () { + stopwatch.start(); + expect(stopwatch.isRunning, isTrue); + expect(stopwatch.elapsedMicroseconds, equals(12345)); + }); + + group("reset()", () { + setUp(() { + stopwatch.reset(); + }); + + test("sets the elapsed time to zero", () { + expect(stopwatch.elapsed, equals(Duration.ZERO)); + }); + + test("reports more elapsed time", () { + time = clock.microsFromNow(54321); + expect(stopwatch.elapsedMicroseconds, equals(54321)); + }); + }); + + group("reports elapsed", () { + test("duration", () { + expect(stopwatch.elapsed, equals(new Duration(microseconds: 12345))); + }); + + test("ticks", () { + expect(stopwatch.elapsedTicks, + equals((new Stopwatch().frequency * 12345) ~/ 1000000)); + }); + + test("microseconds", () { + expect(stopwatch.elapsedMicroseconds, equals(12345)); + }); + + test("milliseconds", () { + expect(stopwatch.elapsedMilliseconds, equals(12)); + }); + }); + }); + + group("and the stopwatch is inactive, reports that as", () { + setUp(() { + stopwatch.stop(); + }); + + test("is not running", () { + expect(stopwatch.isRunning, isFalse); + }); + + test("doesn't report more elapsed time", () { + time = clock.microsFromNow(54321); + expect(stopwatch.elapsedMicroseconds, equals(12345)); + }); + + test("start starts reporting more elapsed time", () { + stopwatch.start(); + expect(stopwatch.isRunning, isTrue); + time = clock.microsFromNow(54321); + expect(stopwatch.elapsedMicroseconds, equals(66666)); + }); + + group("reset()", () { + setUp(() { + stopwatch.reset(); + }); + + test("sets the elapsed time to zero", () { + expect(stopwatch.elapsed, equals(Duration.ZERO)); + }); + + test("doesn't report more elapsed time", () { + time = clock.microsFromNow(54321); + expect(stopwatch.elapsed, equals(Duration.ZERO)); + }); + }); + + group("reports elapsed", () { + test("duration", () { + expect(stopwatch.elapsed, equals(new Duration(microseconds: 12345))); + }); + + test("ticks", () { + expect(stopwatch.elapsedTicks, + equals((new Stopwatch().frequency * 12345) ~/ 1000000)); + }); + + test("microseconds", () { + expect(stopwatch.elapsedMicroseconds, equals(12345)); + }); + + test("milliseconds", () { + expect(stopwatch.elapsedMilliseconds, equals(12)); + }); + }); + }); + }); +} From de3d7f2244a782b278c67753432ea857084942b6 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 7 Mar 2018 13:05:59 -0800 Subject: [PATCH 30/89] Code review change --- pkgs/clock/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 4ad290fa4..de66ff8dc 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -21,7 +21,7 @@ backwards-compatible with the old version of the `clock` package. ### Changes Relative to `clock` 0.1 * The top-level `new` getter and `getStopwatch()` methods are deprecated. - `clock.new()` and `clock.getStopwatch()` should be used instead. + `clock.new()` and `clock.stopwatch()` should be used instead. * `Clock.getStopwatch()` is deprecated. `Clock.stopwatch()` should be used instead. From 71cca229fe1f0ce1022a0c2395df39f5c5e8e1ce Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 7 Mar 2018 13:06:05 -0800 Subject: [PATCH 31/89] Fix test failures --- pkgs/clock/lib/clock.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 786585fcb..f7bf0b726 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -15,6 +15,8 @@ export 'src/clock.dart'; export 'src/default.dart'; +import 'src/default.dart'; + /// Returns current time. @Deprecated("Pass around an instance of Clock instead.") typedef DateTime TimeFunction(); From ef407f3c6b523c0395ab5a937e481801905c1ac0 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 7 Mar 2018 13:32:06 -0800 Subject: [PATCH 32/89] Fix const Clock() for Dart 1 --- pkgs/clock/lib/src/clock.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/lib/src/clock.dart b/pkgs/clock/lib/src/clock.dart index 0ff29bfe8..2984e3010 100644 --- a/pkgs/clock/lib/src/clock.dart +++ b/pkgs/clock/lib/src/clock.dart @@ -34,7 +34,7 @@ class Clock { /// Creates a clock based on the given [currentTime], or on the system clock /// by default. - const Clock([DateTime currentTime()]) : _time = currentTime ?? systemTime; + const Clock([DateTime currentTime() = systemTime]) : _time = currentTime; /// Creates [Clock] that always considers the current time to be [time]. Clock.fixed(DateTime time) : _time = (() => time); From fad1a2ef03898c9a229f0b3856408d79950b3731 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 1 May 2018 15:57:04 -0700 Subject: [PATCH 33/89] Fix runtime Dart 2 errors in tests (dart-lang/clock#3) Works around dart-lang/sdkdart-lang/clock#33015. --- pkgs/clock/test/default_test.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart index edcb7cd92..48ef06eb3 100644 --- a/pkgs/clock/test/default_test.dart +++ b/pkgs/clock/test/default_test.dart @@ -69,11 +69,17 @@ void main() { withClock(new Clock.fixed(outerTime), () { expect(clock.now(), equals(outerTime)); - expect( - () => withClock(fixed(2016, 11, 8), neverCalled), throwsStateError); + expect(() => withClock(fixed(2016, 11, 8), neverCalledVoid), + throwsStateError); expect(clock.now(), equals(outerTime)); }, isFinal: true); }); }); } + +/// A wrapper for [neverCalled] that works around sdk#33015. +void Function() get neverCalledVoid { + var function = neverCalled; + return () => neverCalled(); +} From 71637de818cf25c380d5ac854397a0cd5129f860 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 2 May 2018 13:01:53 -0700 Subject: [PATCH 34/89] Fix analysis issues (dart-lang/clock#4) --- pkgs/clock/test/default_test.dart | 2 +- pkgs/clock/test/stopwatch_test.dart | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart index 48ef06eb3..d75e8da2c 100644 --- a/pkgs/clock/test/default_test.dart +++ b/pkgs/clock/test/default_test.dart @@ -81,5 +81,5 @@ void main() { /// A wrapper for [neverCalled] that works around sdk#33015. void Function() get neverCalledVoid { var function = neverCalled; - return () => neverCalled(); + return () => function(); } diff --git a/pkgs/clock/test/stopwatch_test.dart b/pkgs/clock/test/stopwatch_test.dart index 66f01b067..11e625522 100644 --- a/pkgs/clock/test/stopwatch_test.dart +++ b/pkgs/clock/test/stopwatch_test.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'dart:async'; - import 'package:clock/clock.dart'; import 'package:test/test.dart'; From 21615981c835bde8b10237c9640f44ea3c110892 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Fri, 13 Jul 2018 13:47:21 -0700 Subject: [PATCH 35/89] Fix to use lowercase Dart 2 core library constant names. --- pkgs/clock/CHANGELOG.md | 4 ++++ pkgs/clock/analysis_options.yaml | 2 -- pkgs/clock/lib/src/utils.dart | 2 +- pkgs/clock/pubspec.yaml | 4 ++-- pkgs/clock/test/stopwatch_test.dart | 10 +++++----- 5 files changed, 12 insertions(+), 10 deletions(-) delete mode 100644 pkgs/clock/analysis_options.yaml diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index de66ff8dc..d1932bce8 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.1 + +* Update to lowercase Dart core library constants. + ## 1.0.0 This release contains the `Clock` class that was defined in [`quiver`][]. It's diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml deleted file mode 100644 index a10d4c5a0..000000000 --- a/pkgs/clock/analysis_options.yaml +++ /dev/null @@ -1,2 +0,0 @@ -analyzer: - strong-mode: true diff --git a/pkgs/clock/lib/src/utils.dart b/pkgs/clock/lib/src/utils.dart index 48fd0be30..c1223cf98 100644 --- a/pkgs/clock/lib/src/utils.dart +++ b/pkgs/clock/lib/src/utils.dart @@ -29,7 +29,7 @@ const _daysInMonth = const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; /// This function assumes the use of the Gregorian calendar or the proleptic /// Gregorian calendar. int daysInMonth(int year, int month) => - (month == DateTime.FEBRUARY && isLeapYear(year)) ? 29 : _daysInMonth[month]; + (month == DateTime.february && isLeapYear(year)) ? 29 : _daysInMonth[month]; /// Returns true if [year] is a leap year. /// diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 8a79678a2..6d7325de8 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,11 +1,11 @@ name: clock -version: 1.0.0 +version: 1.0.1 description: A fakeable wrapper for dart:core clock APIs author: Dart Team homepage: https://github.com/dart-lang/clock environment: - sdk: '>=1.24.0 <2.0.0' + sdk: '>=2.0.0-dev.36.0 <3.0.0' dependencies: meta: '>=0.9.0 <2.0.0' diff --git a/pkgs/clock/test/stopwatch_test.dart b/pkgs/clock/test/stopwatch_test.dart index 11e625522..151d2dc95 100644 --- a/pkgs/clock/test/stopwatch_test.dart +++ b/pkgs/clock/test/stopwatch_test.dart @@ -35,11 +35,11 @@ void main() { test("stop() does nothing", () { stopwatch.stop(); expect(stopwatch.isRunning, isFalse); - expect(stopwatch.elapsed, equals(Duration.ZERO)); + expect(stopwatch.elapsed, equals(Duration.zero)); }); group("reports no elapsed", () { - test("duration", () => expect(stopwatch.elapsed, equals(Duration.ZERO))); + test("duration", () => expect(stopwatch.elapsed, equals(Duration.zero))); test("ticks", () => expect(stopwatch.elapsedTicks, isZero)); test("microseconds", () => expect(stopwatch.elapsedMicroseconds, isZero)); test("milliseconds", () => expect(stopwatch.elapsedMilliseconds, isZero)); @@ -79,7 +79,7 @@ void main() { }); test("sets the elapsed time to zero", () { - expect(stopwatch.elapsed, equals(Duration.ZERO)); + expect(stopwatch.elapsed, equals(Duration.zero)); }); test("reports more elapsed time", () { @@ -135,12 +135,12 @@ void main() { }); test("sets the elapsed time to zero", () { - expect(stopwatch.elapsed, equals(Duration.ZERO)); + expect(stopwatch.elapsed, equals(Duration.zero)); }); test("doesn't report more elapsed time", () { time = clock.microsFromNow(54321); - expect(stopwatch.elapsed, equals(Duration.ZERO)); + expect(stopwatch.elapsed, equals(Duration.zero)); }); }); From c67d55d8dfd68b7f9aeb198ca06ec4ef8b6b63d1 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Fri, 13 Jul 2018 16:38:55 -0700 Subject: [PATCH 36/89] Don't run Travis on stable. --- pkgs/clock/.travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index 9124e035b..70fa656b9 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -7,7 +7,6 @@ language: dart dart: - dev -- stable # See https://docs.travis-ci.com/user/languages/dart/ for details. dart_task: @@ -19,10 +18,9 @@ dart_task: # them against each Dart version. matrix: include: - - dart: stable - dart_task: dartfmt - dart: dev dart_task: dartanalyzer + dart_task: dartfmt # Only building master means that we don't run two builds for each pull request. branches: From 9aa00f952fe6fd3f1d0e0884ace540c4989fe048 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sun, 15 Jul 2018 19:08:04 -0700 Subject: [PATCH 37/89] Fix travis (dart-lang/clock#7) --- pkgs/clock/.travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index 70fa656b9..a9f76c7fc 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -20,6 +20,7 @@ matrix: include: - dart: dev dart_task: dartanalyzer + - dart: dev dart_task: dartfmt # Only building master means that we don't run two builds for each pull request. From 30f57c963e28b071d93a91f9d50d3875a841a743 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 14 Aug 2018 12:46:23 -0700 Subject: [PATCH 38/89] Update .travis.yml (dart-lang/clock#9) --- pkgs/clock/.travis.yml | 5 ++--- pkgs/clock/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index a9f76c7fc..468491aad 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -7,12 +7,11 @@ language: dart dart: - dev +- stable # See https://docs.travis-ci.com/user/languages/dart/ for details. dart_task: -- test: --platform vm -# Uncomment this line to run tests on the browser. -# - test: --platform firefox + - test # Only run one instance of the formatter and the analyzer, rather than running # them against each Dart version. diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 6d7325de8..7156808b9 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -11,4 +11,4 @@ dependencies: meta: '>=0.9.0 <2.0.0' dev_dependencies: - test: '^0.12.28' + test: ^1.0.0 From 25ebb7e9a1c6ac1b0b81dc9dc6ddcb1895472969 Mon Sep 17 00:00:00 2001 From: Will Stubbs Date: Wed, 24 Apr 2019 14:56:55 -0700 Subject: [PATCH 39/89] Minor README tidy for Dart 2. (dart-lang/clock#10) - Remove new - use single quotes --- pkgs/clock/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/clock/README.md b/pkgs/clock/README.md index 68bdba1ff..fd4a131bf 100644 --- a/pkgs/clock/README.md +++ b/pkgs/clock/README.md @@ -17,7 +17,7 @@ import 'package:clock/clock.dart'; T runWithTiming(T callback()) { var stopwatch = clock.stopwatch()..start(); var result = callback(); - print("It took ${stopwatch.elapsed}!"); + print('It took ${stopwatch.elapsed}!'); return result; } ``` @@ -35,13 +35,13 @@ import 'package:fake_async/fake_async.dart'; import 'package:test/test.dart'; void main() { - test("runWithTiming() prints the elapsed time", () { - new FakeAsync().run((async) { + test('runWithTiming() prints the elapsed time', () { + FakeAsync().run((async) { expect(() { runWithTiming(() { - async.elapse(new Duration(seconds: 10)); + async.elapse(Duration(seconds: 10)); }); - }, prints("It took 0:00:10.000000!")); + }, prints('It took 0:00:10.000000!')); }); }); } From 396a9868d66067a7c353323d8fa58fa70de04039 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 24 Apr 2019 15:03:38 -0700 Subject: [PATCH 40/89] Small tweaks to SDK constraint and travis (dart-lang/clock#11) --- pkgs/clock/.travis.yml | 10 +--------- pkgs/clock/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index 468491aad..963abdd61 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -1,20 +1,12 @@ language: dart -# By default, builds are run in containers. -# https://docs.travis-ci.com/user/getting-started/#Selecting-infrastructure-(optional) -# Set `sudo: true` to disable containers if you need to use sudo in your scripts. -# sudo: true - dart: - dev -- stable +- 2.0.0 -# See https://docs.travis-ci.com/user/languages/dart/ for details. dart_task: - test -# Only run one instance of the formatter and the analyzer, rather than running -# them against each Dart version. matrix: include: - dart: dev diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 7156808b9..4abae3f0a 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -5,7 +5,7 @@ author: Dart Team homepage: https://github.com/dart-lang/clock environment: - sdk: '>=2.0.0-dev.36.0 <3.0.0' + sdk: '>=2.0.0 <3.0.0' dependencies: meta: '>=0.9.0 <2.0.0' From 6ea0a4c3b42139b4b0a831d7f109e132386e19d9 Mon Sep 17 00:00:00 2001 From: Keerti Parthasarathy Date: Wed, 9 Oct 2019 10:07:00 -0700 Subject: [PATCH 41/89] Update package to pedantic 1.8.0 (dart-lang/clock#12) * Update package to pedantic 1.8.0 * Update travis to use stable, update SDK constraints * format files * Travis: test with 2.1.1 --- pkgs/clock/.travis.yml | 2 +- pkgs/clock/analysis_options.yaml | 93 +++++++++++++++++++++++++++++ pkgs/clock/lib/clock.dart | 8 +-- pkgs/clock/lib/src/clock.dart | 49 +++++++-------- pkgs/clock/lib/src/default.dart | 16 ++--- pkgs/clock/lib/src/stopwatch.dart | 4 +- pkgs/clock/lib/src/utils.dart | 6 +- pkgs/clock/pubspec.yaml | 3 +- pkgs/clock/test/clock_test.dart | 38 ++++++------ pkgs/clock/test/default_test.dart | 16 ++--- pkgs/clock/test/stopwatch_test.dart | 14 +++-- pkgs/clock/test/utils.dart | 4 +- 12 files changed, 175 insertions(+), 78 deletions(-) create mode 100644 pkgs/clock/analysis_options.yaml diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index 963abdd61..412ec44bf 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -2,7 +2,7 @@ language: dart dart: - dev -- 2.0.0 +- 2.1.1 dart_task: - test diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml new file mode 100644 index 000000000..168ac1543 --- /dev/null +++ b/pkgs/clock/analysis_options.yaml @@ -0,0 +1,93 @@ +include: package:pedantic/analysis_options.yaml +analyzer: + strong-mode: + implicit-casts: false +linter: + rules: + - always_declare_return_types + #- annotate_overrides + - avoid_bool_literals_in_conditional_expressions + - avoid_classes_with_only_static_members + - avoid_empty_else + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_null_checks_in_equality_operators + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - avoid_returning_null + - avoid_returning_null_for_future + - avoid_returning_null_for_void + - avoid_returning_this + - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements + - avoid_types_as_parameter_names + - avoid_unused_constructor_parameters + - await_only_futures + - camel_case_types + - cancel_subscriptions + - cascade_invocations + - comment_references + - constant_identifier_names + - control_flow_in_finally + - directives_ordering + - empty_catches + - empty_constructor_bodies + - empty_statements + - file_names + - hash_and_equals + - implementation_imports + - invariant_booleans + - iterable_contains_unrelated_type + - join_return_with_assignment + - library_names + - library_prefixes + - list_remove_unrelated_type + - literal_only_boolean_expressions + - no_adjacent_strings_in_list + - no_duplicate_case_values + - non_constant_identifier_names + - null_closures + - omit_local_variable_types + - only_throw_errors + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - prefer_adjacent_string_concatenation + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_contains + - prefer_equal_for_default_values + - prefer_final_fields + #- prefer_final_locals + - prefer_generic_function_type_aliases + - prefer_initializing_formals + - prefer_interpolation_to_compose_strings + - prefer_is_empty + - prefer_is_not_empty + - prefer_null_aware_operators + #- prefer_single_quotes + - prefer_typing_uninitialized_variables + - recursive_getters + - slash_for_doc_comments + - test_types_in_equals + - throw_in_finally + - type_init_formals + - unawaited_futures + - unnecessary_await_in_return + - unnecessary_brace_in_string_interps + - unnecessary_const + - unnecessary_getters_setters + - unnecessary_lambdas + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_parenthesis + - unnecessary_statements + - unnecessary_this + - unrelated_type_equality_checks + - use_function_type_syntax_for_parameters + - use_rethrow_when_possible + - valid_regexps + - void_checks diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index f7bf0b726..9836b3950 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -12,18 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'src/default.dart'; + export 'src/clock.dart'; export 'src/default.dart'; -import 'src/default.dart'; - /// Returns current time. @Deprecated("Pass around an instance of Clock instead.") -typedef DateTime TimeFunction(); +typedef TimeFunction = DateTime Function(); /// Returns the current system time. @Deprecated("Use new DateTime.now() instead.") -DateTime systemTime() => new DateTime.now(); +DateTime systemTime() => DateTime.now(); /// Returns the current time as reported by [clock]. @Deprecated("Use clock.now() instead.") diff --git a/pkgs/clock/lib/src/clock.dart b/pkgs/clock/lib/src/clock.dart index 2984e3010..088f7017b 100644 --- a/pkgs/clock/lib/src/clock.dart +++ b/pkgs/clock/lib/src/clock.dart @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'utils.dart'; - import '../clock.dart'; import 'stopwatch.dart'; +import 'utils.dart'; /// A provider for the "current time" and points relative to the current time. /// @@ -34,7 +33,9 @@ class Clock { /// Creates a clock based on the given [currentTime], or on the system clock /// by default. - const Clock([DateTime currentTime() = systemTime]) : _time = currentTime; + // ignore: deprecated_member_use_from_same_package + const Clock([DateTime Function() currentTime = systemTime]) + : _time = currentTime; /// Creates [Clock] that always considers the current time to be [time]. Clock.fixed(DateTime time) : _time = (() => time); @@ -52,13 +53,13 @@ class Clock { /// /// The amount of time is the sum of the individual parts. DateTime ago( - {int days: 0, - int hours: 0, - int minutes: 0, - int seconds: 0, - int milliseconds: 0, - int microseconds: 0}) => - agoBy(new Duration( + {int days = 0, + int hours = 0, + int minutes = 0, + int seconds = 0, + int milliseconds = 0, + int microseconds = 0}) => + agoBy(Duration( days: days, hours: hours, minutes: minutes, @@ -70,13 +71,13 @@ class Clock { /// /// The amount of time is the sum of the individual parts. DateTime fromNow( - {int days: 0, - int hours: 0, - int minutes: 0, - int seconds: 0, - int milliseconds: 0, - int microseconds: 0}) => - fromNowBy(new Duration( + {int days = 0, + int hours = 0, + int minutes = 0, + int seconds = 0, + int milliseconds = 0, + int microseconds = 0}) => + fromNowBy(Duration( days: days, hours: hours, minutes: minutes, @@ -137,7 +138,7 @@ class Clock { var month = (time.month - months - 1) % 12 + 1; var year = time.year - (months + 12 - time.month) ~/ 12; var day = clampDayOfMonth(year: year, month: month, day: time.day); - return new DateTime(year, month, day, time.hour, time.minute, time.second, + return DateTime(year, month, day, time.hour, time.minute, time.second, time.millisecond); } @@ -150,7 +151,7 @@ class Clock { var month = (time.month + months - 1) % 12 + 1; var year = time.year + (months + time.month - 1) ~/ 12; var day = clampDayOfMonth(year: year, month: month, day: time.day); - return new DateTime(year, month, day, time.hour, time.minute, time.second, + return DateTime(year, month, day, time.hour, time.minute, time.second, time.millisecond); } @@ -162,8 +163,8 @@ class Clock { var time = now(); var year = time.year - years; var day = clampDayOfMonth(year: year, month: time.month, day: time.day); - return new DateTime(year, time.month, day, time.hour, time.minute, - time.second, time.millisecond); + return DateTime(year, time.month, day, time.hour, time.minute, time.second, + time.millisecond); } /// Return the point in time [years] from now on the same date. @@ -172,10 +173,10 @@ class Clock { /// valid day in the original month will be used. DateTime yearsFromNow(int years) => yearsAgo(-years); - /// Returns a new stopwatch that uses the current time as reported by [this]. - Stopwatch stopwatch() => new ClockStopwatch(this); + /// Returns a new stopwatch that uses the current time as reported by `this`. + Stopwatch stopwatch() => ClockStopwatch(this); - /// Returns a new stopwatch that uses the current time as reported by [this]. + /// Returns a new stopwatch that uses the current time as reported by `this`. @Deprecated("Use stopwatch() instead.") Stopwatch getStopwatch() => stopwatch(); } diff --git a/pkgs/clock/lib/src/default.dart b/pkgs/clock/lib/src/default.dart index b380927ae..7cb47b29f 100644 --- a/pkgs/clock/lib/src/default.dart +++ b/pkgs/clock/lib/src/default.dart @@ -18,29 +18,31 @@ import 'clock.dart'; /// The key for the [Zone] value that controls the current implementation of /// [clock]. -final _clockKey = new Object(); +final _clockKey = Object(); /// The key for the [Zone] value that controls whether nested zones can override /// [clock]. -final _isFinalKey = new Object(); +final _isFinalKey = Object(); /// The default implementation of [clock] for the current [Zone]. /// /// This defaults to the system clock. It can be set within a zone using /// [withClock]. -Clock get clock => Zone.current[_clockKey] ?? const Clock(); +Clock get clock => Zone.current[_clockKey] as Clock ?? const Clock(); /// Runs [callback] with the given value for the top-level [clock] field. /// /// This is [Zone]-scoped, so asynchronous callbacks spawned within [callback] /// will also use the new value for [clock]. /// +// ignore: deprecated_member_use_from_same_package /// If [isFinal] is `true`, calls to [withClock] within [callback] will throw a /// [StateError]. However, this parameter is deprecated and should be avoided. -T withClock(Clock clock, T callback(), {@deprecated bool isFinal: false}) { - if (Zone.current[_isFinalKey] ?? false) { - throw new StateError( - "Cannot call withClock() within a call to withClock(isFinal: true)."); +T withClock(Clock clock, T Function() callback, + {@deprecated bool isFinal = false}) { + if ((Zone.current[_isFinalKey] ?? false) == true) { + throw StateError( + "Cannot call withClock() within a call to withClock(isFinal = true)."); } return runZoned(callback, diff --git a/pkgs/clock/lib/src/stopwatch.dart b/pkgs/clock/lib/src/stopwatch.dart index 1cf66a45c..625a5d9aa 100644 --- a/pkgs/clock/lib/src/stopwatch.dart +++ b/pkgs/clock/lib/src/stopwatch.dart @@ -19,7 +19,7 @@ import 'clock.dart'; /// We can't really know how frequently the clock is updated, and that may not /// even make sense for some implementations, so we just pretend we follow the /// system's frequency. -final _frequency = new Stopwatch().frequency; +final _frequency = Stopwatch().frequency; /// A stopwatch that gets its notion of the current time from a [Clock]. class ClockStopwatch implements Stopwatch { @@ -40,7 +40,7 @@ class ClockStopwatch implements Stopwatch { int get frequency => _frequency; int get elapsedTicks => (elapsedMicroseconds * frequency) ~/ 1000000; - Duration get elapsed => new Duration(microseconds: elapsedMicroseconds); + Duration get elapsed => Duration(microseconds: elapsedMicroseconds); int get elapsedMilliseconds => elapsedMicroseconds ~/ 1000; bool get isRunning => _start != null; diff --git a/pkgs/clock/lib/src/utils.dart b/pkgs/clock/lib/src/utils.dart index c1223cf98..843be0bb5 100644 --- a/pkgs/clock/lib/src/utils.dart +++ b/pkgs/clock/lib/src/utils.dart @@ -22,7 +22,7 @@ import 'package:meta/meta.dart'; /// /// This array uses 1-based month numbers, i.e. January is the 1-st element in /// the array, not the 0-th. -const _daysInMonth = const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; +const _daysInMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; /// Returns the number of days in the specified month. /// @@ -42,7 +42,7 @@ int daysInMonth(int year, int month) => bool isLeapYear(int year) => year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); -/// Takes a [date] that may be outside the allowed range of dates for a given +/// Takes a `date` that may be outside the allowed range of dates for a given /// [month] in a given [year] and returns the closest date that is within the /// allowed range. /// @@ -58,4 +58,4 @@ bool isLeapYear(int year) => /// doesn't have 31-st date. int clampDayOfMonth( {@required int year, @required int month, @required int day}) => - day.clamp(1, daysInMonth(year, month)); + day.clamp(1, daysInMonth(year, month)) as int; diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 4abae3f0a..f67cc71f7 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -5,10 +5,11 @@ author: Dart Team homepage: https://github.com/dart-lang/clock environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.1.1 <3.0.0' dependencies: meta: '>=0.9.0 <2.0.0' dev_dependencies: test: ^1.0.0 + pedantic: ^1.8.0 diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 3d2d1b259..b92b53187 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -18,10 +18,10 @@ import 'package:test/test.dart'; import 'utils.dart'; -main() { +void main() { Clock clock; setUp(() { - clock = new Clock.fixed(date(2013)); + clock = Clock.fixed(date(2013)); }); test('should return a non-null value from system clock', () { @@ -33,17 +33,15 @@ main() { test('should be close enough to system clock', () { // At 10ms the test doesn't seem to be flaky. var epsilon = 10; - expect( - new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(), + expect(DateTime.now().difference(const Clock().now()).inMilliseconds.abs(), lessThan(epsilon)); - expect( - new DateTime.now().difference(const Clock().now()).inMilliseconds.abs(), + expect(DateTime.now().difference(const Clock().now()).inMilliseconds.abs(), lessThan(epsilon)); }); test('should return time provided by a custom function', () { var time = date(2013); - var fixedClock = new Clock(() => time); + var fixedClock = Clock(() => time); expect(fixedClock.now(), date(2013)); time = date(2014); @@ -51,7 +49,7 @@ main() { }); test('should return fixed time', () { - expect(new Clock.fixed(date(2013)).now(), date(2013)); + expect(Clock.fixed(date(2013)).now(), date(2013)); }); test('should return time Duration ago', () { @@ -71,7 +69,7 @@ main() { seconds: 1, milliseconds: 1, microseconds: 1000), - new DateTime(2012, 12, 30, 22, 58, 58, 998)); + DateTime(2012, 12, 30, 22, 58, 58, 998)); }); test('should return time parts from now', () { @@ -83,47 +81,47 @@ main() { seconds: 1, milliseconds: 1, microseconds: 1000), - new DateTime(2013, 1, 2, 1, 1, 1, 2)); + DateTime(2013, 1, 2, 1, 1, 1, 2)); }); test('should return time micros ago', () { - expect(clock.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999)); + expect(clock.microsAgo(1000), DateTime(2012, 12, 31, 23, 59, 59, 999)); }); test('should return time micros from now', () { - expect(clock.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1)); + expect(clock.microsFromNow(1000), DateTime(2013, 1, 1, 0, 0, 0, 1)); }); test('should return time millis ago', () { - expect(clock.millisAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 000)); + expect(clock.millisAgo(1000), DateTime(2012, 12, 31, 23, 59, 59, 000)); }); test('should return time millis from now', () { - expect(clock.millisFromNow(3), new DateTime(2013, 1, 1, 0, 0, 0, 3)); + expect(clock.millisFromNow(3), DateTime(2013, 1, 1, 0, 0, 0, 3)); }); test('should return time seconds ago', () { - expect(clock.secondsAgo(10), new DateTime(2012, 12, 31, 23, 59, 50, 000)); + expect(clock.secondsAgo(10), DateTime(2012, 12, 31, 23, 59, 50, 000)); }); test('should return time seconds from now', () { - expect(clock.secondsFromNow(3), new DateTime(2013, 1, 1, 0, 0, 3, 0)); + expect(clock.secondsFromNow(3), DateTime(2013, 1, 1, 0, 0, 3, 0)); }); test('should return time minutes ago', () { - expect(clock.minutesAgo(10), new DateTime(2012, 12, 31, 23, 50, 0, 000)); + expect(clock.minutesAgo(10), DateTime(2012, 12, 31, 23, 50, 0, 000)); }); test('should return time minutes from now', () { - expect(clock.minutesFromNow(3), new DateTime(2013, 1, 1, 0, 3, 0, 0)); + expect(clock.minutesFromNow(3), DateTime(2013, 1, 1, 0, 3, 0, 0)); }); test('should return time hours ago', () { - expect(clock.hoursAgo(10), new DateTime(2012, 12, 31, 14, 0, 0, 000)); + expect(clock.hoursAgo(10), DateTime(2012, 12, 31, 14, 0, 0, 000)); }); test('should return time hours from now', () { - expect(clock.hoursFromNow(3), new DateTime(2013, 1, 1, 3, 0, 0, 0)); + expect(clock.hoursFromNow(3), DateTime(2013, 1, 1, 3, 0, 0, 0)); }); test('should return time days ago', () { diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart index d75e8da2c..6cbd08536 100644 --- a/pkgs/clock/test/default_test.dart +++ b/pkgs/clock/test/default_test.dart @@ -22,7 +22,7 @@ import 'utils.dart'; void main() { test("the default clock returns the system time", () { - expect(new DateTime.now().difference(clock.now()).inMilliseconds.abs(), + expect(DateTime.now().difference(clock.now()).inMilliseconds.abs(), lessThan(100)); }); @@ -30,7 +30,7 @@ void main() { group("overrides the clock", () { test("synchronously", () { var time = date(1990, 11, 8); - withClock(new Clock(() => time), () { + withClock(Clock(() => time), () { expect(clock.now(), equals(time)); time = date(2016, 6, 26); expect(clock.now(), equals(time)); @@ -39,8 +39,8 @@ void main() { test("asynchronously", () { var time = date(1990, 11, 8); - withClock(new Clock.fixed(time), () { - expect(new Future(() async { + withClock(Clock.fixed(time), () { + expect(Future(() async { expect(clock.now(), equals(time)); }), completes); }); @@ -48,13 +48,13 @@ void main() { test("within another withClock() call", () { var outerTime = date(1990, 11, 8); - withClock(new Clock.fixed(outerTime), () { + withClock(Clock.fixed(outerTime), () { expect(clock.now(), equals(outerTime)); var innerTime = date(2016, 11, 8); - withClock(new Clock.fixed(innerTime), () { + withClock(Clock.fixed(innerTime), () { expect(clock.now(), equals(innerTime)); - expect(new Future(() async { + expect(Future(() async { expect(clock.now(), equals(innerTime)); }), completes); }); @@ -66,7 +66,7 @@ void main() { test("with isFinal: true doesn't allow nested calls", () { var outerTime = date(1990, 11, 8); - withClock(new Clock.fixed(outerTime), () { + withClock(Clock.fixed(outerTime), () { expect(clock.now(), equals(outerTime)); expect(() => withClock(fixed(2016, 11, 8), neverCalledVoid), diff --git a/pkgs/clock/test/stopwatch_test.dart b/pkgs/clock/test/stopwatch_test.dart index 151d2dc95..66d119459 100644 --- a/pkgs/clock/test/stopwatch_test.dart +++ b/pkgs/clock/test/stopwatch_test.dart @@ -21,7 +21,7 @@ import 'utils.dart'; void main() { test("returns the system frequency", () { expect(fixed(1990, 11, 8).stopwatch().frequency, - equals(new Stopwatch().frequency)); + equals(Stopwatch().frequency)); }); group("before it starts", () { @@ -52,7 +52,7 @@ void main() { Stopwatch stopwatch; setUp(() { time = date(1990, 11, 8); - clock = new Clock(() => time); + clock = Clock(() => time); stopwatch = clock.stopwatch()..start(); time = clock.microsFromNow(12345); }); @@ -90,12 +90,13 @@ void main() { group("reports elapsed", () { test("duration", () { - expect(stopwatch.elapsed, equals(new Duration(microseconds: 12345))); + expect( + stopwatch.elapsed, equals(const Duration(microseconds: 12345))); }); test("ticks", () { expect(stopwatch.elapsedTicks, - equals((new Stopwatch().frequency * 12345) ~/ 1000000)); + equals((Stopwatch().frequency * 12345) ~/ 1000000)); }); test("microseconds", () { @@ -146,12 +147,13 @@ void main() { group("reports elapsed", () { test("duration", () { - expect(stopwatch.elapsed, equals(new Duration(microseconds: 12345))); + expect( + stopwatch.elapsed, equals(const Duration(microseconds: 12345))); }); test("ticks", () { expect(stopwatch.elapsedTicks, - equals((new Stopwatch().frequency * 12345) ~/ 1000000)); + equals((Stopwatch().frequency * 12345) ~/ 1000000)); }); test("microseconds", () { diff --git a/pkgs/clock/test/utils.dart b/pkgs/clock/test/utils.dart index 17c07f34a..3fd1372ca 100644 --- a/pkgs/clock/test/utils.dart +++ b/pkgs/clock/test/utils.dart @@ -17,9 +17,9 @@ import 'package:clock/clock.dart'; /// A utility function for tersely constructing a [DateTime] with no time /// component. DateTime date(int year, [int month, int day]) => - new DateTime(year, month ?? 1, day ?? 1); + DateTime(year, month ?? 1, day ?? 1); /// Returns a clock that always returns a date with the given [year], [month], /// and [day]. Clock fixed(int year, [int month, int day]) => - new Clock.fixed(date(year, month, day)); + Clock.fixed(date(year, month, day)); From e93b5139c08fcddff52dff3083cb527dc5627569 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 12 Dec 2019 13:56:18 -0800 Subject: [PATCH 42/89] Fix newly enforced package:pedantic lints (dart-lang/clock#13) - annotate_overrides - prefer_single_quotes --- pkgs/clock/lib/clock.dart | 8 ++-- pkgs/clock/lib/src/clock.dart | 2 +- pkgs/clock/lib/src/default.dart | 2 +- pkgs/clock/lib/src/stopwatch.dart | 9 ++++ pkgs/clock/pubspec.yaml | 2 +- pkgs/clock/test/default_test.dart | 12 +++--- pkgs/clock/test/stopwatch_test.dart | 64 ++++++++++++++--------------- 7 files changed, 54 insertions(+), 45 deletions(-) diff --git a/pkgs/clock/lib/clock.dart b/pkgs/clock/lib/clock.dart index 9836b3950..755789e77 100644 --- a/pkgs/clock/lib/clock.dart +++ b/pkgs/clock/lib/clock.dart @@ -18,17 +18,17 @@ export 'src/clock.dart'; export 'src/default.dart'; /// Returns current time. -@Deprecated("Pass around an instance of Clock instead.") +@Deprecated('Pass around an instance of Clock instead.') typedef TimeFunction = DateTime Function(); /// Returns the current system time. -@Deprecated("Use new DateTime.now() instead.") +@Deprecated('Use new DateTime.now() instead.') DateTime systemTime() => DateTime.now(); /// Returns the current time as reported by [clock]. -@Deprecated("Use clock.now() instead.") +@Deprecated('Use clock.now() instead.') DateTime get now => clock.now(); /// Returns a stopwatch that uses the current time as reported by [clock]. -@Deprecated("Use clock.stopwatch() instead.") +@Deprecated('Use clock.stopwatch() instead.') Stopwatch getStopwatch() => clock.stopwatch(); diff --git a/pkgs/clock/lib/src/clock.dart b/pkgs/clock/lib/src/clock.dart index 088f7017b..6079fb304 100644 --- a/pkgs/clock/lib/src/clock.dart +++ b/pkgs/clock/lib/src/clock.dart @@ -177,6 +177,6 @@ class Clock { Stopwatch stopwatch() => ClockStopwatch(this); /// Returns a new stopwatch that uses the current time as reported by `this`. - @Deprecated("Use stopwatch() instead.") + @Deprecated('Use stopwatch() instead.') Stopwatch getStopwatch() => stopwatch(); } diff --git a/pkgs/clock/lib/src/default.dart b/pkgs/clock/lib/src/default.dart index 7cb47b29f..57dac6f33 100644 --- a/pkgs/clock/lib/src/default.dart +++ b/pkgs/clock/lib/src/default.dart @@ -42,7 +42,7 @@ T withClock(Clock clock, T Function() callback, {@deprecated bool isFinal = false}) { if ((Zone.current[_isFinalKey] ?? false) == true) { throw StateError( - "Cannot call withClock() within a call to withClock(isFinal = true)."); + 'Cannot call withClock() within a call to withClock(isFinal = true).'); } return runZoned(callback, diff --git a/pkgs/clock/lib/src/stopwatch.dart b/pkgs/clock/lib/src/stopwatch.dart index 625a5d9aa..9a14645c5 100644 --- a/pkgs/clock/lib/src/stopwatch.dart +++ b/pkgs/clock/lib/src/stopwatch.dart @@ -38,25 +38,34 @@ class ClockStopwatch implements Stopwatch { ClockStopwatch(this._clock); + @override int get frequency => _frequency; + @override int get elapsedTicks => (elapsedMicroseconds * frequency) ~/ 1000000; + @override Duration get elapsed => Duration(microseconds: elapsedMicroseconds); + @override int get elapsedMilliseconds => elapsedMicroseconds ~/ 1000; + @override bool get isRunning => _start != null; + @override int get elapsedMicroseconds => _elapsed + (_start == null ? 0 : _clock.now().difference(_start).inMicroseconds); + @override void start() { _start ??= _clock.now(); } + @override void stop() { _elapsed = elapsedMicroseconds; _start = null; } + @override void reset() { _elapsed = 0; if (_start != null) _start = _clock.now(); diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index f67cc71f7..275e43d27 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,5 +1,5 @@ name: clock -version: 1.0.1 +version: 1.0.2-dev description: A fakeable wrapper for dart:core clock APIs author: Dart Team homepage: https://github.com/dart-lang/clock diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart index 6cbd08536..bc56e48cf 100644 --- a/pkgs/clock/test/default_test.dart +++ b/pkgs/clock/test/default_test.dart @@ -21,14 +21,14 @@ import 'package:test/test.dart'; import 'utils.dart'; void main() { - test("the default clock returns the system time", () { + test('the default clock returns the system time', () { expect(DateTime.now().difference(clock.now()).inMilliseconds.abs(), lessThan(100)); }); - group("withClock()", () { - group("overrides the clock", () { - test("synchronously", () { + group('withClock()', () { + group('overrides the clock', () { + test('synchronously', () { var time = date(1990, 11, 8); withClock(Clock(() => time), () { expect(clock.now(), equals(time)); @@ -37,7 +37,7 @@ void main() { }); }); - test("asynchronously", () { + test('asynchronously', () { var time = date(1990, 11, 8); withClock(Clock.fixed(time), () { expect(Future(() async { @@ -46,7 +46,7 @@ void main() { }); }); - test("within another withClock() call", () { + test('within another withClock() call', () { var outerTime = date(1990, 11, 8); withClock(Clock.fixed(outerTime), () { expect(clock.now(), equals(outerTime)); diff --git a/pkgs/clock/test/stopwatch_test.dart b/pkgs/clock/test/stopwatch_test.dart index 66d119459..16720f1ab 100644 --- a/pkgs/clock/test/stopwatch_test.dart +++ b/pkgs/clock/test/stopwatch_test.dart @@ -19,34 +19,34 @@ import 'package:test/test.dart'; import 'utils.dart'; void main() { - test("returns the system frequency", () { + test('returns the system frequency', () { expect(fixed(1990, 11, 8).stopwatch().frequency, equals(Stopwatch().frequency)); }); - group("before it starts", () { + group('before it starts', () { Stopwatch stopwatch; setUp(() { stopwatch = clock.stopwatch(); }); - test("is not running", () => expect(stopwatch.isRunning, isFalse)); + test('is not running', () => expect(stopwatch.isRunning, isFalse)); - test("stop() does nothing", () { + test('stop() does nothing', () { stopwatch.stop(); expect(stopwatch.isRunning, isFalse); expect(stopwatch.elapsed, equals(Duration.zero)); }); - group("reports no elapsed", () { - test("duration", () => expect(stopwatch.elapsed, equals(Duration.zero))); - test("ticks", () => expect(stopwatch.elapsedTicks, isZero)); - test("microseconds", () => expect(stopwatch.elapsedMicroseconds, isZero)); - test("milliseconds", () => expect(stopwatch.elapsedMilliseconds, isZero)); + group('reports no elapsed', () { + test('duration', () => expect(stopwatch.elapsed, equals(Duration.zero))); + test('ticks', () => expect(stopwatch.elapsedTicks, isZero)); + test('microseconds', () => expect(stopwatch.elapsedMicroseconds, isZero)); + test('milliseconds', () => expect(stopwatch.elapsedMilliseconds, isZero)); }); }); - group("when 12345μs have elapsed", () { + group('when 12345μs have elapsed', () { DateTime time; Clock clock; Stopwatch stopwatch; @@ -57,64 +57,64 @@ void main() { time = clock.microsFromNow(12345); }); - group("and the stopwatch is active", () { - test("is running", () { + group('and the stopwatch is active', () { + test('is running', () { expect(stopwatch.isRunning, isTrue); }); - test("reports more elapsed time", () { + test('reports more elapsed time', () { time = clock.microsFromNow(54321); expect(stopwatch.elapsedMicroseconds, equals(66666)); }); - test("start does nothing", () { + test('start does nothing', () { stopwatch.start(); expect(stopwatch.isRunning, isTrue); expect(stopwatch.elapsedMicroseconds, equals(12345)); }); - group("reset()", () { + group('reset()', () { setUp(() { stopwatch.reset(); }); - test("sets the elapsed time to zero", () { + test('sets the elapsed time to zero', () { expect(stopwatch.elapsed, equals(Duration.zero)); }); - test("reports more elapsed time", () { + test('reports more elapsed time', () { time = clock.microsFromNow(54321); expect(stopwatch.elapsedMicroseconds, equals(54321)); }); }); - group("reports elapsed", () { - test("duration", () { + group('reports elapsed', () { + test('duration', () { expect( stopwatch.elapsed, equals(const Duration(microseconds: 12345))); }); - test("ticks", () { + test('ticks', () { expect(stopwatch.elapsedTicks, equals((Stopwatch().frequency * 12345) ~/ 1000000)); }); - test("microseconds", () { + test('microseconds', () { expect(stopwatch.elapsedMicroseconds, equals(12345)); }); - test("milliseconds", () { + test('milliseconds', () { expect(stopwatch.elapsedMilliseconds, equals(12)); }); }); }); - group("and the stopwatch is inactive, reports that as", () { + group('and the stopwatch is inactive, reports that as', () { setUp(() { stopwatch.stop(); }); - test("is not running", () { + test('is not running', () { expect(stopwatch.isRunning, isFalse); }); @@ -123,19 +123,19 @@ void main() { expect(stopwatch.elapsedMicroseconds, equals(12345)); }); - test("start starts reporting more elapsed time", () { + test('start starts reporting more elapsed time', () { stopwatch.start(); expect(stopwatch.isRunning, isTrue); time = clock.microsFromNow(54321); expect(stopwatch.elapsedMicroseconds, equals(66666)); }); - group("reset()", () { + group('reset()', () { setUp(() { stopwatch.reset(); }); - test("sets the elapsed time to zero", () { + test('sets the elapsed time to zero', () { expect(stopwatch.elapsed, equals(Duration.zero)); }); @@ -145,22 +145,22 @@ void main() { }); }); - group("reports elapsed", () { - test("duration", () { + group('reports elapsed', () { + test('duration', () { expect( stopwatch.elapsed, equals(const Duration(microseconds: 12345))); }); - test("ticks", () { + test('ticks', () { expect(stopwatch.elapsedTicks, equals((Stopwatch().frequency * 12345) ~/ 1000000)); }); - test("microseconds", () { + test('microseconds', () { expect(stopwatch.elapsedMicroseconds, equals(12345)); }); - test("milliseconds", () { + test('milliseconds', () { expect(stopwatch.elapsedMilliseconds, equals(12)); }); }); From 62940b22b114893daedef18575e6f964d3cb6089 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 12 Dec 2019 16:19:31 -0800 Subject: [PATCH 43/89] Update for repo best practices (dart-lang/clock#14) - Use `pub.dev` links over `dardocs.org`. - In example, follow `package:pedantic` style for function typed argument. - Drop unused author field from pubspec. - Use a simpler constraint on `package:meta` since the SDK constraint already prevents us from picking up older versions. --- pkgs/clock/.travis.yml | 10 +++++++--- pkgs/clock/README.md | 6 +++--- pkgs/clock/pubspec.yaml | 3 +-- pkgs/clock/test/stopwatch_test.dart | 2 ++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index 412ec44bf..50f4a33c6 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -5,14 +5,18 @@ dart: - 2.1.1 dart_task: - - test + - test: -p vm,chrome matrix: include: - - dart: dev - dart_task: dartanalyzer - dart: dev dart_task: dartfmt + - dart: dev + dart_task: + dartanalyzer: --fatal-lints --fatal-warnings . + - dart: 2.1.1 + dart_task: + dartanalyzer: --fatal-warnings . # Only building master means that we don't run two builds for each pull request. branches: diff --git a/pkgs/clock/README.md b/pkgs/clock/README.md index fd4a131bf..b847f763b 100644 --- a/pkgs/clock/README.md +++ b/pkgs/clock/README.md @@ -4,8 +4,8 @@ Different `Clock`s can have a different notion of the current time, and the default top-level [`clock`][]'s notion can be swapped out to reliably test timing-dependent code. -[`Clock`]: https://www.dartdocs.org/documentation/clock/latest/clock/Clock-class.html -[`clock`]: https://www.dartdocs.org/documentation/clock/latest/clock/clock.html +[`Clock`]: https://pub.dev/documentation/clock/latest/clock/Clock-class.html +[`clock`]: https://pub.dev/documentation/clock/latest/clock/clock.html For example, you can use `clock` in your libraries like this: @@ -14,7 +14,7 @@ For example, you can use `clock` in your libraries like this: import 'package:clock/clock.dart'; /// Runs [callback] and prints how long it took. -T runWithTiming(T callback()) { +T runWithTiming(T Function() callback) { var stopwatch = clock.stopwatch()..start(); var result = callback(); print('It took ${stopwatch.elapsed}!'); diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 275e43d27..bfb1e06f6 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,14 +1,13 @@ name: clock version: 1.0.2-dev description: A fakeable wrapper for dart:core clock APIs -author: Dart Team homepage: https://github.com/dart-lang/clock environment: sdk: '>=2.1.1 <3.0.0' dependencies: - meta: '>=0.9.0 <2.0.0' + meta: ^1.0.0 dev_dependencies: test: ^1.0.0 diff --git a/pkgs/clock/test/stopwatch_test.dart b/pkgs/clock/test/stopwatch_test.dart index 16720f1ab..d8e905d79 100644 --- a/pkgs/clock/test/stopwatch_test.dart +++ b/pkgs/clock/test/stopwatch_test.dart @@ -165,5 +165,7 @@ void main() { }); }); }); + }, onPlatform: { + 'js': const Skip('Web does not have enough precision'), }); } From 251826fe85a592ebf9c1c0e0e36e1bdb4cf32697 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Wed, 22 Jul 2020 11:23:27 -0700 Subject: [PATCH 44/89] Merge null safety branch into master (dart-lang/clock#18) --- pkgs/clock/.travis.yml | 17 ++------ pkgs/clock/CHANGELOG.md | 4 ++ pkgs/clock/analysis_options.yaml | 2 + pkgs/clock/lib/src/default.dart | 2 +- pkgs/clock/lib/src/stopwatch.dart | 4 +- pkgs/clock/lib/src/utils.dart | 4 +- pkgs/clock/pubspec.yaml | 64 ++++++++++++++++++++++++++--- pkgs/clock/test/clock_test.dart | 2 +- pkgs/clock/test/stopwatch_test.dart | 8 ++-- pkgs/clock/test/utils.dart | 4 +- 10 files changed, 80 insertions(+), 31 deletions(-) diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index 50f4a33c6..e1bd731d6 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -1,22 +1,13 @@ language: dart dart: -- dev -- 2.1.1 +- preview/raw/2.10.0-0.2-dev dart_task: - test: -p vm,chrome - -matrix: - include: - - dart: dev - dart_task: dartfmt - - dart: dev - dart_task: - dartanalyzer: --fatal-lints --fatal-warnings . - - dart: 2.1.1 - dart_task: - dartanalyzer: --fatal-warnings . + - dartfmt + - dartanalyzer: --fatal-lints --fatal-warnings . + # Only building master means that we don't run two builds for each pull request. branches: diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index d1932bce8..bce195f84 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0-nullsafety + +* Update to null safety. + ## 1.0.1 * Update to lowercase Dart core library constants. diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml index 168ac1543..237e493ea 100644 --- a/pkgs/clock/analysis_options.yaml +++ b/pkgs/clock/analysis_options.yaml @@ -2,6 +2,8 @@ include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false + enable-experiment: + - non-nullable linter: rules: - always_declare_return_types diff --git a/pkgs/clock/lib/src/default.dart b/pkgs/clock/lib/src/default.dart index 57dac6f33..241917029 100644 --- a/pkgs/clock/lib/src/default.dart +++ b/pkgs/clock/lib/src/default.dart @@ -28,7 +28,7 @@ final _isFinalKey = Object(); /// /// This defaults to the system clock. It can be set within a zone using /// [withClock]. -Clock get clock => Zone.current[_clockKey] as Clock ?? const Clock(); +Clock get clock => Zone.current[_clockKey] as Clock? ?? const Clock(); /// Runs [callback] with the given value for the top-level [clock] field. /// diff --git a/pkgs/clock/lib/src/stopwatch.dart b/pkgs/clock/lib/src/stopwatch.dart index 9a14645c5..93fe1abc4 100644 --- a/pkgs/clock/lib/src/stopwatch.dart +++ b/pkgs/clock/lib/src/stopwatch.dart @@ -34,7 +34,7 @@ class ClockStopwatch implements Stopwatch { /// The point at which [start] was called most recently, or `null` if this /// isn't active. - DateTime _start; + DateTime? _start; ClockStopwatch(this._clock); @@ -52,7 +52,7 @@ class ClockStopwatch implements Stopwatch { @override int get elapsedMicroseconds => _elapsed + - (_start == null ? 0 : _clock.now().difference(_start).inMicroseconds); + (_start == null ? 0 : _clock.now().difference(_start!).inMicroseconds); @override void start() { diff --git a/pkgs/clock/lib/src/utils.dart b/pkgs/clock/lib/src/utils.dart index 843be0bb5..e0853dde6 100644 --- a/pkgs/clock/lib/src/utils.dart +++ b/pkgs/clock/lib/src/utils.dart @@ -16,8 +16,6 @@ // because quiver is very large and the amount of code we use from it is very // small. -import 'package:meta/meta.dart'; - /// The number of days in each month. /// /// This array uses 1-based month numbers, i.e. January is the 1-st element in @@ -57,5 +55,5 @@ bool isLeapYear(int year) => /// month back takes us to February 28 (or 29 during a leap year), as February /// doesn't have 31-st date. int clampDayOfMonth( - {@required int year, @required int month, @required int day}) => + {required int year, required int month, required int day}) => day.clamp(1, daysInMonth(year, month)) as int; diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index bfb1e06f6..e6391b318 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,14 +1,68 @@ name: clock -version: 1.0.2-dev +version: 1.1.0-nullsafety description: A fakeable wrapper for dart:core clock APIs homepage: https://github.com/dart-lang/clock environment: - sdk: '>=2.1.1 <3.0.0' - -dependencies: - meta: ^1.0.0 + # This must remain a tight constraint until nnbd is stable + sdk: '>=2.10.0-0 <2.10.0' dev_dependencies: test: ^1.0.0 pedantic: ^1.8.0 + +dependency_overrides: + async: + git: git://github.com/dart-lang/async.git + boolean_selector: + git: git://github.com/dart-lang/boolean_selector.git + charcode: + git: git://github.com/dart-lang/charcode.git + collection: + git: git://github.com/dart-lang/collection.git + js: + git: + url: git://github.com/dart-lang/sdk.git + path: pkg/js + ref: 2-10-pkgs + matcher: + git: git://github.com/dart-lang/matcher.git + meta: + git: + url: git://github.com/dart-lang/sdk.git + path: pkg/meta + ref: 2-10-pkgs + path: + git: git://github.com/dart-lang/path.git + pedantic: + git: git://github.com/dart-lang/pedantic.git + pool: + git: git://github.com/dart-lang/pool.git + source_maps: + git: git://github.com/dart-lang/source_maps.git + source_map_stack_trace: + git: git://github.com/dart-lang/source_map_stack_trace.git + source_span: + git: git://github.com/dart-lang/source_span.git + stack_trace: + git: git://github.com/dart-lang/stack_trace.git + stream_channel: + git: git://github.com/dart-lang/stream_channel.git + string_scanner: + git: git://github.com/dart-lang/string_scanner.git + term_glyph: + git: git://github.com/dart-lang/term_glyph.git + test_api: + git: + url: git://github.com/dart-lang/test.git + path: pkgs/test_api + test_core: + git: + url: git://github.com/dart-lang/test.git + path: pkgs/test_core + test: + git: + url: git://github.com/dart-lang/test.git + path: pkgs/test + typed_data: + git: git://github.com/dart-lang/typed_data.git diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index b92b53187..6c7231c54 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -19,7 +19,7 @@ import 'package:test/test.dart'; import 'utils.dart'; void main() { - Clock clock; + late Clock clock; setUp(() { clock = Clock.fixed(date(2013)); }); diff --git a/pkgs/clock/test/stopwatch_test.dart b/pkgs/clock/test/stopwatch_test.dart index d8e905d79..e96c0f7d0 100644 --- a/pkgs/clock/test/stopwatch_test.dart +++ b/pkgs/clock/test/stopwatch_test.dart @@ -25,7 +25,7 @@ void main() { }); group('before it starts', () { - Stopwatch stopwatch; + late Stopwatch stopwatch; setUp(() { stopwatch = clock.stopwatch(); }); @@ -47,9 +47,9 @@ void main() { }); group('when 12345μs have elapsed', () { - DateTime time; - Clock clock; - Stopwatch stopwatch; + late DateTime time; + late Clock clock; + late Stopwatch stopwatch; setUp(() { time = date(1990, 11, 8); clock = Clock(() => time); diff --git a/pkgs/clock/test/utils.dart b/pkgs/clock/test/utils.dart index 3fd1372ca..ea4b1df68 100644 --- a/pkgs/clock/test/utils.dart +++ b/pkgs/clock/test/utils.dart @@ -16,10 +16,10 @@ import 'package:clock/clock.dart'; /// A utility function for tersely constructing a [DateTime] with no time /// component. -DateTime date(int year, [int month, int day]) => +DateTime date(int year, [int? month, int? day]) => DateTime(year, month ?? 1, day ?? 1); /// Returns a clock that always returns a date with the given [year], [month], /// and [day]. -Clock fixed(int year, [int month, int day]) => +Clock fixed(int year, [int? month, int? day]) => Clock.fixed(date(year, month, day)); From ffa4951a8932a49545c31d14dcf261d8938cb89f Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 23 Jul 2020 07:27:56 -0700 Subject: [PATCH 45/89] CI: Test on dev branch (dart-lang/clock#19) --- pkgs/clock/.travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml index e1bd731d6..19bd41641 100644 --- a/pkgs/clock/.travis.yml +++ b/pkgs/clock/.travis.yml @@ -1,7 +1,7 @@ language: dart dart: -- preview/raw/2.10.0-0.2-dev +- dev dart_task: - test: -p vm,chrome From e0ada7efebd3709d7fc3814c2b4f65443377dc76 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 27 Aug 2020 14:35:52 -0700 Subject: [PATCH 46/89] Remove unnecessary cast from clamp computation. (dart-lang/clock#21) Now that the analyzer correctly computes the type of `int.clamp(int, int)` as `int` (for libraries opted into null safety), we no longer need to cast the result to an `int`. --- pkgs/clock/lib/src/utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/lib/src/utils.dart b/pkgs/clock/lib/src/utils.dart index e0853dde6..4301b099d 100644 --- a/pkgs/clock/lib/src/utils.dart +++ b/pkgs/clock/lib/src/utils.dart @@ -56,4 +56,4 @@ bool isLeapYear(int year) => /// doesn't have 31-st date. int clampDayOfMonth( {required int year, required int month, required int day}) => - day.clamp(1, daysInMonth(year, month)) as int; + day.clamp(1, daysInMonth(year, month)); From fb4964a731650baea61d7f550d06a2ff05b245d7 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Mon, 21 Sep 2020 15:39:25 -0700 Subject: [PATCH 47/89] Remove unused dart:async import --- pkgs/clock/test/default_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart index bc56e48cf..fbf1a29f3 100644 --- a/pkgs/clock/test/default_test.dart +++ b/pkgs/clock/test/default_test.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'dart:async'; - import 'package:clock/clock.dart'; import 'package:test/test.dart'; From ab3a25b1c3b18dafd7acfae7d89d3ee681306f36 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 22 Sep 2020 09:57:46 -0700 Subject: [PATCH 48/89] Prepare for the 2.11 dev SDKs (dart-lang/clock#23) Bump the upper bound to allow 2.10 stable and 2.11.0 dev SDK versions. --- pkgs/clock/CHANGELOG.md | 4 ++++ pkgs/clock/pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index bce195f84..935b5cc85 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0-nullsafety.1 + +* Allow 2.10 stable and 2.11.0 dev SDK versions. + ## 1.1.0-nullsafety * Update to null safety. diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index e6391b318..5904b6737 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,11 +1,11 @@ name: clock -version: 1.1.0-nullsafety +version: 1.1.0-nullsafety.1 description: A fakeable wrapper for dart:core clock APIs homepage: https://github.com/dart-lang/clock environment: # This must remain a tight constraint until nnbd is stable - sdk: '>=2.10.0-0 <2.10.0' + sdk: '>=2.10.0-0 <2.11.0' dev_dependencies: test: ^1.0.0 From 2a4876cd4d1dd24b92ecbb5934e6ea3e5436ffc6 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Fri, 23 Oct 2020 13:26:04 -0700 Subject: [PATCH 49/89] allow the 2.12 prerelease sdks (dart-lang/clock#24) --- pkgs/clock/CHANGELOG.md | 4 +++ pkgs/clock/pubspec.yaml | 64 +++-------------------------------------- 2 files changed, 8 insertions(+), 60 deletions(-) diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 935b5cc85..a5cd2ee9f 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0-nullsafety.2 + +* Allow prerelease versions of the 2.12 sdk. + ## 1.1.0-nullsafety.1 * Allow 2.10 stable and 2.11.0 dev SDK versions. diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 5904b6737..7c1f0d115 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,68 +1,12 @@ name: clock -version: 1.1.0-nullsafety.1 +version: 1.1.0-nullsafety.2 description: A fakeable wrapper for dart:core clock APIs homepage: https://github.com/dart-lang/clock environment: # This must remain a tight constraint until nnbd is stable - sdk: '>=2.10.0-0 <2.11.0' + sdk: '>=2.10.0-0 <2.12.0' dev_dependencies: - test: ^1.0.0 - pedantic: ^1.8.0 - -dependency_overrides: - async: - git: git://github.com/dart-lang/async.git - boolean_selector: - git: git://github.com/dart-lang/boolean_selector.git - charcode: - git: git://github.com/dart-lang/charcode.git - collection: - git: git://github.com/dart-lang/collection.git - js: - git: - url: git://github.com/dart-lang/sdk.git - path: pkg/js - ref: 2-10-pkgs - matcher: - git: git://github.com/dart-lang/matcher.git - meta: - git: - url: git://github.com/dart-lang/sdk.git - path: pkg/meta - ref: 2-10-pkgs - path: - git: git://github.com/dart-lang/path.git - pedantic: - git: git://github.com/dart-lang/pedantic.git - pool: - git: git://github.com/dart-lang/pool.git - source_maps: - git: git://github.com/dart-lang/source_maps.git - source_map_stack_trace: - git: git://github.com/dart-lang/source_map_stack_trace.git - source_span: - git: git://github.com/dart-lang/source_span.git - stack_trace: - git: git://github.com/dart-lang/stack_trace.git - stream_channel: - git: git://github.com/dart-lang/stream_channel.git - string_scanner: - git: git://github.com/dart-lang/string_scanner.git - term_glyph: - git: git://github.com/dart-lang/term_glyph.git - test_api: - git: - url: git://github.com/dart-lang/test.git - path: pkgs/test_api - test_core: - git: - url: git://github.com/dart-lang/test.git - path: pkgs/test_core - test: - git: - url: git://github.com/dart-lang/test.git - path: pkgs/test - typed_data: - git: git://github.com/dart-lang/typed_data.git + test: ^1.16.0-nullsafety + pedantic: ^1.10.0-nullsafety From 69b1008fd74bdf5ab1bfe4070cec85cebf54e59f Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 3 Nov 2020 14:40:29 -0800 Subject: [PATCH 50/89] Bump SDK constraints for pub (dart-lang/clock#25) Use a 2.12.0 lower bound since pub does not understand allowed experiments for earlier versions. Use a 3.0.0 upper bound to avoid a warning in pub and to give some flexibility in publishing for stable. --- pkgs/clock/CHANGELOG.md | 5 +++++ pkgs/clock/pubspec.yaml | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index a5cd2ee9f..2b2fa6f86 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.0-nullsafety.3 + +* Update SDK constraints to `>=2.12.0-0 <3.0.0` based on beta release + guidelines. + ## 1.1.0-nullsafety.2 * Allow prerelease versions of the 2.12 sdk. diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 7c1f0d115..bace9896a 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,11 +1,10 @@ name: clock -version: 1.1.0-nullsafety.2 +version: 1.1.0-nullsafety.3 description: A fakeable wrapper for dart:core clock APIs homepage: https://github.com/dart-lang/clock environment: - # This must remain a tight constraint until nnbd is stable - sdk: '>=2.10.0-0 <2.12.0' + sdk: ">=2.12.0-0 <3.0.0" dev_dependencies: test: ^1.16.0-nullsafety From c86cc730bccc4e931ec0b4c7dcd8623ac2a11a69 Mon Sep 17 00:00:00 2001 From: Phil Quitslund Date: Wed, 11 Nov 2020 08:25:26 -0800 Subject: [PATCH 51/89] remove redundant experiment --- pkgs/clock/analysis_options.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml index 237e493ea..168ac1543 100644 --- a/pkgs/clock/analysis_options.yaml +++ b/pkgs/clock/analysis_options.yaml @@ -2,8 +2,6 @@ include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false - enable-experiment: - - non-nullable linter: rules: - always_declare_return_types From 7f2d3d2133587fb8976080f3fd24d04afc7624bd Mon Sep 17 00:00:00 2001 From: Alexander Thomas Date: Mon, 21 Dec 2020 22:39:27 +0100 Subject: [PATCH 52/89] Migrate to GitHub Actions (dart-lang/clock#27) * Delete .travis.yml * Ignore deprecated member use in test --- pkgs/clock/.github/workflows/test-package.yml | 64 +++++++++++++++++++ pkgs/clock/.travis.yml | 18 ------ pkgs/clock/test/default_test.dart | 1 + 3 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 pkgs/clock/.github/workflows/test-package.yml delete mode 100644 pkgs/clock/.travis.yml diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml new file mode 100644 index 000000000..e55702c22 --- /dev/null +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -0,0 +1,64 @@ +name: Dart CI + +on: + # Run on PRs and pushes to the default branch. + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + - cron: "0 0 * * 0" + +env: + PUB_ENVIRONMENT: bot.github + +jobs: + # Check code formatting and static analysis on a single OS (linux) + # against Dart dev. + analyze: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sdk: [dev] + steps: + - uses: actions/checkout@v2 + - uses: dart-lang/setup-dart@v0.1 + with: + channel: ${{ matrix.sdk }} + - id: install + name: Install dependencies + run: dart pub get + - name: Check formatting + run: dart format --output=none --set-exit-if-changed . + if: always() && steps.install.outcome == 'success' + - name: Analyze code + run: dart analyze --fatal-infos + if: always() && steps.install.outcome == 'success' + + # Run tests on a matrix consisting of two dimensions: + # 1. OS: ubuntu-latest, (macos-latest, windows-latest) + # 2. release channel: dev + test: + needs: analyze + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + # Add macos-latest and/or windows-latest if relevant for this package. + os: [ubuntu-latest] + sdk: [dev] + steps: + - uses: actions/checkout@v2 + - uses: dart-lang/setup-dart@v0.1 + with: + channel: ${{ matrix.sdk }} + - id: install + name: Install dependencies + run: dart pub get + - name: Run VM tests + run: dart test --platform vm + if: always() && steps.install.outcome == 'success' + - name: Run Chrome tests + run: dart test --platform chrome + if: always() && steps.install.outcome == 'success' diff --git a/pkgs/clock/.travis.yml b/pkgs/clock/.travis.yml deleted file mode 100644 index 19bd41641..000000000 --- a/pkgs/clock/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: dart - -dart: -- dev - -dart_task: - - test: -p vm,chrome - - dartfmt - - dartanalyzer: --fatal-lints --fatal-warnings . - - -# Only building master means that we don't run two builds for each pull request. -branches: - only: [master] - -cache: - directories: - - $HOME/.pub-cache diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart index fbf1a29f3..26a770418 100644 --- a/pkgs/clock/test/default_test.dart +++ b/pkgs/clock/test/default_test.dart @@ -71,6 +71,7 @@ void main() { throwsStateError); expect(clock.now(), equals(outerTime)); + // ignore: deprecated_member_use_from_same_package }, isFinal: true); }); }); From 6a1e2890518d9e6e5eac4384a917dc64935dcd90 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 2 Feb 2021 11:36:37 -0800 Subject: [PATCH 53/89] Prepare to publish stable null safety (dart-lang/clock#28) --- pkgs/clock/CHANGELOG.md | 4 ++++ pkgs/clock/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 2b2fa6f86..b6e18a04d 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +* Stable release for null safety. + ## 1.1.0-nullsafety.3 * Update SDK constraints to `>=2.12.0-0 <3.0.0` based on beta release diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index bace9896a..4f8cb93cf 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,5 +1,5 @@ name: clock -version: 1.1.0-nullsafety.3 +version: 1.1.0 description: A fakeable wrapper for dart:core clock APIs homepage: https://github.com/dart-lang/clock From faf01060d67b7661b801c15574df3d8d519796ab Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 20 Mar 2021 18:03:28 -0700 Subject: [PATCH 54/89] Fix formatting (dart-lang/clock#29) --- pkgs/clock/test/default_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/test/default_test.dart b/pkgs/clock/test/default_test.dart index 26a770418..80acd15bb 100644 --- a/pkgs/clock/test/default_test.dart +++ b/pkgs/clock/test/default_test.dart @@ -71,7 +71,7 @@ void main() { throwsStateError); expect(clock.now(), equals(outerTime)); - // ignore: deprecated_member_use_from_same_package + // ignore: deprecated_member_use_from_same_package }, isFinal: true); }); }); From a0fc1b9e6028ae52b5d13b9acabdaa5b40eb338a Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 23 Apr 2021 10:49:16 -0700 Subject: [PATCH 55/89] Update CI (dart-lang/clock#30) --- pkgs/clock/.github/workflows/test-package.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index e55702c22..cdc25d958 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -23,9 +23,9 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v0.1 + - uses: dart-lang/setup-dart@v1.0 with: - channel: ${{ matrix.sdk }} + sdk: ${{ matrix.sdk }} - id: install name: Install dependencies run: dart pub get @@ -47,12 +47,12 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [dev] + sdk: [2.12.0, dev] steps: - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v0.1 + - uses: dart-lang/setup-dart@v1.0 with: - channel: ${{ matrix.sdk }} + sdk: ${{ matrix.sdk }} - id: install name: Install dependencies run: dart pub get From fd18bdd043f1fa5006602504bd89bc8a38c09146 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Wed, 20 Apr 2022 14:38:32 -0700 Subject: [PATCH 56/89] Switch from homepage to repository in pubspec (dart-lang/clock#32) --- pkgs/clock/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 4f8cb93cf..585fa6178 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,7 +1,7 @@ name: clock version: 1.1.0 description: A fakeable wrapper for dart:core clock APIs -homepage: https://github.com/dart-lang/clock +repository: https://github.com/dart-lang/clock environment: sdk: ">=2.12.0-0 <3.0.0" From f149ad29551a2110475a435f585fc07cb5b0ad79 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 12 May 2022 02:11:54 +0000 Subject: [PATCH 57/89] switch to package:lints --- pkgs/clock/CHANGELOG.md | 3 ++ pkgs/clock/analysis_options.yaml | 92 +------------------------------- pkgs/clock/lib/src/default.dart | 8 ++- pkgs/clock/pubspec.yaml | 8 +-- 4 files changed, 15 insertions(+), 96 deletions(-) diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index b6e18a04d..9ee14389a 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.1.1-dev + + ## 1.1.0 * Stable release for null safety. diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml index 168ac1543..05f3a8ded 100644 --- a/pkgs/clock/analysis_options.yaml +++ b/pkgs/clock/analysis_options.yaml @@ -1,93 +1,5 @@ -include: package:pedantic/analysis_options.yaml +include: package:lints/core.yaml + analyzer: strong-mode: implicit-casts: false -linter: - rules: - - always_declare_return_types - #- annotate_overrides - - avoid_bool_literals_in_conditional_expressions - - avoid_classes_with_only_static_members - - avoid_empty_else - - avoid_function_literals_in_foreach_calls - - avoid_init_to_null - - avoid_null_checks_in_equality_operators - - avoid_relative_lib_imports - - avoid_renaming_method_parameters - - avoid_return_types_on_setters - - avoid_returning_null - - avoid_returning_null_for_future - - avoid_returning_null_for_void - - avoid_returning_this - - avoid_shadowing_type_parameters - - avoid_single_cascade_in_expression_statements - - avoid_types_as_parameter_names - - avoid_unused_constructor_parameters - - await_only_futures - - camel_case_types - - cancel_subscriptions - - cascade_invocations - - comment_references - - constant_identifier_names - - control_flow_in_finally - - directives_ordering - - empty_catches - - empty_constructor_bodies - - empty_statements - - file_names - - hash_and_equals - - implementation_imports - - invariant_booleans - - iterable_contains_unrelated_type - - join_return_with_assignment - - library_names - - library_prefixes - - list_remove_unrelated_type - - literal_only_boolean_expressions - - no_adjacent_strings_in_list - - no_duplicate_case_values - - non_constant_identifier_names - - null_closures - - omit_local_variable_types - - only_throw_errors - - overridden_fields - - package_api_docs - - package_names - - package_prefixed_library_names - - prefer_adjacent_string_concatenation - - prefer_collection_literals - - prefer_conditional_assignment - - prefer_const_constructors - - prefer_contains - - prefer_equal_for_default_values - - prefer_final_fields - #- prefer_final_locals - - prefer_generic_function_type_aliases - - prefer_initializing_formals - - prefer_interpolation_to_compose_strings - - prefer_is_empty - - prefer_is_not_empty - - prefer_null_aware_operators - #- prefer_single_quotes - - prefer_typing_uninitialized_variables - - recursive_getters - - slash_for_doc_comments - - test_types_in_equals - - throw_in_finally - - type_init_formals - - unawaited_futures - - unnecessary_await_in_return - - unnecessary_brace_in_string_interps - - unnecessary_const - - unnecessary_getters_setters - - unnecessary_lambdas - - unnecessary_new - - unnecessary_null_aware_assignments - - unnecessary_parenthesis - - unnecessary_statements - - unnecessary_this - - unrelated_type_equality_checks - - use_function_type_syntax_for_parameters - - use_rethrow_when_possible - - valid_regexps - - void_checks diff --git a/pkgs/clock/lib/src/default.dart b/pkgs/clock/lib/src/default.dart index 241917029..927e21d48 100644 --- a/pkgs/clock/lib/src/default.dart +++ b/pkgs/clock/lib/src/default.dart @@ -38,8 +38,12 @@ Clock get clock => Zone.current[_clockKey] as Clock? ?? const Clock(); // ignore: deprecated_member_use_from_same_package /// If [isFinal] is `true`, calls to [withClock] within [callback] will throw a /// [StateError]. However, this parameter is deprecated and should be avoided. -T withClock(Clock clock, T Function() callback, - {@deprecated bool isFinal = false}) { +T withClock( + Clock clock, + T Function() callback, { + @Deprecated('This parameter is deprecated and should be avoided') + bool isFinal = false, +}) { if ((Zone.current[_isFinalKey] ?? false) == true) { throw StateError( 'Cannot call withClock() within a call to withClock(isFinal = true).'); diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 585fa6178..25c35791d 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,11 +1,11 @@ name: clock -version: 1.1.0 -description: A fakeable wrapper for dart:core clock APIs +version: 1.1.1-dev +description: A fakeable wrapper for dart:core clock APIs. repository: https://github.com/dart-lang/clock environment: sdk: ">=2.12.0-0 <3.0.0" dev_dependencies: - test: ^1.16.0-nullsafety - pedantic: ^1.10.0-nullsafety + lints: ^1.0.0 + test: ^1.16.0 From b76ed33595965d504ce17819af71cfe7e61a880f Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Wed, 15 Jun 2022 11:17:58 -0700 Subject: [PATCH 58/89] prep for publishing 1.1.1 --- pkgs/clock/CHANGELOG.md | 4 +++- pkgs/clock/README.md | 4 ++++ pkgs/clock/analysis_options.yaml | 2 +- pkgs/clock/pubspec.yaml | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 9ee14389a..2e04bc4c4 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,5 +1,7 @@ -## 1.1.1-dev +## 1.1.1 +* Switch to using `package:lints`. +* Populate the pubspec `repository` field. ## 1.1.0 diff --git a/pkgs/clock/README.md b/pkgs/clock/README.md index b847f763b..2d29311a3 100644 --- a/pkgs/clock/README.md +++ b/pkgs/clock/README.md @@ -1,3 +1,7 @@ +[![Dart CI](https://github.com/dart-lang/clock/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/clock/actions/workflows/test-package.yml) +[![pub package](https://img.shields.io/pub/v/clock.svg)](https://pub.dev/packages/clock) +[![package publisher](https://img.shields.io/pub/publisher/clock.svg)](https://pub.dev/packages/clock/publisher) + This package provides a [`Clock`][] class which encapsulates the notion of the "current time" and provides easy access to points relative to the current time. Different `Clock`s can have a different notion of the current time, and the diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml index 05f3a8ded..4fa4b8d13 100644 --- a/pkgs/clock/analysis_options.yaml +++ b/pkgs/clock/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:lints/core.yaml +include: package:lints/recommended.yaml analyzer: strong-mode: diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 25c35791d..f162ae87e 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,5 +1,5 @@ name: clock -version: 1.1.1-dev +version: 1.1.1 description: A fakeable wrapper for dart:core clock APIs. repository: https://github.com/dart-lang/clock From 285483053a41548ab54f4129ce637ff1e46ccfdf Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Wed, 15 Jun 2022 13:53:42 -0700 Subject: [PATCH 59/89] Update pubspec.yaml --- pkgs/clock/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index f162ae87e..c67030cc0 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -4,7 +4,7 @@ description: A fakeable wrapper for dart:core clock APIs. repository: https://github.com/dart-lang/clock environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dev_dependencies: lints: ^1.0.0 From c0f3b218d4aed99e29faf40f52f32b29ab7acba1 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 29 Aug 2022 11:28:37 -0700 Subject: [PATCH 60/89] Update CONTRIBUTING.md --- pkgs/clock/CONTRIBUTING.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkgs/clock/CONTRIBUTING.md b/pkgs/clock/CONTRIBUTING.md index 615b92ff9..2632963a5 100644 --- a/pkgs/clock/CONTRIBUTING.md +++ b/pkgs/clock/CONTRIBUTING.md @@ -38,11 +38,9 @@ Before you send your pull request, make sure all the tests pass! ### File headers -All files in the project must start with the following header. - - // Copyright (c) 2017, 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. +When creating new source files, please copy the file header from +https://github.com/dart-lang/clock/blob/master/lib/clock.dart and update the year +for the copyright to the current year. ### The small print From 0900d8fc5d9f5f109c09af8753609490ff405d7c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 9 Nov 2022 15:23:32 -0800 Subject: [PATCH 61/89] blast_repo fixes (dart-lang/clock#40) Dependabot GitHub Action --- pkgs/clock/.github/dependabot.yml | 9 +++++++++ pkgs/clock/.github/workflows/test-package.yml | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 pkgs/clock/.github/dependabot.yml diff --git a/pkgs/clock/.github/dependabot.yml b/pkgs/clock/.github/dependabot.yml new file mode 100644 index 000000000..1603cdd9e --- /dev/null +++ b/pkgs/clock/.github/dependabot.yml @@ -0,0 +1,9 @@ +# Dependabot configuration file. +# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates +version: 2 + +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index cdc25d958..68f255c74 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,8 +22,8 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v1.0 + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} - id: install @@ -49,8 +49,8 @@ jobs: os: [ubuntu-latest] sdk: [2.12.0, dev] steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v1.0 + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} - id: install From 9aff12410c4d0416efc8621c94366107bfd554fa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Jan 2023 11:04:19 -0800 Subject: [PATCH 62/89] Bump actions/checkout from 3.1.0 to 3.2.0 (dart-lang/clock#41) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8...755da8c3cf115ac066823e79a1e1788f8940201b) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 68f255c74..c3560007f 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.12.0, dev] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d with: sdk: ${{ matrix.sdk }} From 49db8e4b8cbd40e7952708704a518c647b2509c5 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 9 Jan 2023 19:22:41 -0800 Subject: [PATCH 63/89] Migrate from no-implicit-casts to strict-casts (dart-lang/clock#42) --- pkgs/clock/analysis_options.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml index 4fa4b8d13..055ac1087 100644 --- a/pkgs/clock/analysis_options.yaml +++ b/pkgs/clock/analysis_options.yaml @@ -1,5 +1,5 @@ include: package:lints/recommended.yaml analyzer: - strong-mode: - implicit-casts: false + language: + strict-casts: true From b5a2c47f6f185a925359f7f31ea8a77776d6825a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Feb 2023 08:00:49 -0800 Subject: [PATCH 64/89] Bump dart-lang/setup-dart from 1.3 to 1.4 (dart-lang/clock#44) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.3 to 1.4. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/6a218f2413a3e78e9087f638a238f6b40893203d...a57a6c04cf7d4840e88432aad6281d1e125f0d46) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index c3560007f..ce5f2d2b1 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.12.0, dev] steps: - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b - - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d + - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} - id: install From 8cba5f464e6665ad30caa98242ff02847e5d3add Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Feb 2023 08:33:29 -0800 Subject: [PATCH 65/89] Bump actions/checkout from 3.2.0 to 3.3.0 (dart-lang/clock#43) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/755da8c3cf115ac066823e79a1e1788f8940201b...ac593985615ec2ede58e132d2e21d2b1cbd6127c) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index ce5f2d2b1..70fb7ec43 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.12.0, dev] steps: - - uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 with: sdk: ${{ matrix.sdk }} From ef00809cc1d941b035a6490acdb3a45c14ea9c75 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 15 Mar 2023 14:48:21 -0700 Subject: [PATCH 66/89] Require Dart 2.19, use and fix recommended lints (dart-lang/clock#46) --- pkgs/clock/.github/workflows/test-package.yml | 2 +- pkgs/clock/CHANGELOG.md | 22 +++++-------------- pkgs/clock/analysis_options.yaml | 11 +++++++++- pkgs/clock/lib/src/clock.dart | 2 +- pkgs/clock/pubspec.yaml | 6 ++--- pkgs/clock/test/clock_test.dart | 14 ++++++------ 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 70fb7ec43..20b28dece 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -47,7 +47,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [2.12.0, dev] + sdk: [2.19.0, dev] steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 2e04bc4c4..9d94e5bfd 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.2-dev + +* Require Dart 2.19 + ## 1.1.1 * Switch to using `package:lints`. @@ -5,23 +9,7 @@ ## 1.1.0 -* Stable release for null safety. - -## 1.1.0-nullsafety.3 - -* Update SDK constraints to `>=2.12.0-0 <3.0.0` based on beta release - guidelines. - -## 1.1.0-nullsafety.2 - -* Allow prerelease versions of the 2.12 sdk. - -## 1.1.0-nullsafety.1 - -* Allow 2.10 stable and 2.11.0 dev SDK versions. - -## 1.1.0-nullsafety - +* Update SDK constraints to `>=2.12.0 <3.0.0`. * Update to null safety. ## 1.0.1 diff --git a/pkgs/clock/analysis_options.yaml b/pkgs/clock/analysis_options.yaml index 055ac1087..9ee7c2b6a 100644 --- a/pkgs/clock/analysis_options.yaml +++ b/pkgs/clock/analysis_options.yaml @@ -1,5 +1,14 @@ -include: package:lints/recommended.yaml +# https://dart.dev/guides/language/analysis-options +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: strict-casts: true + strict-inference: true + strict-raw-types: true + +linter: + rules: + - avoid_private_typedef_functions + - avoid_redundant_argument_values + - use_super_parameters diff --git a/pkgs/clock/lib/src/clock.dart b/pkgs/clock/lib/src/clock.dart index 6079fb304..f6f47deb1 100644 --- a/pkgs/clock/lib/src/clock.dart +++ b/pkgs/clock/lib/src/clock.dart @@ -20,7 +20,7 @@ import 'utils.dart'; /// /// This class is designed with testability in mind. The current point in time /// (or [now()]) is defined by a function that returns a [DateTime]. By -/// supplying your own time function or using [new Clock.fixed], you can control +/// supplying your own time function or using [Clock.fixed], you can control /// exactly what time a [Clock] returns and base your test expectations on that. /// /// Most users should use the top-level [clock] field, which provides access to diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index c67030cc0..3700d4b49 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,11 +1,11 @@ name: clock -version: 1.1.1 +version: 1.1.2-dev description: A fakeable wrapper for dart:core clock APIs. repository: https://github.com/dart-lang/clock environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.19.0 <3.0.0" dev_dependencies: - lints: ^1.0.0 + dart_flutter_team_lints: ^1.0.0 test: ^1.16.0 diff --git a/pkgs/clock/test/clock_test.dart b/pkgs/clock/test/clock_test.dart index 6c7231c54..c457153df 100644 --- a/pkgs/clock/test/clock_test.dart +++ b/pkgs/clock/test/clock_test.dart @@ -93,7 +93,7 @@ void main() { }); test('should return time millis ago', () { - expect(clock.millisAgo(1000), DateTime(2012, 12, 31, 23, 59, 59, 000)); + expect(clock.millisAgo(1000), DateTime(2012, 12, 31, 23, 59, 59)); }); test('should return time millis from now', () { @@ -101,27 +101,27 @@ void main() { }); test('should return time seconds ago', () { - expect(clock.secondsAgo(10), DateTime(2012, 12, 31, 23, 59, 50, 000)); + expect(clock.secondsAgo(10), DateTime(2012, 12, 31, 23, 59, 50)); }); test('should return time seconds from now', () { - expect(clock.secondsFromNow(3), DateTime(2013, 1, 1, 0, 0, 3, 0)); + expect(clock.secondsFromNow(3), DateTime(2013, 1, 1, 0, 0, 3)); }); test('should return time minutes ago', () { - expect(clock.minutesAgo(10), DateTime(2012, 12, 31, 23, 50, 0, 000)); + expect(clock.minutesAgo(10), DateTime(2012, 12, 31, 23, 50)); }); test('should return time minutes from now', () { - expect(clock.minutesFromNow(3), DateTime(2013, 1, 1, 0, 3, 0, 0)); + expect(clock.minutesFromNow(3), DateTime(2013, 1, 1, 0, 3)); }); test('should return time hours ago', () { - expect(clock.hoursAgo(10), DateTime(2012, 12, 31, 14, 0, 0, 000)); + expect(clock.hoursAgo(10), DateTime(2012, 12, 31, 14)); }); test('should return time hours from now', () { - expect(clock.hoursFromNow(3), DateTime(2013, 1, 1, 3, 0, 0, 0)); + expect(clock.hoursFromNow(3), DateTime(2013, 1, 1, 3)); }); test('should return time days ago', () { From de144fc29492801375c0532d314d818b6a858710 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:36:37 -0700 Subject: [PATCH 67/89] Bump dart-lang/setup-dart from 1.4.0 to 1.5.0 (dart-lang/clock#48) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/dart-lang/setup-dart/releases) - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md) - [Commits](https://github.com/dart-lang/setup-dart/compare/a57a6c04cf7d4840e88432aad6281d1e125f0d46...d6a63dab3335f427404425de0fbfed4686d93c4f) --- updated-dependencies: - dependency-name: dart-lang/setup-dart dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 20b28dece..d6d0f892a 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c - - uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46 + - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} - id: install From 28db4f777dd7db0f2333b009298904e1f1a5a59b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:52:26 -0700 Subject: [PATCH 68/89] Bump actions/checkout from 3.3.0 to 3.5.0 (dart-lang/clock#47) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.3.0 to 3.5.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/ac593985615ec2ede58e132d2e21d2b1cbd6127c...8f4b7f84864484a7bf31766abe9204da3cbe65b3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index d6d0f892a..763267350 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From c53e768b3cbc6be6bf84eebac386cd4aeba5f5cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 May 2023 12:24:42 -0700 Subject: [PATCH 69/89] Bump actions/checkout from 3.5.0 to 3.5.2 (dart-lang/clock#50) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.0 to 3.5.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/8f4b7f84864484a7bf31766abe9204da3cbe65b3...8e5e7e5ab8b370d6c329ec480221332ada57f0ab) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 763267350..0874bdd38 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From 41c2e553ea6efb0c144069c2d91145543e8c98fa Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 15 May 2023 14:35:16 -0700 Subject: [PATCH 70/89] blast_repo fixes (dart-lang/clock#51) dependabot --- pkgs/clock/.github/dependabot.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/clock/.github/dependabot.yml b/pkgs/clock/.github/dependabot.yml index 1603cdd9e..725f03af2 100644 --- a/pkgs/clock/.github/dependabot.yml +++ b/pkgs/clock/.github/dependabot.yml @@ -3,7 +3,9 @@ version: 2 updates: - - package-ecosystem: "github-actions" - directory: "/" + - package-ecosystem: github-actions + directory: / schedule: - interval: "monthly" + interval: monthly + labels: + - autosubmit From 1bc0ca7fcf5a3da5cc48b9dcd1ed282711b66e86 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sun, 21 May 2023 19:57:15 -0700 Subject: [PATCH 71/89] Update formatting (dart-lang/clock#52) --- pkgs/clock/lib/src/default.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clock/lib/src/default.dart b/pkgs/clock/lib/src/default.dart index 927e21d48..2a46b9f8b 100644 --- a/pkgs/clock/lib/src/default.dart +++ b/pkgs/clock/lib/src/default.dart @@ -42,7 +42,7 @@ T withClock( Clock clock, T Function() callback, { @Deprecated('This parameter is deprecated and should be avoided') - bool isFinal = false, + bool isFinal = false, }) { if ((Zone.current[_isFinalKey] ?? false) == true) { throw StateError( From 78b7e068f83bfcec38d3d42f636027fa00ae4c91 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Jul 2023 12:14:57 +0000 Subject: [PATCH 72/89] Bump actions/checkout from 3.5.2 to 3.5.3 (dart-lang/clock#54) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.2 to 3.5.3.
Release notes

Sourced from actions/checkout's releases.

v3.5.3

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v3...v3.5.3

Changelog

Sourced from actions/checkout's changelog.

Changelog

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

v3.1.0

v3.0.2

v3.0.1

v3.0.0

v2.3.1

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=3.5.2&new-version=3.5.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 0874bdd38..4c8399a81 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From e2245ac7b5d96725d0688b1a21743359f07fbc08 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:38:05 +0000 Subject: [PATCH 73/89] Bump actions/checkout from 3.5.3 to 3.6.0 (dart-lang/clock#55) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.3 to 3.6.0.
Release notes

Sourced from actions/checkout's releases.

v3.6.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v3.5.3...v3.6.0

Changelog

Sourced from actions/checkout's changelog.

Changelog

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

v3.1.0

v3.0.2

v3.0.1

v3.0.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=3.5.3&new-version=3.6.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 4c8399a81..8b1f4d4fb 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: sdk: ${{ matrix.sdk }} From c6b3b4915994e5feeb3781efed7c6ed3325ceba0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 12:58:43 +0000 Subject: [PATCH 74/89] Bump dart-lang/setup-dart from 1.5.0 to 1.5.1 (dart-lang/clock#57) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.5.0 to 1.5.1.
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.
Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

  • Automatically create OIDC token for pub.dev.
  • Add a reusable workflow for publishing.

v1.3.0

  • The install location of the Dart SDK is now available in an environment variable, DART_HOME (dart-lang/clock#43).
  • Fixed an issue where cached downloads could lead to unzip issues on self-hosted runners (dart-lang/clock#35).

v1.2.0

  • Fixed a path issue impacting git dependencies on Windows.

v1.1.0

  • Added a flavor option setup.sh to allow downloading unpublished builds.

v1.0.0

  • Promoted to 1.0 stable.

v0.5

  • Fixed a Windows pub global activate path issue.

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=dart-lang/setup-dart&package-manager=github_actions&previous-version=1.5.0&new-version=1.5.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 8b1f4d4fb..297fd2bfc 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f + - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} - id: install From 83d6e6290396d47384305a657c7db216c18d50a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 12:59:33 +0000 Subject: [PATCH 75/89] Bump actions/checkout from 3.6.0 to 4.1.0 (dart-lang/clock#56) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.1.0.
Release notes

Sourced from actions/checkout's releases.

v4.1.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.0.0...v4.1.0

v4.0.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v3...v4.0.0

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

v3.1.0

v3.0.2

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=3.6.0&new-version=4.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 297fd2bfc..367d5dea3 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} From 7190d6befd8d7dfc4b788f64b2f3cd8d963f1425 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:56:43 +0000 Subject: [PATCH 76/89] Bump actions/checkout from 4.1.0 to 4.1.1 (dart-lang/clock#58) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1.
Release notes

Sourced from actions/checkout's releases.

v4.1.1

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.0...v4.1.1

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.0&new-version=4.1.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 367d5dea3..e0d4f73af 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 with: sdk: ${{ matrix.sdk }} From 540933465d39d79e58c8ff7af571c98b1fd7c7f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:23:05 +0000 Subject: [PATCH 77/89] Bump dart-lang/setup-dart from 1.5.1 to 1.6.0 (dart-lang/clock#59) Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.5.1 to 1.6.0.
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).
Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

  • Automatically create OIDC token for pub.dev.
  • Add a reusable workflow for publishing.

v1.3.0

  • The install location of the Dart SDK is now available in an environment variable, DART_HOME (dart-lang/clock#43).
  • Fixed an issue where cached downloads could lead to unzip issues on self-hosted runners (dart-lang/clock#35).

v1.2.0

  • Fixed a path issue impacting git dependencies on Windows.

v1.1.0

  • Added a flavor option setup.sh to allow downloading unpublished builds.

v1.0.0

  • Promoted to 1.0 stable.

v0.5

  • Fixed a Windows pub global activate path issue.

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=dart-lang/setup-dart&package-manager=github_actions&previous-version=1.5.1&new-version=1.6.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index e0d4f73af..02786315a 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: sdk: ${{ matrix.sdk }} - id: install From b76434600277e11128b559307fd998976f8f269f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 12:33:56 +0000 Subject: [PATCH 78/89] Bump dart-lang/setup-dart from 1.6.0 to 1.6.2 (dart-lang/clock#60) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.6.0 to 1.6.2.
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.
Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

  • Automatically create OIDC token for pub.dev.
  • Add a reusable workflow for publishing.

v1.3.0

  • The install location of the Dart SDK is now available in an environment variable, DART_HOME (dart-lang/clock#43).
  • Fixed an issue where cached downloads could lead to unzip issues on self-hosted runners (dart-lang/clock#35).

v1.2.0

  • Fixed a path issue impacting git dependencies on Windows.

v1.1.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=dart-lang/setup-dart&package-manager=github_actions&previous-version=1.6.0&new-version=1.6.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 02786315a..41ca6901b 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d + - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} - id: install From 71e2280e2a16e81057c755737e3fd209639263c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:41:18 +0000 Subject: [PATCH 79/89] Bump actions/checkout from 4.1.1 to 4.1.2 (dart-lang/clock#61) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2.
Release notes

Sourced from actions/checkout's releases.

v4.1.2

We are investigating the following issue with this release and have rolled-back the v4 tag to point to v4.1.1

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.1...v4.1.2

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

v3.3.0

v3.2.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.1&new-version=4.1.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 41ca6901b..c42ccfd30 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} From 74e193bbd67f283ad38912dc1551da776a57b248 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 12:15:18 +0000 Subject: [PATCH 80/89] Bump actions/checkout from 4.1.2 to 4.1.4 (dart-lang/clock#62) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.2 to 4.1.4.
Release notes

Sourced from actions/checkout's releases.

v4.1.4

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.3...v4.1.4

v4.1.3

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.2...v4.1.3

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

v3.5.0

v3.4.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.2&new-version=4.1.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index c42ccfd30..7c3b74fea 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 with: sdk: ${{ matrix.sdk }} From fa609895e285e3cac1e9adbab89aa8c2b746363e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 15:17:53 +0000 Subject: [PATCH 81/89] Bump dart-lang/setup-dart from 1.6.2 to 1.6.4 (dart-lang/clock#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.6.2 to 1.6.4.
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.4

  • Rebuild JS code to include changes from v1.6.3

v1.6.3

Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.4

  • Rebuild JS code.

v1.6.3

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

  • Automatically create OIDC token for pub.dev.
  • Add a reusable workflow for publishing.

v1.3.0

  • The install location of the Dart SDK is now available

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=dart-lang/setup-dart&package-manager=github_actions&previous-version=1.6.2&new-version=1.6.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 7c3b74fea..a3400f3f1 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -23,7 +23,7 @@ jobs: sdk: [dev] steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} - id: install @@ -50,7 +50,7 @@ jobs: sdk: [2.19.0, dev] steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b - - uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 + - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} - id: install From 0cede1c9579a7d78a340216b8970031d0848e6ad Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 3 May 2024 15:07:38 -0700 Subject: [PATCH 82/89] blast_repo fixes (dart-lang/clock#64) dependabot --- pkgs/clock/.github/dependabot.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/clock/.github/dependabot.yml b/pkgs/clock/.github/dependabot.yml index 725f03af2..cde02ad6a 100644 --- a/pkgs/clock/.github/dependabot.yml +++ b/pkgs/clock/.github/dependabot.yml @@ -9,3 +9,7 @@ updates: interval: monthly labels: - autosubmit + groups: + github-actions: + patterns: + - "*" From b49a03d1cbe5630c35167515b0f1a9a5c35c69f8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Jun 2024 12:24:18 +0000 Subject: [PATCH 83/89] Bump actions/checkout from 4.1.4 to 4.1.6 in the github-actions group (dart-lang/clock#65) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 1 update: [actions/checkout](https://github.com/actions/checkout). Updates `actions/checkout` from 4.1.4 to 4.1.6
Release notes

Sourced from actions/checkout's releases.

v4.1.6

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.5...v4.1.6

v4.1.5

What's Changed

Full Changelog: https://github.com/actions/checkout/compare/v4.1.4...v4.1.5

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.6

v4.1.5

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

v3.5.2

v3.5.1

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.4&new-version=4.1.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index a3400f3f1..dc216a4f1 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} From 5376a7d4ded47aa4bfcd225d3c552c72a0cc8488 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:40:01 +0000 Subject: [PATCH 84/89] Bump the github-actions group with 2 updates (dart-lang/clock#66) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 2 updates: [actions/checkout](https://github.com/actions/checkout) and [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart). Updates `actions/checkout` from 4.1.6 to 4.1.7
Release notes

Sourced from actions/checkout's releases.

v4.1.7

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.6...v4.1.7

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.1.7

v4.1.6

v4.1.5

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

v3.5.3

... (truncated)

Commits

Updates `dart-lang/setup-dart` from 1.6.4 to 1.6.5
Release notes

Sourced from dart-lang/setup-dart's releases.

v1.6.5

dart-lang/clock#118: dart-lang/setup-dartdart-lang/clock#118

Changelog

Sourced from dart-lang/setup-dart's changelog.

v1.6.5

dart-lang/clock#118: dart-lang/setup-dartdart-lang/clock#118

v1.6.4

  • Rebuild JS code.

v1.6.3

v1.6.2

v1.6.1

  • Updated the google storage url for main channel releases.

v1.6.0

  • Enable provisioning of the latest Dart SDK patch release by specifying just the major and minor version (e.g. 3.2).

v1.5.1

  • No longer test the setup-dart action on pre-2.12 SDKs.
  • Upgrade JS interop code to use extension types (the new name for inline classes).
  • The upcoming rename of the be channel to main is now supported with forward compatibility that switches when the rename happens.

v1.5.0

  • Re-wrote the implementation of the action into Dart.
  • Auto-detect the platform architecture (x64, ia32, arm, arm64).
  • Improved the caching and download resilience of the sdk.
  • Added a new action output: dart-version - the installed version of the sdk.

v1.4.0

... (truncated)

Commits

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- pkgs/clock/.github/workflows/test-package.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index dc216a4f1..2181d7961 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,8 +22,8 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} - id: install @@ -49,8 +49,8 @@ jobs: os: [ubuntu-latest] sdk: [2.19.0, dev] steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 - - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} - id: install From 946185c98a251953ee9086c6783c7f1cd6aae461 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 8 Jul 2024 10:42:13 -0700 Subject: [PATCH 85/89] blast_repo fixes (dart-lang/clock#67) auto-publish, github-actions, no-response --- pkgs/clock/.github/workflows/no-response.yml | 37 ++++++++++++++++++++ pkgs/clock/.github/workflows/publish.yaml | 17 +++++++++ 2 files changed, 54 insertions(+) create mode 100644 pkgs/clock/.github/workflows/no-response.yml create mode 100644 pkgs/clock/.github/workflows/publish.yaml diff --git a/pkgs/clock/.github/workflows/no-response.yml b/pkgs/clock/.github/workflows/no-response.yml new file mode 100644 index 000000000..ab1ac4984 --- /dev/null +++ b/pkgs/clock/.github/workflows/no-response.yml @@ -0,0 +1,37 @@ +# A workflow to close issues where the author hasn't responded to a request for +# more information; see https://github.com/actions/stale. + +name: No Response + +# Run as a daily cron. +on: + schedule: + # Every day at 8am + - cron: '0 8 * * *' + +# All permissions not specified are set to 'none'. +permissions: + issues: write + pull-requests: write + +jobs: + no-response: + runs-on: ubuntu-latest + if: ${{ github.repository_owner == 'dart-lang' }} + steps: + - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e + with: + # Don't automatically mark inactive issues+PRs as stale. + days-before-stale: -1 + # Close needs-info issues and PRs after 14 days of inactivity. + days-before-close: 14 + stale-issue-label: "needs-info" + close-issue-message: > + Without additional information we're not able to resolve this issue. + Feel free to add more info or respond to any questions above and we + can reopen the case. Thanks for your contribution! + stale-pr-label: "needs-info" + close-pr-message: > + Without additional information we're not able to resolve this PR. + Feel free to add more info or respond to any questions above. + Thanks for your contribution! diff --git a/pkgs/clock/.github/workflows/publish.yaml b/pkgs/clock/.github/workflows/publish.yaml new file mode 100644 index 000000000..27157a046 --- /dev/null +++ b/pkgs/clock/.github/workflows/publish.yaml @@ -0,0 +1,17 @@ +# A CI configuration to auto-publish pub packages. + +name: Publish + +on: + pull_request: + branches: [ master ] + push: + tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] + +jobs: + publish: + if: ${{ github.repository_owner == 'dart-lang' }} + uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main + permissions: + id-token: write # Required for authentication using OIDC + pull-requests: write # Required for writing the pull request note From 31d31609c8f28ae8829c5cf623410f44a11fb7e8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 8 Jul 2024 12:49:43 -0700 Subject: [PATCH 86/89] update lints (dart-lang/clock#68) --- pkgs/clock/.github/workflows/test-package.yml | 2 +- pkgs/clock/CHANGELOG.md | 4 ++-- pkgs/clock/pubspec.yaml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 2181d7961..04a0ca567 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -47,7 +47,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [2.19.0, dev] + sdk: [3.4, dev] steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 9d94e5bfd..76ab0c5c4 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,6 +1,6 @@ -## 1.1.2-dev +## 1.1.2-wip -* Require Dart 2.19 +* Require Dart 3.4 ## 1.1.1 diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 3700d4b49..33120587c 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,11 +1,11 @@ name: clock -version: 1.1.2-dev +version: 1.1.2-wip description: A fakeable wrapper for dart:core clock APIs. repository: https://github.com/dart-lang/clock environment: - sdk: ">=2.19.0 <3.0.0" + sdk: ^3.4.0 dev_dependencies: - dart_flutter_team_lints: ^1.0.0 - test: ^1.16.0 + dart_flutter_team_lints: ^3.0.0 + test: ^1.16.6 From 08693ca91dd288e0879033706ae6112a7597865a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:07:19 +0000 Subject: [PATCH 87/89] Bump actions/checkout from 4.1.7 to 4.2.0 in the github-actions group (dart-lang/clock#69) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the github-actions group with 1 update: [actions/checkout](https://github.com/actions/checkout). Updates `actions/checkout` from 4.1.7 to 4.2.0
Release notes

Sourced from actions/checkout's releases.

v4.2.0

What's Changed

New Contributors

Full Changelog: https://github.com/actions/checkout/compare/v4.1.7...v4.2.0

Changelog

Sourced from actions/checkout's changelog.

Changelog

v4.2.0

v4.1.7

v4.1.6

v4.1.5

v4.1.4

v4.1.3

v4.1.2

v4.1.1

v4.1.0

v4.0.0

v3.6.0

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=4.1.7&new-version=4.2.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
--- pkgs/clock/.github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clock/.github/workflows/test-package.yml b/pkgs/clock/.github/workflows/test-package.yml index 04a0ca567..867cc9615 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/pkgs/clock/.github/workflows/test-package.yml @@ -22,7 +22,7 @@ jobs: matrix: sdk: [dev] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} @@ -49,7 +49,7 @@ jobs: os: [ubuntu-latest] sdk: [3.4, dev] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 with: sdk: ${{ matrix.sdk }} From 55c5b2a0d6861847d826f102f9e4e666425ef0ec Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 25 Oct 2024 11:35:51 +0200 Subject: [PATCH 88/89] Add issue template and other fixes --- .github/ISSUE_TEMPLATE/clock.md | 5 ++++ pkgs/clock/CONTRIBUTING.md | 51 --------------------------------- pkgs/clock/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 52 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/clock.md delete mode 100644 pkgs/clock/CONTRIBUTING.md diff --git a/.github/ISSUE_TEMPLATE/clock.md b/.github/ISSUE_TEMPLATE/clock.md new file mode 100644 index 000000000..1ed8f73b6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/clock.md @@ -0,0 +1,5 @@ +--- +name: "package:clock" +about: "Create a bug or file a feature request against package:clock." +labels: "package:clock" +--- \ No newline at end of file diff --git a/pkgs/clock/CONTRIBUTING.md b/pkgs/clock/CONTRIBUTING.md deleted file mode 100644 index 2632963a5..000000000 --- a/pkgs/clock/CONTRIBUTING.md +++ /dev/null @@ -1,51 +0,0 @@ -Want to contribute? Great! First, read this page (including the small print at -the end). - -### Before you contribute - -Before we can use your code, you must sign the -[Google Individual Contributor License Agreement][CLA] (CLA), which you can do -online. The CLA is necessary mainly because you own the copyright to your -changes, even after your contribution becomes part of our codebase, so we need -your permission to use and distribute your code. We also need to be sure of -various other things—for instance that you'll tell us if you know that your code -infringes on other people's patents. You don't have to sign the CLA until after -you've submitted your code for review and a member has approved it, but you must -do it before we can put your code into our codebase. - -Before you start working on a larger contribution, you should get in touch with -us first through the issue tracker with your idea so that we can help out and -possibly guide you. Coordinating up front makes it much easier to avoid -frustration later on. - -[CLA]: https://cla.developers.google.com/about/google-individual - -### Code reviews - -All submissions, including submissions by project members, require review. We -recommend [forking the repository][fork], making changes in your fork, and -[sending us a pull request][pr] so we can review the changes and merge them into -this repository. - -[fork]: https://help.github.com/articles/about-forks/ -[pr]: https://help.github.com/articles/creating-a-pull-request/ - -Functional changes will require tests to be added or changed. The tests live in -the `test/` directory, and are run with `pub run test`. If you need to create -new tests, use the existing tests as a guideline for what they should look like. - -Before you send your pull request, make sure all the tests pass! - -### File headers - -When creating new source files, please copy the file header from -https://github.com/dart-lang/clock/blob/master/lib/clock.dart and update the year -for the copyright to the current year. - -### The small print - -Contributions made by corporations are covered by a different agreement than the -one above, the -[Software Grant and Corporate Contributor License Agreement][CCLA]. - -[CCLA]: https://developers.google.com/open-source/cla/corporate diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index 33120587c..de2930323 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,7 +1,7 @@ name: clock version: 1.1.2-wip description: A fakeable wrapper for dart:core clock APIs. -repository: https://github.com/dart-lang/clock +repository: https://github.com/dart-lang/tools/tree/main/pkgs/clock environment: sdk: ^3.4.0 From aabc387ab70ddd58f131db1ab201337413d16e09 Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 25 Oct 2024 11:52:09 +0200 Subject: [PATCH 89/89] Moving fixes --- .github/labeler.yml | 4 ++ .../workflows/clock.yaml | 17 +++++++-- README.md | 1 + pkgs/clock/.github/dependabot.yml | 15 -------- pkgs/clock/.github/workflows/no-response.yml | 37 ------------------- pkgs/clock/.github/workflows/publish.yaml | 17 --------- pkgs/clock/CHANGELOG.md | 3 +- pkgs/clock/README.md | 2 +- pkgs/clock/pubspec.yaml | 2 +- 9 files changed, 23 insertions(+), 75 deletions(-) rename pkgs/clock/.github/workflows/test-package.yml => .github/workflows/clock.yaml (87%) delete mode 100644 pkgs/clock/.github/dependabot.yml delete mode 100644 pkgs/clock/.github/workflows/no-response.yml delete mode 100644 pkgs/clock/.github/workflows/publish.yaml diff --git a/.github/labeler.yml b/.github/labeler.yml index c3d5de0b9..a6939c7f8 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -12,6 +12,10 @@ - changed-files: - any-glob-to-any-file: 'pkgs/cli_config/**' +'package:clock': + - changed-files: + - any-glob-to-any-file: 'pkgs/clock/**' + 'package:coverage': - changed-files: - any-glob-to-any-file: 'pkgs/coverage/**' diff --git a/pkgs/clock/.github/workflows/test-package.yml b/.github/workflows/clock.yaml similarity index 87% rename from pkgs/clock/.github/workflows/test-package.yml rename to .github/workflows/clock.yaml index 867cc9615..1ad4ade04 100644 --- a/pkgs/clock/.github/workflows/test-package.yml +++ b/.github/workflows/clock.yaml @@ -1,17 +1,28 @@ -name: Dart CI +name: package:clock on: # Run on PRs and pushes to the default branch. push: - branches: [ master ] + branches: [ main ] + paths: + - '.github/workflows/clock.yml' + - 'pkgs/clock/**' pull_request: - branches: [ master ] + branches: [ main ] + paths: + - '.github/workflows/clock.yml' + - 'pkgs/clock/**' schedule: - cron: "0 0 * * 0" env: PUB_ENVIRONMENT: bot.github + +defaults: + run: + working-directory: pkgs/clock/ + jobs: # Check code formatting and static analysis on a single OS (linux) # against Dart dev. diff --git a/README.md b/README.md index ac4edf204..f7972895b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ don't naturally belong to other topic monorepos (like | --- | --- | --- | | [boolean_selector](pkgs/boolean_selector/) | A flexible syntax for boolean expressions, based on a simplified version of Dart's expression syntax. | [![pub package](https://img.shields.io/pub/v/boolean_selector.svg)](https://pub.dev/packages/boolean_selector) | | [cli_config](pkgs/cli_config/) | A library to take config values from configuration files, CLI arguments, and environment variables. | [![pub package](https://img.shields.io/pub/v/cli_config.svg)](https://pub.dev/packages/cli_config) | +| [clock](pkgs/clock/) | A fakeable wrapper for dart:core clock APIs. | [![pub package](https://img.shields.io/pub/v/clock.svg)](https://pub.dev/packages/clock) | | [coverage](pkgs/coverage/) | Coverage data manipulation and formatting. | [![pub package](https://img.shields.io/pub/v/coverage.svg)](https://pub.dev/packages/coverage) | | [extension_discovery](pkgs/extension_discovery/) | A convention and utilities for package extension discovery. | [![pub package](https://img.shields.io/pub/v/extension_discovery.svg)](https://pub.dev/packages/extension_discovery) | | [file](pkgs/file/) | A pluggable, mockable file system abstraction for Dart. | [![pub package](https://img.shields.io/pub/v/file.svg)](https://pub.dev/packages/file) | diff --git a/pkgs/clock/.github/dependabot.yml b/pkgs/clock/.github/dependabot.yml deleted file mode 100644 index cde02ad6a..000000000 --- a/pkgs/clock/.github/dependabot.yml +++ /dev/null @@ -1,15 +0,0 @@ -# Dependabot configuration file. -# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates -version: 2 - -updates: - - package-ecosystem: github-actions - directory: / - schedule: - interval: monthly - labels: - - autosubmit - groups: - github-actions: - patterns: - - "*" diff --git a/pkgs/clock/.github/workflows/no-response.yml b/pkgs/clock/.github/workflows/no-response.yml deleted file mode 100644 index ab1ac4984..000000000 --- a/pkgs/clock/.github/workflows/no-response.yml +++ /dev/null @@ -1,37 +0,0 @@ -# A workflow to close issues where the author hasn't responded to a request for -# more information; see https://github.com/actions/stale. - -name: No Response - -# Run as a daily cron. -on: - schedule: - # Every day at 8am - - cron: '0 8 * * *' - -# All permissions not specified are set to 'none'. -permissions: - issues: write - pull-requests: write - -jobs: - no-response: - runs-on: ubuntu-latest - if: ${{ github.repository_owner == 'dart-lang' }} - steps: - - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e - with: - # Don't automatically mark inactive issues+PRs as stale. - days-before-stale: -1 - # Close needs-info issues and PRs after 14 days of inactivity. - days-before-close: 14 - stale-issue-label: "needs-info" - close-issue-message: > - Without additional information we're not able to resolve this issue. - Feel free to add more info or respond to any questions above and we - can reopen the case. Thanks for your contribution! - stale-pr-label: "needs-info" - close-pr-message: > - Without additional information we're not able to resolve this PR. - Feel free to add more info or respond to any questions above. - Thanks for your contribution! diff --git a/pkgs/clock/.github/workflows/publish.yaml b/pkgs/clock/.github/workflows/publish.yaml deleted file mode 100644 index 27157a046..000000000 --- a/pkgs/clock/.github/workflows/publish.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# A CI configuration to auto-publish pub packages. - -name: Publish - -on: - pull_request: - branches: [ master ] - push: - tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] - -jobs: - publish: - if: ${{ github.repository_owner == 'dart-lang' }} - uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main - permissions: - id-token: write # Required for authentication using OIDC - pull-requests: write # Required for writing the pull request note diff --git a/pkgs/clock/CHANGELOG.md b/pkgs/clock/CHANGELOG.md index 76ab0c5c4..f372adaa1 100644 --- a/pkgs/clock/CHANGELOG.md +++ b/pkgs/clock/CHANGELOG.md @@ -1,6 +1,7 @@ -## 1.1.2-wip +## 1.1.2 * Require Dart 3.4 +* Move to `dart-lang/tools` monorepo. ## 1.1.1 diff --git a/pkgs/clock/README.md b/pkgs/clock/README.md index 2d29311a3..dccdc0755 100644 --- a/pkgs/clock/README.md +++ b/pkgs/clock/README.md @@ -1,4 +1,4 @@ -[![Dart CI](https://github.com/dart-lang/clock/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/clock/actions/workflows/test-package.yml) +[![Build Status](https://github.com/dart-lang/tools/actions/workflows/clock.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/clock.yaml) [![pub package](https://img.shields.io/pub/v/clock.svg)](https://pub.dev/packages/clock) [![package publisher](https://img.shields.io/pub/publisher/clock.svg)](https://pub.dev/packages/clock/publisher) diff --git a/pkgs/clock/pubspec.yaml b/pkgs/clock/pubspec.yaml index de2930323..2487fe778 100644 --- a/pkgs/clock/pubspec.yaml +++ b/pkgs/clock/pubspec.yaml @@ -1,5 +1,5 @@ name: clock -version: 1.1.2-wip +version: 1.1.2 description: A fakeable wrapper for dart:core clock APIs. repository: https://github.com/dart-lang/tools/tree/main/pkgs/clock