| 826 | * ``` |
| 827 | */ |
| 828 | export 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. |