(units: number, unit: TimeUnit)
| 48 | * Important: This function may lose precision when converting from a floating number when using the smallest unit. |
| 49 | */ |
| 50 | export const fromTimeUnit = (units: number, unit: TimeUnit): bigint => { |
| 51 | switch (unit) { |
| 52 | case TimeUnit.Years: { |
| 53 | return BigInt(units * Number(YEAR_IN_SECONDS)); |
| 54 | } |
| 55 | case TimeUnit.Months: { |
| 56 | return BigInt(units * Number(MONTH_IN_SECONDS)); |
| 57 | } |
| 58 | case TimeUnit.Days: { |
| 59 | return BigInt(units * Number(DAY_IN_SECONDS)); |
| 60 | } |
| 61 | case TimeUnit.Hours: { |
| 62 | return BigInt(units * Number(HOUR_IN_SECONDS)); |
| 63 | } |
| 64 | case TimeUnit.Minutes: { |
| 65 | return BigInt(units * Number(MINUTE_IN_SECONDS)); |
| 66 | } |
| 67 | case TimeUnit.Seconds: |
| 68 | return BigInt(Math.floor(units)); |
| 69 | default: |
| 70 | return unreachable(unit); |
| 71 | } |
| 72 | }; |
no test coverage detected