mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Fix OverflowException when estimating the progress remaining time (#404)
Fix OverflowException when estimating the progress remaining time
This commit is contained in:
@ -286,20 +286,20 @@ namespace Spectre.Console
|
||||
}
|
||||
|
||||
var speed = GetSpeed();
|
||||
if (speed == null)
|
||||
if (speed == null || speed == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// If the speed is zero, the estimate below
|
||||
// will return infinity (since it's a double),
|
||||
// so let's set the speed to 1 in that case.
|
||||
if (speed == 0)
|
||||
// If the speed is near zero, the estimate below causes the
|
||||
// TimeSpan creation to throw an OverflowException. Just return
|
||||
// the maximum possible remaining time instead of overflowing.
|
||||
var estimate = (MaxValue - Value) / speed.Value;
|
||||
if (estimate > TimeSpan.MaxValue.TotalSeconds)
|
||||
{
|
||||
speed = 1;
|
||||
return TimeSpan.MaxValue;
|
||||
}
|
||||
|
||||
var estimate = (MaxValue - Value) / speed.Value;
|
||||
return TimeSpan.FromSeconds(estimate);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user