GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Searching for packages
  • Package scoring and pub points
  • Using packages
  • Developing packages and plugins
  • Publishing a package
  • Using packages

This view

  • Original page
  • New address

GeezerVison is showing pub.dev — clock | Dart package

clock 1.1.3 copy "clock: ^1.1.3" to clipboard
clock: ^1.1.3 copied to clipboard

Published 3 months ago • verified publishertools.dart.dev
SDKDartFlutter
PlatformAndroidiOSLinuxmacOSwebWindows
260
→

Metadata

A fakeable wrapper for dart:core clock APIs.

More...

  • Readme
  • Changelog
  • Installing
  • Versions
  • Scores

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!'));
    });
  });
}
260
likes
140
points
17.3M
downloads

Documentation

API reference

Publisher

verified publishertools.dart.dev

Weekly Downloads

Metadata

A fakeable wrapper for dart:core clock APIs.

Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (license)

More

Packages that depend on clock

← Metadata

260
likes
140
points
17.3M
downloads

Documentation

API reference

Publisher

verified publishertools.dart.dev

Weekly Downloads

Metadata

A fakeable wrapper for dart:core clock APIs.

Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (license)

More

Packages that depend on clock

Back

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.