p-hatan/ mirror

pub repository

mirror.p-hatan.com

clock

1.1.3

A fakeable wrapper for dart:core clock APIs.

Cached in Iran · upstream_checksum

Download archive

Readme

Build Status pub package package 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 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.3

  • Keep microseconds when using monthsAgo, monthsFromNow and yearsAgo

1.1.2

  • Require Dart 3.4
  • Move to dart-lang/tools monorepo.

1.1.1

  • Switch to using package:lints.
  • Populate the pubspec repository field.

1.1.0

  • Update SDK constraints to >=2.12.0 <3.0.0.
  • 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 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.

Changes Relative to clock 0.1

  • The top-level new getter and getStopwatch() methods are deprecated. clock.new() and clock.stopwatch() 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.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add clock
pubspec.yaml
name: clock
version: 1.1.3
description: A fakeable wrapper for dart:core clock APIs.
repository: https://github.com/dart-lang/tools/tree/main/pkgs/clock
issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aclock

environment:
  sdk: ^3.4.0

dev_dependencies:
  dart_flutter_team_lints: ^3.0.0
  test: ^1.16.6

Version history

VersionPublishedArchiveSHA-256
0.0.12014-10-06T21:38:23.370380ZCached976bd3c33b1eb7a62750e73af0c4e3cd9c3d57bcf6ba89bfb960723ce44e43f6
0.1.02014-10-07T16:01:49.532160ZCached6c93f80f9f1dae4d70bf20677a2fbb381a39d90bc4e8cda00c16acee57ee6ce8
0.1.12014-10-07T16:09:38.998930ZCached41b5892c780206977cb9962be27261465939eda9278b528f65ec5f6586c7b494
0.1.22014-10-07T16:46:14.571780ZCached287a1e6fc9a7e07bb749656710842c77e313e77bee39e120c054c8822ecb1642
1.0.02018-05-01T23:14:34.600091ZCached83474092a00c76435490ad92a6430b48392d812164083a815fdac6ba23f1e4e0
1.0.12018-07-14T00:02:16.153774ZCacheda0c95fc69a08429cabc100307849b357daf6833cf818208a5c7b458958dd568c
1.1.0-nullsafety2020-07-29T17:45:24.662300ZCachedb130f8fd9f6986f19571463c60b51ffafc146fffae28ff819c4f6d2c5e71f94a
1.1.0-nullsafety.12020-09-22T16:58:26.079810ZCached5bf99f5ee9a71f68e075c36411321c6478c4b82da334b10dd570515f479adc1d
1.1.0-nullsafety.22020-10-23T21:31:40.285590ZCachedc913d7935e67117d8e325c9d379f4ba32b510491ee9adf3f7cd7584f334419ca
1.1.0-nullsafety.32020-11-03T22:40:57.449744ZCached477d51891fcd21264e98e3909166af917e360c08053cda43d2f31a2498f22464
1.1.02021-02-02T19:36:56.889689ZCached6021e0172ab6e6eaa1d391afed0a99353921f00c54385c574dc53e55d67c092c
1.1.12022-06-16T01:04:53.130936ZCachedcb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
1.1.22024-10-28T08:20:37.591570ZCachedfddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
1.1.32026-08-28T20:42:07.361034ZCachede51d50bca3217c9a9fa2b41a30e4a38971133f5f9ec7a3d57bae095007f1d28e

Dependencies

No direct dependencies declared.