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

Use the clock package to help us create tests #169

Open
hbock-42 opened this issue Apr 24, 2023 · 0 comments
Open

Use the clock package to help us create tests #169

hbock-42 opened this issue Apr 24, 2023 · 0 comments

Comments

@hbock-42
Copy link

I find it might be interesting to use the 'clock' package from the Dart team to help us test our application.
They have a very interesting feature where you wrap your code inside a withClock, and you can set the time returned by Clock.now -> so if you use clock.now() instead of DateTime.now inside TZDatime, it is easy to write tests.

withClock(Clock.fixed(DateTime.parse('2000-04-24 13:00:00.000000')), () {
        final DateTime nowClock = clock.now();
        final nowParis = TZDateTime.now(getLocation('Europe/Paris'));
        print('TZLocatedNowWithClockOverride:${TZDateTime.from(nowClock, getLocation('Europe/Paris'))}');
        print('paris:$nowParis');
}

If you are in Paris, it currently, returns:

nowclock:2000-04-24 13:00:00.000
TZLocatedNowWithClockOverride:2000-04-24 13:00:00.000+0200
paris:2023-04-24 13:14:47.899249+0200

After the change, it would return:

nowclock:2000-04-24 13:00:00.000
TZLocatedNowWithClockOverride:2000-04-24 13:00:00.000+0200
paris:2000-04-24 13:00:00.000+0200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant