increment method
Increments the current timestamp for transmission to another system.
The local wall time will be used if wallTime
isn't supplied.
Implementation
Hlc increment({DateTime? wallTime}) {
// Retrieve the local wall time if millis is null
wallTime = (wallTime ?? DateTime.now()).toUtc();
// Calculate the next time and counter
// * ensure that the logical time never goes backward
// * increment the counter if time does not advance
final dateTimeNew = wallTime.isAfter(dateTime) ? wallTime : dateTime;
final counterNew = dateTimeNew == dateTime ? counter + 1 : 0;
// Check the result for drift and counter overflow
if (dateTimeNew.difference(wallTime) > _maxDrift) {
throw ClockDriftException(dateTimeNew, wallTime);
}
if (counterNew > _maxCounter) {
throw OverflowException(counterNew);
}
return Hlc(dateTimeNew, counterNew, nodeId);
}