pub repository
mirror.p-hatan.irclock
1.1.0-nullsafety.2A fakeable wrapper for dart:core clock APIs
Readme
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 Clocks 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.
For example, you can use clock in your libraries like this:
// run_with_timing.dart
import 'package:clock/clock.dart';
/// Runs [callback] and prints how long it took.
T runWithTiming<T>(T Function() callback) {
var stopwatch = clock.stopwatch()..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:
// 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', () {
FakeAsync().run((async) {
expect(() {
runWithTiming(() {
async.elapse(Duration(seconds: 10));
});
}, prints('It took 0:00:10.000000!'));
});
});
}
Changelog
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 to null safety.
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
backwards-compatible with the quiver version, and mostly
backwards-compatible with the old version of the clock package.
New Features
-
A top-level
clockfield has been added that provides a defaultClockimplementation. It can be controlled by thewithClock()function. It should generally be used in preference to manual dependency-injection, since it will work with thefake_asyncpackage. -
A
Clock.stopwatch()method has been added that creates aStopwatchthat uses the clock as its source of time.
Changes Relative to clock 0.1
-
The top-level
newgetter andgetStopwatch()methods are deprecated.clock.new()andclock.stopwatch()should be used instead. -
Clock.getStopwatch()is deprecated.Clock.stopwatch()should be used instead. -
The
isFinalargument towithClock()is deprecated. -
new Clock()now takes an optional positional argument that returns the current time as aDateTimeinstead of its old arguments. -
Clock.now()is now a method rather than a getter.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add clockpubspec.yaml
name: clock
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.12.0'
dev_dependencies:
test: ^1.16.0-nullsafety
pedantic: ^1.10.0-nullsafety
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2014-10-06T21:38:23.370380Z | Download | 976bd3c33b1eb7a62750e73af0c4e3cd9c3d57bcf6ba89bfb960723ce44e43f6 |
| 0.1.0 | 2014-10-07T16:01:49.532160Z | Download | 6c93f80f9f1dae4d70bf20677a2fbb381a39d90bc4e8cda00c16acee57ee6ce8 |
| 0.1.1 | 2014-10-07T16:09:38.998930Z | Download | 41b5892c780206977cb9962be27261465939eda9278b528f65ec5f6586c7b494 |
| 0.1.2 | 2014-10-07T16:46:14.571780Z | Download | 287a1e6fc9a7e07bb749656710842c77e313e77bee39e120c054c8822ecb1642 |
| 1.0.0 | 2018-05-01T23:14:34.600091Z | Download | 83474092a00c76435490ad92a6430b48392d812164083a815fdac6ba23f1e4e0 |
| 1.0.1 | 2018-07-14T00:02:16.153774Z | Download | a0c95fc69a08429cabc100307849b357daf6833cf818208a5c7b458958dd568c |
| 1.1.0-nullsafety | 2020-07-29T17:45:24.662300Z | Download | b130f8fd9f6986f19571463c60b51ffafc146fffae28ff819c4f6d2c5e71f94a |
| 1.1.0-nullsafety.1 | 2020-09-22T16:58:26.079810Z | Download | 5bf99f5ee9a71f68e075c36411321c6478c4b82da334b10dd570515f479adc1d |
| 1.1.0-nullsafety.2 | 2020-10-23T21:31:40.285590Z | Download | c913d7935e67117d8e325c9d379f4ba32b510491ee9adf3f7cd7584f334419ca |
| 1.1.0-nullsafety.3 | 2020-11-03T22:40:57.449744Z | Download | 477d51891fcd21264e98e3909166af917e360c08053cda43d2f31a2498f22464 |
| 1.1.0 | 2021-02-02T19:36:56.889689Z | Download | 6021e0172ab6e6eaa1d391afed0a99353921f00c54385c574dc53e55d67c092c |
| 1.1.1 | 2022-06-16T01:04:53.130936Z | Download | cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf |
| 1.1.2 | 2024-10-28T08:20:37.591570Z | Download | fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b |
| 1.1.3 | 2026-08-28T20:42:07.361034Z | Download | e51d50bca3217c9a9fa2b41a30e4a38971133f5f9ec7a3d57bae095007f1d28e |
Dependencies
No direct dependencies declared.