(input: string, scale: bigint)
| 41 | const roundMillisToNanos = (millis: number): bigint => roundTiesAwayFromZero(millis * 1_000_000) |
| 42 | |
| 43 | const parseNanos = (input: string, scale: bigint): bigint => { |
| 44 | const decimalIndex = input.indexOf(".") |
| 45 | if (decimalIndex === -1) return BigInt(input) * scale |
| 46 | |
| 47 | const isNegative = input[0] === "-" |
| 48 | const fractional = input.slice(decimalIndex + 1) |
| 49 | const fractionalScale = bigint10 ** BigInt(fractional.length) |
| 50 | const scaled = ( |
| 51 | BigInt(input.slice(isNegative ? 1 : 0, decimalIndex)) * fractionalScale + BigInt(fractional) |
| 52 | ) * scale |
| 53 | const rounded = scaled / fractionalScale + |
| 54 | (scaled % fractionalScale * bigint2 >= fractionalScale ? bigint1 : bigint0) |
| 55 | return isNegative ? -rounded : rounded |
| 56 | } |
| 57 | |
| 58 | const nanosToHrTime = (nanos: bigint): [seconds: number, nanos: number] => { |
| 59 | const sign = nanos < bigint0 ? -bigint1 : bigint1 |
no test coverage detected