parsedTime property

DateTime get parsedTime

The parsed time as a usable DateTime object.

This method is only useful for v1 UUIDs, because the time field has different semantics for other version.

Throws a StateError if variant is not UuidVariant.rfc4122 or version is not 1.

Implementation

DateTime get parsedTime {
  if (variant != UuidVariant.rfc4122) {
    throw StateError('Only available for RFC 4122 UUIDs');
  } else if (version != 1) {
    throw StateError('Only available for v1 UUIDs');
  }
  // time is the count of 100-nanosecond intervals
  // since 00:00:00.00, 15 October 1582.
  final referenceTime = DateTime.utc(1582, 10, 15);
  // 1000 nanoseconds are a microsecond.
  final microseconds = (time ~/ 10);
  final timeDuration = Duration(microseconds: microseconds);
  return referenceTime.add(timeDuration);
}