(input: Input)
| 273 | * @since 4.0.0 |
| 274 | */ |
| 275 | export const fromInputUnsafe = (input: Input): Duration => { |
| 276 | switch (typeof input) { |
| 277 | case "number": |
| 278 | return millis(input) |
| 279 | case "bigint": |
| 280 | return nanos(input) |
| 281 | case "string": { |
| 282 | if (input === "Infinity") { |
| 283 | return infinity |
| 284 | } |
| 285 | if (input === "-Infinity") { |
| 286 | return negativeInfinity |
| 287 | } |
| 288 | const match = DURATION_REGEXP.exec(input) |
| 289 | if (!match) break |
| 290 | const [_, valueStr, unit] = match |
| 291 | if (unit === "nano" || unit === "nanos") { |
| 292 | return nanos(parseNanos(valueStr, bigint1)) |
| 293 | } |
| 294 | if (unit === "micro" || unit === "micros") { |
| 295 | return nanos(parseNanos(valueStr, bigint1e3)) |
| 296 | } |
| 297 | switch (unit) { |
| 298 | case "milli": |
| 299 | case "millis": |
| 300 | return fromMillisString(valueStr, 1) |
| 301 | case "second": |
| 302 | case "seconds": |
| 303 | return fromMillisString(valueStr, 1_000) |
| 304 | case "minute": |
| 305 | case "minutes": |
| 306 | return fromMillisString(valueStr, 60_000) |
| 307 | case "hour": |
| 308 | case "hours": |
| 309 | return fromMillisString(valueStr, 3_600_000) |
| 310 | case "day": |
| 311 | case "days": |
| 312 | return fromMillisString(valueStr, 86_400_000) |
| 313 | case "week": |
| 314 | case "weeks": |
| 315 | return fromMillisString(valueStr, 604_800_000) |
| 316 | } |
| 317 | break |
| 318 | } |
| 319 | case "object": { |
| 320 | if (input === null) break |
| 321 | if (TypeId in input) return input as Duration |
| 322 | if (Array.isArray(input)) { |
| 323 | if (input.length !== 2 || !input.every(isNumber)) { |
| 324 | return invalid(input) |
| 325 | } |
| 326 | if (Number.isNaN(input[0]) || Number.isNaN(input[1])) { |
| 327 | return zero |
| 328 | } |
| 329 | if (input[0] === -Infinity || input[1] === -Infinity) { |
| 330 | return negativeInfinity |
| 331 | } |
| 332 | if (input[0] === Infinity || input[1] === Infinity) { |
no test coverage detected