Skip to content

Commit a52767c

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 0608f52 commit a52767c

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
@@ -120,6 +120,11 @@ abstract class ZulipBinding {
120120
/// This wraps [url_launcher.closeInAppWebView].
121121
Future<void> closeInAppWebView();
122122

123+
/// Provides access to the current UTC date and time.
124+
///
125+
/// Outside tests, this just calls [DateTime.timestamp].
126+
DateTime utcNow();
127+
123128
/// Provides access to a new stopwatch.
124129
///
125130
/// Outside tests, this just calls the [Stopwatch] constructor.
@@ -383,6 +388,9 @@ class LiveZulipBinding extends ZulipBinding {
383388
return url_launcher.closeInAppWebView();
384389
}
385390

391+
@override
392+
DateTime utcNow() => DateTime.timestamp();
393+
386394
@override
387395
Stopwatch stopwatch() => Stopwatch();
388396

test/model/binding.dart

+3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ class TestZulipBinding extends ZulipBinding {
241241
_closeInAppWebViewCallCount++;
242242
}
243243

244+
@override
245+
DateTime utcNow() => clock.now().toUtc();
246+
244247
@override
245248
Stopwatch stopwatch() => clock.stopwatch();
246249

0 commit comments

Comments
 (0)