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

Function parts

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

Source from the content-addressed store, hash-verified

1640 * @since 3.8.0
1641 */
1642export const parts = (self: Duration): {
1643 days: number
1644 hours: number
1645 minutes: number
1646 seconds: number
1647 millis: number
1648 nanos: number
1649} => {
1650 if (self.value._tag === "Infinity") {
1651 return {
1652 days: Infinity,
1653 hours: Infinity,
1654 minutes: Infinity,
1655 seconds: Infinity,
1656 millis: Infinity,
1657 nanos: Infinity
1658 }
1659 }
1660 if (self.value._tag === "NegativeInfinity") {
1661 return {
1662 days: -Infinity,
1663 hours: -Infinity,
1664 minutes: -Infinity,
1665 seconds: -Infinity,
1666 millis: -Infinity,
1667 nanos: -Infinity
1668 }
1669 }
1670
1671 const n = toNanosUnsafe(self)
1672 const neg = n < bigint0
1673 const a = neg ? -n : n
1674 const ms = a / bigint1e6
1675 const sec = ms / bigint1e3
1676 const min = sec / bigint60
1677 const hr = min / bigint60
1678 const d = hr / bigint24
1679 const sign = neg ? -1 : 1
1680
1681 return {
1682 days: sign * Number(d),
1683 hours: sign * Number(hr % bigint24),
1684 minutes: sign * Number(min % bigint60),
1685 seconds: sign * Number(sec % bigint60),
1686 millis: sign * Number(ms % bigint1e3),
1687 nanos: sign * Number(a % bigint1e6)
1688 }
1689}
1690
1691/**
1692 * Converts a `Duration` to a human readable string.

Callers 1

formatFunction · 0.85

Calls 2

toNanosUnsafeFunction · 0.85
NumberInterface · 0.70

Tested by

no test coverage detected