@somnia-chain/markets-sdk / index / snapIntervalSec
Function: snapIntervalSec()
snapIntervalSec(
sec,toleranceSec?):number
Defined in: packages/sdk/src/interval.ts:60
Snap a raw cadence (seconds) to its nearest natural unit — minute (< 1h),
hour (< 1d), else day — but ONLY when the raw value sits within
toleranceSec of that unit, i.e. it is genuine off-by-a-second jitter
(899 → 900, 3601 → 3600, 86399 → 86400). A value further than the tolerance
from any unit is a real partial / non-standard window and is returned
UNCHANGED, never bucketed up: 840 → 840 ("14m"), 870 → 870 ("14m30s" is
not clean, so → "870s"), 5400 → 5400 ("90m"), 86100 → 86100 (23h55m,
NOT "24h"). Because a series-registered market carries an EXACT on-chain
intervalSec, the snap is a no-op on real cadences; the tolerance only
matters on the expiry − tradingStart fallback path. Non-positive → 0.
Parameters
sec
number
toleranceSec?
number = 2
Returns
number