Timestamp.fromMicrosecondsSinceEpoch constructor

Timestamp.fromMicrosecondsSinceEpoch(
  1. int microseconds
)

Creates a timestamp from a number of microseconds since the epoch, 1970-01-01T00:00:00Z (negative for earlier instants). Throws an ArgumentError outside the range of Timestamp.

Implementation

factory Timestamp.fromMicrosecondsSinceEpoch(int microseconds) {
  // Floor division, so that negative values keep non-negative nanoseconds.
  int seconds = microseconds ~/ 1000000;
  int nanoseconds = microseconds.remainder(1000000) * 1000;

  if (nanoseconds < 0) {
    seconds -= 1;
    nanoseconds += 1000000000;
  }

  _validateRange(seconds, nanoseconds);
  return Timestamp(seconds, nanoseconds);
}