p-hatan/ mirror

pub repository

mirror.p-hatan.ir

clock

1.1.0-nullsafety.1

A fakeable wrapper for dart:core clock APIs

Download archive

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.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 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.ir
flutter pub add clock
pubspec.yaml
name: clock
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.11.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

Version history

VersionPublishedArchiveSHA-256
0.0.12014-10-06T21:38:23.370380ZDownload976bd3c33b1eb7a62750e73af0c4e3cd9c3d57bcf6ba89bfb960723ce44e43f6
0.1.02014-10-07T16:01:49.532160ZDownload6c93f80f9f1dae4d70bf20677a2fbb381a39d90bc4e8cda00c16acee57ee6ce8
0.1.12014-10-07T16:09:38.998930ZDownload41b5892c780206977cb9962be27261465939eda9278b528f65ec5f6586c7b494
0.1.22014-10-07T16:46:14.571780ZDownload287a1e6fc9a7e07bb749656710842c77e313e77bee39e120c054c8822ecb1642
1.0.02018-05-01T23:14:34.600091ZDownload83474092a00c76435490ad92a6430b48392d812164083a815fdac6ba23f1e4e0
1.0.12018-07-14T00:02:16.153774ZDownloada0c95fc69a08429cabc100307849b357daf6833cf818208a5c7b458958dd568c
1.1.0-nullsafety2020-07-29T17:45:24.662300ZDownloadb130f8fd9f6986f19571463c60b51ffafc146fffae28ff819c4f6d2c5e71f94a
1.1.0-nullsafety.12020-09-22T16:58:26.079810ZDownload5bf99f5ee9a71f68e075c36411321c6478c4b82da334b10dd570515f479adc1d
1.1.0-nullsafety.22020-10-23T21:31:40.285590ZDownloadc913d7935e67117d8e325c9d379f4ba32b510491ee9adf3f7cd7584f334419ca
1.1.0-nullsafety.32020-11-03T22:40:57.449744ZDownload477d51891fcd21264e98e3909166af917e360c08053cda43d2f31a2498f22464
1.1.02021-02-02T19:36:56.889689ZDownload6021e0172ab6e6eaa1d391afed0a99353921f00c54385c574dc53e55d67c092c
1.1.12022-06-16T01:04:53.130936ZDownloadcb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
1.1.22024-10-28T08:20:37.591570ZDownloadfddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
1.1.32026-08-28T20:42:07.361034ZDownloade51d50bca3217c9a9fa2b41a30e4a38971133f5f9ec7a3d57bae095007f1d28e

Dependencies

No direct dependencies declared.