timestamp property

DateTime get timestamp

Returns the generation date (accurate up to the second) that this ObjectId was generated.

Implementation

DateTime get timestamp {
  if (_timestamp != null) return _timestamp!;

  var secondsSinceEpoch = 0;
  for (var x = 3, y = 0; x >= 0; x--, y++) {
    secondsSinceEpoch += _bytes[x] * math.pow(256, y).toInt();
  }

  return _timestamp = DateTime.fromMillisecondsSinceEpoch(
    secondsSinceEpoch * 1000,
  );
}