Skip to content

Commit e3bac3a

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 db08953 commit e3bac3a

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.
@@ -381,6 +386,9 @@ class LiveZulipBinding extends ZulipBinding {
381386
return url_launcher.closeInAppWebView();
382387
}
383388

389+
@override
390+
DateTime utcNow() => DateTime.timestamp();
391+
384392
@override
385393
Stopwatch stopwatch() => Stopwatch();
386394

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)