| 817 | * ``` |
| 818 | */ |
| 819 | export 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. |