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

Function parts

packages/effect/src/Duration.ts:778–813  ·  view source on GitHub ↗
(self: DurationInput)

Source from the content-addressed store, hash-verified

776 * @category conversions
777 */
778export const parts = (self: DurationInput): {
779 days: number
780 hours: number
781 minutes: number
782 seconds: number
783 millis: number
784 nanos: number
785} => {
786 const duration = decode(self)
787 if (duration.value._tag === "Infinity") {
788 return {
789 days: Infinity,
790 hours: Infinity,
791 minutes: Infinity,
792 seconds: Infinity,
793 millis: Infinity,
794 nanos: Infinity
795 }
796 }
797
798 const nanos = unsafeToNanos(duration)
799 const ms = nanos / bigint1e6
800 const sec = ms / bigint1e3
801 const min = sec / bigint60
802 const hr = min / bigint60
803 const days = hr / bigint24
804
805 return {
806 days: Number(days),
807 hours: Number(hr % bigint24),
808 minutes: Number(min % bigint60),
809 seconds: Number(sec % bigint60),
810 millis: Number(ms % bigint1e3),
811 nanos: Number(nanos % bigint1e6)
812 }
813}
814
815/**
816 * Converts a `Duration` to a human readable string.

Callers 2

formatFunction · 0.85
unsafeFormatIsoFunction · 0.85

Calls 3

unsafeToNanosFunction · 0.85
NumberInterface · 0.85
decodeFunction · 0.70

Tested by

no test coverage detected