MCPcopy Index your code
hub / github.com/Effect-TS/effect / format

Function format

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

Source from the content-addressed store, hash-verified

817 * ```
818 */
819export const format = (self: DurationInput): string => {
820 const duration = decode(self)
821 if (duration.value._tag === "Infinity") {
822 return "Infinity"
823 }
824 if (isZero(duration)) {
825 return "0"
826 }
827
828 const fragments = parts(duration)
829 const pieces = []
830 if (fragments.days !== 0) {
831 pieces.push(`${fragments.days}d`)
832 }
833
834 if (fragments.hours !== 0) {
835 pieces.push(`${fragments.hours}h`)
836 }
837
838 if (fragments.minutes !== 0) {
839 pieces.push(`${fragments.minutes}m`)
840 }
841
842 if (fragments.seconds !== 0) {
843 pieces.push(`${fragments.seconds}s`)
844 }
845
846 if (fragments.millis !== 0) {
847 pieces.push(`${fragments.millis}ms`)
848 }
849
850 if (fragments.nanos !== 0) {
851 pieces.push(`${fragments.nanos}ns`)
852 }
853
854 return pieces.join(" ")
855}
856
857/**
858 * Formats a Duration into an ISO8601 duration string.

Callers 1

toStringFunction · 0.70

Calls 4

partsFunction · 0.85
decodeFunction · 0.70
isZeroFunction · 0.70
joinMethod · 0.65

Tested by

no test coverage detected