Skip to content

Commit

Permalink
first fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaneri committed Jan 26, 2025
1 parent 886b8a7 commit 717c8d8
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 697 deletions.
108 changes: 0 additions & 108 deletions src/Private/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4097,114 +4097,6 @@ function Invoke-PodeWinElevatedCommand {
return Invoke-Expression "$Command $Arguments"
}

<#
.SYNOPSIS
Converts a duration in milliseconds into a human-readable time format.
.DESCRIPTION
This function takes an input duration in milliseconds and converts it into
a readable time format. It supports multiple output styles, such as verbose
(detailed text), compact (`dd:hh:mm:ss`), and concise (short notation).
Optionally, milliseconds can be excluded from the output.
.PARAMETER Milliseconds
The duration in milliseconds to be converted.
.PARAMETER VerboseOutput
If specified, outputs a detailed, descriptive format (e.g., "1 day, 2 hours, 3 minutes").
.PARAMETER CompactOutput
If specified, outputs a compact format (e.g., "dd:hh:mm:ss").
.PARAMETER ExcludeMilliseconds
If specified, excludes milliseconds from the output.
.EXAMPLE
Convert-PodeMillisecondsToReadable -Milliseconds 123456789
Output:
1d 10h 17m 36s
.EXAMPLE
Convert-PodeMillisecondsToReadable -Milliseconds 123456789 -VerboseOutput
Output:
1 day, 10 hours, 17 minutes, 36 seconds, 789 milliseconds
.EXAMPLE
Convert-PodeMillisecondsToReadable -Milliseconds 123456789 -CompactOutput -ExcludeMilliseconds
Output:
01:10:17:36
.NOTES
This is an internal function and may change in future releases of Pode.
#>

function Convert-PodeMillisecondsToReadable {
param (
[Parameter(Mandatory)]
[long]$Milliseconds,

[switch]$VerboseOutput, # Provide detailed descriptions
[switch]$CompactOutput, # Provide compact format like dd:hh:mm:ss or mm:ss:ms
[switch]$ExcludeMilliseconds # Exclude milliseconds from the output
)

$timeSpan = [timespan]::FromMilliseconds($Milliseconds)

if ($CompactOutput) {
# Dynamically build compact format
$components = @()

# Include days only if greater than 0
if ($timeSpan.Days -gt 0) { $components += '{0:D2}' -f $timeSpan.Days }

# Include hours only if greater than 0 or days are included
if ($timeSpan.Hours -gt 0 -or $components.Count -gt 0) { $components += '{0:D2}' -f $timeSpan.Hours }

# Include minutes if relevant
if ($timeSpan.Minutes -gt 0 -or $components.Count -gt 0) { $components += '{0:D2}' -f $timeSpan.Minutes }

# Add seconds as the final required time component
$components += '{0:D2}' -f $timeSpan.Seconds

# Append milliseconds if not excluded
if (-not $ExcludeMilliseconds) {
$components[-1] += ':{0:D3}' -f $timeSpan.Milliseconds
}

# Join with ":" and return
return $components -join ':'
}

# Default or verbose format
if ($VerboseOutput) {
$verboseParts = @()
if ($timeSpan.Days -gt 0) { $verboseParts += "$($timeSpan.Days) day$(if ($timeSpan.Days -ne 1) { 's' })" }
if ($timeSpan.Hours -gt 0) { $verboseParts += "$($timeSpan.Hours) hour$(if ($timeSpan.Hours -ne 1) { 's' })" }
if ($timeSpan.Minutes -gt 0) { $verboseParts += "$($timeSpan.Minutes) minute$(if ($timeSpan.Minutes -ne 1) { 's' })" }
if ($timeSpan.Seconds -gt 0) { $verboseParts += "$($timeSpan.Seconds) second$(if ($timeSpan.Seconds -ne 1) { 's' })" }
if (-not $ExcludeMilliseconds -and $timeSpan.Milliseconds -gt 0) {
$verboseParts += "$($timeSpan.Milliseconds) millisecond$(if ($timeSpan.Milliseconds -ne 1) { 's' })"
}

return $verboseParts -join ' '
}

# Default concise format
$parts = @()
if ($timeSpan.Days -gt 0) { $parts += "$($timeSpan.Days)d" }
if ($timeSpan.Hours -gt 0 -or $parts.Count -gt 0) { $parts += "$($timeSpan.Hours)h" }
if ($timeSpan.Minutes -gt 0 -or $parts.Count -gt 0) { $parts += "$($timeSpan.Minutes)m" }
if ($timeSpan.Seconds -gt 0 -or $parts.Count -gt 0) { $parts += "$($timeSpan.Seconds)s" }
if (-not $ExcludeMilliseconds -and $timeSpan.Milliseconds -gt 0 -or $parts.Count -gt 0) {
$parts += "$($timeSpan.Milliseconds)ms"
}

return $parts -join ':'
}

<#
.SYNOPSIS
Determines the OS architecture for the current system.
Expand Down
Loading

0 comments on commit 717c8d8

Please sign in to comment.