* Calculate what fraction of a time window has elapsed. * Used for time-relative early warning fallback. * @param resetsAt - Unix epoch timestamp in seconds when the limit resets * @param windowSeconds - Duration of the window in seconds * @returns fraction (0-1) of the window that has elapsed
(resetsAt: number, windowSeconds: number)
| 96 | * @returns fraction (0-1) of the window that has elapsed |
| 97 | */ |
| 98 | function computeTimeProgress(resetsAt: number, windowSeconds: number): number { |
| 99 | const nowSeconds = Date.now() / 1000 |
| 100 | const windowStart = resetsAt - windowSeconds |
| 101 | const elapsed = nowSeconds - windowStart |
| 102 | return Math.max(0, Math.min(1, elapsed / windowSeconds)) |
| 103 | } |
| 104 | |
| 105 | // Reason why overage is disabled/rejected |
| 106 | // These values come from the API's unified limiter |
no test coverage detected