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

Function format

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

Source from the content-addressed store, hash-verified

826 * ```
827 */
828export const format = (self: DurationInput): string => {
829 const duration = decode(self)
830 if (duration.value._tag === "Infinity") {
831 return "Infinity"
832 }
833 if (isZero(duration)) {
834 return "0"
835 }
836
837 const fragments = parts(duration)
838 const pieces = []
839 if (fragments.days !== 0) {
840 pieces.push(`${fragments.days}d`)
841 }
842
843 if (fragments.hours !== 0) {
844 pieces.push(`${fragments.hours}h`)
845 }
846
847 if (fragments.minutes !== 0) {
848 pieces.push(`${fragments.minutes}m`)
849 }
850
851 if (fragments.seconds !== 0) {
852 pieces.push(`${fragments.seconds}s`)
853 }
854
855 if (fragments.millis !== 0) {
856 pieces.push(`${fragments.millis}ms`)
857 }
858
859 if (fragments.nanos !== 0) {
860 pieces.push(`${fragments.nanos}ns`)
861 }
862
863 return pieces.join(" ")
864}
865
866/**
867 * 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