Skip to content

otplib API Documentation / @otplib/totp / getRemainingTime

Function: getRemainingTime()

getRemainingTime(time, period, t0, guardrails): number

Defined in: totp/src/index.ts:348

Get the remaining time until the next TOTP period

Parameters

time

number = ...

Current Unix timestamp in seconds (default: now)

period

number = 30

Time step in seconds (default: 30)

t0

number = 0

Initial Unix time to start counting time steps (default: 0)

guardrails

OTPGuardrails = ...

Returns

number

Remaining seconds until next period

Example

ts
import { getRemainingTime } from '@otplib/totp';

const remaining = getRemainingTime();
// Returns: 15 (seconds remaining in current 30-second window)

Released under the MIT License.