MCPcopy Create free account
hub / github.com/dfinity/orbit / fromTimeUnit

Function fromTimeUnit

apps/wallet/src/mappers/time.mapper.ts:50–72  ·  view source on GitHub ↗
(units: number, unit: TimeUnit)

Source from the content-addressed store, hash-verified

48 * Important: This function may lose precision when converting from a floating number when using the smallest unit.
49 */
50export 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};

Callers 1

Calls 1

unreachableFunction · 0.90

Tested by

no test coverage detected