Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make _RelativeClock extends _SystemClock #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions lib/src/relative_clock.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@

part of clock;

typedef Duration _Elapsed();

class _RelativeClock implements Clock {

class _RelativeClock implements _SystemClock {
final DateTime _initialTime;
final _Elapsed _elapsed;
final int _frequency;

_RelativeClock({
DateTime initialTime,
Duration elapsed(),
int frequency: 1000000
})
: _initialTime = initialTime == null ? _zonedClock.value.now : initialTime,

_RelativeClock(
{DateTime initialTime, Duration elapsed(), int frequency: 1000000})
: _initialTime =
initialTime == null ? _zonedClock.value.now : initialTime,
_elapsed = elapsed == null ? (() => Duration.ZERO) : elapsed,
_frequency = frequency;

DateTime get now => _initialTime.add(_elapsed());
Stopwatch getStopwatch() => new FakeStopwatch(() =>
_elapsed().inMicroseconds * _frequency ~/ 1000000, _frequency);
Stopwatch getStopwatch() => new FakeStopwatch(
() => _elapsed().inMicroseconds * _frequency ~/ 1000000, _frequency);
}