fix: handle NaN in build time estimate (#5679)

This commit is contained in:
Presley Pizzo
2023-01-11 15:56:21 -05:00
committed by GitHub
parent c0d9e32300
commit 1df72ee093
2 changed files with 10 additions and 2 deletions
@@ -67,3 +67,9 @@ StartingHighVariaton.args = {
...Starting.args,
transitionStats: { P50: 10000, P95: 20000 },
}
export const StartingZeroEstimate = Template.bind({})
StartingZeroEstimate.args = {
...Starting.args,
transitionStats: { P50: 0, P95: 0 },
}
@@ -34,11 +34,13 @@ const estimateFinish = (
p95: number,
): [number | undefined, string] => {
const sinceStart = dayjs().diff(startedAt)
const secondsLeft = (est: number) =>
Math.max(
const secondsLeft = (est: number) => {
const max = Math.max(
Math.ceil(dayjs.duration((1 - sinceStart / est) * est).asSeconds()),
0,
)
return isNaN(max) ? 0 : max
}
const lowGuess = secondsLeft(p50)
const highGuess = secondsLeft(p95)