readDateTime method

DateTime readDateTime()

Reads a DateTime value. Supports both ISO 8601 and UNIX second and millisecond timestamps.

Implementation

DateTime readDateTime() {
  final start = _offset;
  final value = read();
  if (value is String) {
    return DateTime.parse(value);
  } else if (value is num) {
    if (value > 20000000000) {
      return DateTime.fromMillisecondsSinceEpoch(value.toInt());
    } else {
      return DateTime.fromMillisecondsSinceEpoch(value.toInt() * 1000);
    }
  } else {
    _error(start, expected: 'DateTime');
  }
}