UuidV1Generator.fromLastUuid constructor

UuidV1Generator.fromLastUuid(
  1. Uuid uuid, {
  2. DateTime now() = DateTime.now,
})

Creates a new instance of a generator from a previously generated uuid.

Both Uuid.node and Uuid.clock are used.

If Uuid.time is ahead of now, the clock sequence is increased.

See: tools.ietf.org/html/rfc4122#section-4.2.1

Implementation

factory UuidV1Generator.fromLastUuid(
  Uuid uuid, {
  DateTime Function() now = DateTime.now,
}) {
  if (uuid.version != UuidVersion.v1) {
    throw ArgumentError.value(uuid.version, 'version', 'UUID is not v1');
  }
  var clockSequence = uuid.clock;
  if (uuid.time!.compareTo(now()) > 0) {
    clockSequence++;
    clockSequence &= 0x3fff;
  }
  return UuidV1Generator._(uuid.node, clockSequence, now);
}