Private/Get-PrismRequestTimeout.ps1

function Get-PrismRequestTimeout {
    <#
    .SYNOPSIS
        Caps an HTTP timeout at the remaining time in a shared request deadline.
    .DESCRIPTION
        PowerShell HTTP timeouts use whole seconds. Round up to avoid passing zero
        (an unlimited timeout); HTTP cancellation can consequently overshoot by
        less than one second, plus transport/DNS and scheduling overhead.
 
        When called from a catch block, pass the caught exception as -InnerException
        so an expired deadline does not hide the error that consumed the budget.
    #>

    [CmdletBinding()]
    [OutputType([int])]
    param(
        [Parameter()][Nullable[DateTimeOffset]]$Deadline,
        [Parameter()][Exception]$InnerException
    )

    if ($null -eq $Deadline) { return 100 }
    $remainingSeconds = ($Deadline - [DateTimeOffset]::UtcNow).TotalSeconds
    if ($remainingSeconds -le 0) {
        $message = 'The Prism request deadline has expired.'
        if ($null -ne $InnerException) {
            throw [TimeoutException]::new("$message Last error: $($InnerException.Message)", $InnerException)
        }
        throw [TimeoutException]::new($message)
    }
    return [int][math]::Ceiling([math]::Min(100.0, $remainingSeconds))
}