(value: number | string | null)
| 43 | |
| 44 | /** Parses an interval value into seconds. */ |
| 45 | export function parseInterval(value: number | string | null): number | null { |
| 46 | let result: number; |
| 47 | |
| 48 | if (value === null) { |
| 49 | return null; |
| 50 | } else if (typeof value === 'number') { |
| 51 | result = value; |
| 52 | } else { |
| 53 | if (value.trim().length === 0) { |
| 54 | return null; |
| 55 | } |
| 56 | |
| 57 | const parsed = value.match(INTERVAL_PATTERN); |
| 58 | const amount = parsed ? parseFloat(parsed[1]) : null; |
| 59 | const unit = parsed?.[2]?.toLowerCase() || null; |
| 60 | |
| 61 | if (!parsed || amount === null || isNaN(amount)) { |
| 62 | return null; |
| 63 | } |
| 64 | |
| 65 | if (unit === 'h' || unit === 'hour' || unit === 'hours') { |
| 66 | result = amount * 3600; |
| 67 | } else if (unit === 'm' || unit === 'min' || unit === 'minute' || unit === 'minutes') { |
| 68 | result = amount * 60; |
| 69 | } else { |
| 70 | result = amount; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return result; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Generates the options to show in a timepicker. |
no outgoing calls
no test coverage detected
searching dependent graphs…