PowerShell_Scripts/base/ConvertFrom-TimeSpan.ps1
lksz 2f317c53f3 Formatting and agility
skip scoop in VSCode
Fix CovertFrom-TimeSpan to handle series and FieldName
2021-04-20 23:43:17 +00:00

24 lines
No EOL
672 B
PowerShell

[CmdletBinding()]param(
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[Alias("Elapsed")]
[TimeSpan]$TimeSpan,
[switch]$NoSeconds
)
process {
foreach( $local:ts in $TimeSpan ) {
$local:out = [string]::Empty
if( $ts.Days ) {
$out = "$($ts.Days)d "
}
if( $out -or $ts.Hours ) {
$out += "$($ts.Hours)h "
}
if( $out -or $ts.Minutes -or ($NoSeconds -and -not $out) ) {
$out += "$($ts.Minutes)m "
}
if( -not $NoSeconds -and ($ts.Seconds -or -not $out) ) {
$out += "$($ts.Seconds)s"
}
$out.Trim();
}
}