Skip to content

Commit d5ce060

Browse files
committed
binding [nfc]: Add utcNow
This will be the same as `DateTime.timestamp()` in live code (therefore the NFC). For testing, utcNow uses a clock instance that can be controlled by FakeAsync. We could have made call sites of `DateTime.now()` use it too, but those for now don't need it for testing.
1 parent 2944095 commit d5ce060

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/model/binding.dart

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ abstract class ZulipBinding {
113113
/// This wraps [url_launcher.closeInAppWebView].
114114
Future<void> closeInAppWebView();
115115

116+
/// Provides access to the current UTC date and time.
117+
///
118+
/// Outside tests, this just calls [DateTime.timestamp].
119+
DateTime utcNow();
120+
116121
/// Provides access to a new stopwatch.
117122
///
118123
/// Outside tests, this just calls the [Stopwatch] constructor.
@@ -365,6 +370,9 @@ class LiveZulipBinding extends ZulipBinding {
365370
return url_launcher.closeInAppWebView();
366371
}
367372

373+
@override
374+
DateTime utcNow() => DateTime.timestamp();
375+
368376
@override
369377
Stopwatch stopwatch() => Stopwatch();
370378

test/model/binding.dart

+3
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ class TestZulipBinding extends ZulipBinding {
238238
_closeInAppWebViewCallCount++;
239239
}
240240

241+
@override
242+
DateTime utcNow() => clock.now().toUtc();
243+
241244
@override
242245
Stopwatch stopwatch() => clock.stopwatch();
243246

0 commit comments

Comments
 (0)