| 16 | if (!match) return -1; |
| 17 | |
| 18 | const value = parseInt(match[1]); |
| 19 | const unit = match[2]?.toLowerCase() || 's'; |
| 20 | |
| 21 | const multipliers: Record<string, number> = { |
| 22 | 's': 1, |
| 23 | 'm': 60, |
| 24 | 'h': 3600, |
| 25 | 'd': 86400 |
| 26 | }; |
| 27 | |
| 28 | return value * (multipliers[unit] || 1); |
| 29 | }; |
| 30 | |
| 31 | // Timer tracking for safe cleanup |
| 32 | const pendingTimers = new Set<ReturnType<typeof setTimeout>>(); |
| 33 | |
| 34 | function scheduleTimer(fn: () => void, ms: number): ReturnType<typeof setTimeout> { |
| 35 | const t = setTimeout(() => { |
| 36 | pendingTimers.delete(t); |