public static DateTime? ForecastEndDate(this DateTime? startDate, DateTime now, decimal? progress)
{
if (progress == null || progress.Value <= 0.01m || progress.Value >= 1m || startDate == null || startDate > now)
{
return null;
}
if (progress <= 0.1m)
{
return null;
}
TimeSpan passedDuration = now - startDate.Value;
if (passedDuration.TotalDays <= 7)
{
return null;
}
decimal stepInMs = (decimal) (passedDuration.TotalMilliseconds * 0.01) / progress.Value;
decimal forecastDurationInMs = stepInMs * (1 - progress.Value) * 100;
TimeSpan forecastDuration = TimeSpan.FromMilliseconds((long) Math.Ceiling(forecastDurationInMs));
DateTime predictedEndDate = now + forecastDuration;
return predictedEndDate;
}