Formatting and agility
skip scoop in VSCode Fix CovertFrom-TimeSpan to handle series and FieldName
This commit is contained in:
parent
c9d13f5c4d
commit
2f317c53f3
2 changed files with 27 additions and 16 deletions
|
@ -1,15 +1,24 @@
|
|||
param([TimeSpan]$TimeSpan, [switch]$NoSeconds)
|
||||
$local:out = [string]::Empty
|
||||
if( $TimeSpan.Days ) {
|
||||
$out = "$($TimeSpan.Days)d "
|
||||
}
|
||||
if( $out -or $TimeSpan.Hours ) {
|
||||
$out += "$($TimeSpan.Hours)h "
|
||||
}
|
||||
if( $out -or $TimeSpan.Minutes -or ($NoSeconds -and -not $out) ) {
|
||||
$out += "$($TimeSpan.Minutes)m "
|
||||
}
|
||||
if( -not $NoSeconds -and ($TimeSpan.Seconds -or -not $out) ) {
|
||||
$out += "$($TimeSpan.Seconds)s"
|
||||
}
|
||||
$out.Trim();
|
||||
[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();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue