capture static method

Future<ServerTimeClock?> capture(
  1. Object? raw
)

Implementation

static Future<ServerTimeClock?> capture(Object? raw) async {
  final epoch = switch (raw) {
    int value => value,
    String value => int.tryParse(value.trim()),
    _ => null,
  };
  // Timer instants use four-digit years; keep elapsed-time arithmetic in that range.
  if (epoch == null || epoch <= 0 || epoch > 253402300799999) return null;
  final clock = ServerTimeClock._(epoch);
  if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
    final nativeNow = await _nativeElapsedMilliseconds();
    if (nativeNow == null) return null;
    clock._nativeAnchorMs = nativeNow - clock._elapsed.elapsedMilliseconds;
  }
  return clock;
}