|
80 | 80 | process { |
81 | 81 | $TotalMilliseconds = $TimeSpan.TotalMilliseconds |
82 | 82 |
|
83 | | - # Handle zero timespan |
84 | 83 | if ($TotalMilliseconds -eq 0) { |
85 | | - "0$SecondLabel" |
| 84 | + # Handle zero timespan |
| 85 | + $Output = "0$SecondLabel" |
| 86 | + |
86 | 87 | } elseif ($TotalMilliseconds -lt 1) { |
87 | | - "{0:N2}$MicrosecondLabel" -f ($TotalMilliseconds * 1000) |
| 88 | + $Output = "{0:N2}$MicrosecondLabel" -f ($TotalMilliseconds * 1000) |
| 89 | + |
88 | 90 | } elseif ($TotalMilliseconds -lt 1000) { |
89 | | - "{0:N2}$MillisecondLabel" -f $TotalMilliseconds |
| 91 | + $Output = "{0:N2}$MillisecondLabel" -f $TotalMilliseconds |
| 92 | + |
90 | 93 | } elseif ($TimeSpan.TotalSeconds -lt 60) { |
91 | | - "{0:N2}$SecondLabel" -f $TimeSpan.TotalSeconds |
| 94 | + $Output = "{0:N2}$SecondLabel" -f $TimeSpan.TotalSeconds |
| 95 | + |
92 | 96 | } elseif ($TimeSpan.TotalMinutes -lt 60) { |
93 | 97 | # Build output with non-zero components only |
94 | 98 | $Output = "{0:N0}$MinuteLabel" -f $TimeSpan.Minutes |
95 | | - if ($TimeSpan.Seconds -gt 0) { |
96 | | - $Output += " {0:N0}$SecondLabel" -f $TimeSpan.Seconds |
97 | | - } |
98 | | - $Output |
| 99 | + if ($TimeSpan.Seconds -gt 0) { $Output += " {0:N0}$SecondLabel" -f $TimeSpan.Seconds } |
| 100 | + |
99 | 101 | } elseif ($TimeSpan.TotalHours -lt 24) { |
100 | 102 | # Build output with non-zero components only |
101 | 103 | $Output = "{0:N0}$HourLabel" -f $TimeSpan.Hours |
102 | | - if ($TimeSpan.Minutes -gt 0) { |
103 | | - $Output += " {0:N0}$MinuteLabel" -f $TimeSpan.Minutes |
104 | | - } |
105 | | - if ($TimeSpan.Seconds -gt 0) { |
106 | | - $Output += " {0:N0}$SecondLabel" -f $TimeSpan.Seconds |
107 | | - } |
108 | | - $Output |
| 104 | + if ($TimeSpan.Minutes -gt 0) { $Output += " {0:N0}$MinuteLabel" -f $TimeSpan.Minutes } |
| 105 | + if ($TimeSpan.Seconds -gt 0) { $Output += " {0:N0}$SecondLabel" -f $TimeSpan.Seconds } |
| 106 | + |
109 | 107 | } else { |
110 | 108 | # Build output with non-zero components only |
111 | 109 | $Output = "{0:N0}$DayLabel" -f $TimeSpan.Days |
112 | | - if ($TimeSpan.Hours -gt 0) { |
113 | | - $Output += " {0:N0}$HourLabel" -f $TimeSpan.Hours |
114 | | - } |
115 | | - if ($TimeSpan.Minutes -gt 0) { |
116 | | - $Output += " {0:N0}$MinuteLabel" -f $TimeSpan.Minutes |
117 | | - } |
118 | | - if ($TimeSpan.Seconds -gt 0) { |
119 | | - $Output += " {0:N0}$SecondLabel" -f $TimeSpan.Seconds |
120 | | - } |
121 | | - $Output |
| 110 | + if ($TimeSpan.Hours -gt 0) { $Output += " {0:N0}$HourLabel" -f $TimeSpan.Hours } |
| 111 | + if ($TimeSpan.Minutes -gt 0) { $Output += " {0:N0}$MinuteLabel" -f $TimeSpan.Minutes } |
| 112 | + if ($TimeSpan.Seconds -gt 0) { $Output += " {0:N0}$SecondLabel" -f $TimeSpan.Seconds } |
122 | 113 | } |
| 114 | + |
| 115 | + $Output |
123 | 116 | } |
124 | 117 | } |
0 commit comments