MCPcopy Create free account
hub / github.com/Effect-TS/effect / parts

Function parts

packages/effect/src/Duration.ts:1789–1836  ·  view source on GitHub ↗
(self: Duration)

Source from the content-addressed store, hash-verified

1787 * @since 3.8.0
1788 */
1789export const parts = (self: Duration): {
1790 days: number
1791 hours: number
1792 minutes: number
1793 seconds: number
1794 millis: number
1795 nanos: number
1796} => {
1797 if (self.value._tag === "Infinity") {
1798 return {
1799 days: Infinity,
1800 hours: Infinity,
1801 minutes: Infinity,
1802 seconds: Infinity,
1803 millis: Infinity,
1804 nanos: Infinity
1805 }
1806 }
1807 if (self.value._tag === "NegativeInfinity") {
1808 return {
1809 days: -Infinity,
1810 hours: -Infinity,
1811 minutes: -Infinity,
1812 seconds: -Infinity,
1813 millis: -Infinity,
1814 nanos: -Infinity
1815 }
1816 }
1817
1818 const n = toNanosUnsafe(self)
1819 const neg = n < bigint0
1820 const a = neg ? -n : n
1821 const ms = a / bigint1e6
1822 const sec = ms / bigint1e3
1823 const min = sec / bigint60
1824 const hr = min / bigint60
1825 const d = hr / bigint24
1826 const sign = neg ? -1 : 1
1827
1828 return {
1829 days: sign * Number(d),
1830 hours: sign * Number(hr % bigint24),
1831 minutes: sign * Number(min % bigint60),
1832 seconds: sign * Number(sec % bigint60),
1833 millis: sign * Number(ms % bigint1e3),
1834 nanos: sign * Number(a % bigint1e6)
1835 }
1836}
1837
1838/**
1839 * Converts a `Duration` to a human readable string.

Callers 1

formatFunction · 0.70

Calls 2

toNanosUnsafeFunction · 0.85
NumberFunction · 0.70

Tested by

no test coverage detected