PowerShell_Scripts/base/ConvertFrom-TimeSpan.ps1

24 lines
672 B
PowerShell
Raw Normal View History

[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();
}
}