From 9ab1acea2cc6375e7f1582733c763df023946a4f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 11 Jul 2025 11:00:22 +0000 Subject: [PATCH 1/3] Initial plan From ac677c85df226834fd6f3a87e18e41d2e4868ef2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 11 Jul 2025 11:09:41 +0000 Subject: [PATCH 2/3] Add Get-TimeSpan function with comprehensive features and tests Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- examples/General.ps1 | 58 ++++++++++++++++ src/functions/public/Get-TimeSpan.ps1 | 97 +++++++++++++++++++++++++++ tests/PSModuleTest.Tests.ps1 | 62 +++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 src/functions/public/Get-TimeSpan.ps1 diff --git a/examples/General.ps1 b/examples/General.ps1 index c01d526..c07dd22 100644 --- a/examples/General.ps1 +++ b/examples/General.ps1 @@ -2,3 +2,61 @@ .SYNOPSIS This is a general example of how to use the module. #> + +# Import required functions +. ./src/variables/private/UnitMap.ps1 +. ./src/functions/private/Format-UnitValue.ps1 +. ./src/functions/public/Format-TimeSpan.ps1 +. ./src/functions/public/Get-TimeSpan.ps1 + +Write-Host "=== TimeSpan Module Examples ===" -ForegroundColor Green + +# Example 1: Format existing TimeSpan +Write-Host "`n1. Formatting TimeSpan objects:" -ForegroundColor Yellow +$timespan = New-TimeSpan -Hours 2 -Minutes 30 -Seconds 15 +Write-Host "Original TimeSpan: $($timespan.ToString())" +Write-Host "Formatted: $(Format-TimeSpan $timespan)" +Write-Host "Formatted with precision 3: $(Format-TimeSpan $timespan -Precision 3 -FullNames)" + +# Example 2: Get TimeSpan to future event +Write-Host "`n2. Getting TimeSpan to future events:" -ForegroundColor Yellow +$futureEvent = [DateTime]::Now.AddHours(3).AddMinutes(45) +$countdown = Get-TimeSpan -Target $futureEvent +Write-Host "Event in future: $($futureEvent.ToString('yyyy-MM-dd HH:mm:ss'))" +Write-Host "Time until event: $($countdown.ToString())" +Write-Host "Formatted countdown: $(Format-TimeSpan $countdown -Precision 2 -FullNames)" + +# Example 3: Get TimeSpan for past events (age calculation) +Write-Host "`n3. Getting age/elapsed time:" -ForegroundColor Yellow +$pastEvent = [DateTime]::Now.AddDays(-30).AddHours(-5) +$age = Get-TimeSpan -Target $pastEvent -AsAge +Write-Host "Past event: $($pastEvent.ToString('yyyy-MM-dd HH:mm:ss'))" +Write-Host "Time since event: $($age.ToString())" +Write-Host "Formatted age: $(Format-TimeSpan $age -Precision 2 -FullNames)" + +# Example 4: Handling negative values +Write-Host "`n4. Handling negative TimeSpan values:" -ForegroundColor Yellow +$pastDeadline = [DateTime]::Now.AddHours(-2) +$defaultResult = Get-TimeSpan -Target $pastDeadline +$allowNegativeResult = Get-TimeSpan -Target $pastDeadline -AllowNegative + +Write-Host "Past deadline: $($pastDeadline.ToString('yyyy-MM-dd HH:mm:ss'))" +Write-Host "Default result (Zero): $($defaultResult.ToString())" +Write-Host "Allow negative result: $($allowNegativeResult.ToString())" +Write-Host "Formatted negative: $(Format-TimeSpan $allowNegativeResult -FullNames)" + +# Example 5: Pipeline usage +Write-Host "`n5. Pipeline usage:" -ForegroundColor Yellow +$events = @( + [DateTime]::Now.AddMinutes(15), + [DateTime]::Now.AddHours(2), + [DateTime]::Now.AddDays(1) +) + +Write-Host "Multiple upcoming events:" +$events | ForEach-Object { + $timeLeft = $_ | Get-TimeSpan + Write-Host " Event at $($_.ToString('HH:mm:ss')): $(Format-TimeSpan $timeLeft -Precision 2)" +} + +Write-Host "`n=== Examples Complete ===" -ForegroundColor Green diff --git a/src/functions/public/Get-TimeSpan.ps1 b/src/functions/public/Get-TimeSpan.ps1 new file mode 100644 index 0000000..fbb35d0 --- /dev/null +++ b/src/functions/public/Get-TimeSpan.ps1 @@ -0,0 +1,97 @@ +function Get-TimeSpan { + <# + .SYNOPSIS + Gets a TimeSpan representing the difference between a target DateTime and the current time. + + .DESCRIPTION + This function calculates the time difference between a specified target DateTime and the current time. + By default, it calculates Target - Now, which gives a positive value for future times and negative for past times. + The function can return zero for negative values or the actual negative TimeSpan based on the AllowNegative parameter. + It can also calculate elapsed time (age) by using the AsAge parameter, which calculates Now - Target. + + .EXAMPLE + $futureTime = [DateTime]::Now.AddMinutes(30) + Get-TimeSpan -Target $futureTime + + Output: + ```powershell + 00:30:00 + ``` + + Returns a TimeSpan representing 30 minutes until the target time. + + .EXAMPLE + $pastTime = [DateTime]::Now.AddMinutes(-30) + Get-TimeSpan -Target $pastTime + + Output: + ```powershell + 00:00:00 + ``` + + Returns TimeSpan.Zero since the target time is in the past and AllowNegative is not specified. + + .EXAMPLE + $pastTime = [DateTime]::Now.AddMinutes(-30) + Get-TimeSpan -Target $pastTime -AllowNegative + + Output: + ```powershell + -00:30:00 + ``` + + Returns a negative TimeSpan showing the target time was 30 minutes ago. + + .EXAMPLE + $pastTime = [DateTime]::Now.AddHours(-2) + Get-TimeSpan -Target $pastTime -AsAge + + Output: + ```powershell + 02:00:00 + ``` + + Returns a positive TimeSpan showing the age/elapsed time since the target. + + .OUTPUTS + System.TimeSpan + + .NOTES + The TimeSpan representing the difference between the target DateTime and now. + + .LINK + https://psmodule.io/TimeSpan/Functions/Get-TimeSpan/ + #> + [CmdletBinding()] + [OutputType([TimeSpan])] + param( + # The target DateTime to calculate the time difference from. + [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [DateTime] $Target, + + # If specified, allows returning negative TimeSpan values instead of TimeSpan.Zero for past dates. + [Parameter()] + [switch] $AllowNegative, + + # If specified, calculates elapsed time (Now - Target) instead of remaining time (Target - Now). + [Parameter()] + [switch] $AsAge + ) + + process { + if ($AsAge) { + # Calculate elapsed time: Now - Target + $timeSpan = [DateTime]::Now - $Target + } else { + # Calculate remaining time: Target - Now + $timeSpan = $Target - [DateTime]::Now + } + + # Handle negative values based on AllowNegative parameter + if ($timeSpan.TotalSeconds -lt 0 -and -not $AllowNegative) { + return [TimeSpan]::Zero + } + + return $timeSpan + } +} \ No newline at end of file diff --git a/tests/PSModuleTest.Tests.ps1 b/tests/PSModuleTest.Tests.ps1 index 0b49355..0ecb8ef 100644 --- a/tests/PSModuleTest.Tests.ps1 +++ b/tests/PSModuleTest.Tests.ps1 @@ -45,4 +45,66 @@ } } } + + Describe 'Get-TimeSpan' { + Context 'Get-TimeSpan - Future DateTime' { + It 'Get-TimeSpan - Returns positive TimeSpan for future datetime' { + $future = [DateTime]::Now.AddMinutes(30) + $result = Get-TimeSpan -Target $future + $result.TotalMinutes | Should -BeGreaterThan 29 + $result.TotalMinutes | Should -BeLessThan 31 + } + } + + Context 'Get-TimeSpan - Past DateTime without AllowNegative' { + It 'Get-TimeSpan - Returns Zero for past datetime' { + $past = [DateTime]::Now.AddMinutes(-30) + $result = Get-TimeSpan -Target $past + $result | Should -Be ([TimeSpan]::Zero) + } + } + + Context 'Get-TimeSpan - Past DateTime with AllowNegative' { + It 'Get-TimeSpan - Returns negative TimeSpan for past datetime when AllowNegative is specified' { + $past = [DateTime]::Now.AddMinutes(-30) + $result = Get-TimeSpan -Target $past -AllowNegative + $result.TotalMinutes | Should -BeLessThan -29 + $result.TotalMinutes | Should -BeGreaterThan -31 + } + } + + Context 'Get-TimeSpan - AsAge parameter' { + It 'Get-TimeSpan - Returns positive elapsed time for past datetime with AsAge' { + $past = [DateTime]::Now.AddHours(-2) + $result = Get-TimeSpan -Target $past -AsAge + $result.TotalHours | Should -BeGreaterThan 1.9 + $result.TotalHours | Should -BeLessThan 2.1 + } + + It 'Get-TimeSpan - Returns negative elapsed time for future datetime with AsAge and AllowNegative' { + $future = [DateTime]::Now.AddHours(2) + $result = Get-TimeSpan -Target $future -AsAge -AllowNegative + $result.TotalHours | Should -BeLessThan -1.9 + $result.TotalHours | Should -BeGreaterThan -2.1 + } + } + + Context 'Get-TimeSpan - Pipeline Support' { + It 'Get-TimeSpan - Accepts DateTime from pipeline' { + $future = [DateTime]::Now.AddMinutes(15) + $result = $future | Get-TimeSpan + $result.TotalMinutes | Should -BeGreaterThan 14 + $result.TotalMinutes | Should -BeLessThan 16 + } + } + + Context 'Get-TimeSpan - Exact Zero Case' { + It 'Get-TimeSpan - Returns Zero for exactly current time' { + $now = [DateTime]::Now + $result = Get-TimeSpan -Target $now + # Allow for small timing differences (should be very close to zero) + [Math]::Abs($result.TotalMilliseconds) | Should -BeLessThan 100 + } + } + } } From 55f7dfcf28c377f413f56d2dd77295f64ceeb56c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 11 Jul 2025 11:21:48 +0000 Subject: [PATCH 3/3] Refactor Get-TimeSpan to use Start/End parameters with default negative handling Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- examples/General.ps1 | 45 ++++++++------- src/functions/public/Get-TimeSpan.ps1 | 80 ++++++++++++++++----------- tests/PSModuleTest.Tests.ps1 | 72 ++++++++++++++---------- 3 files changed, 116 insertions(+), 81 deletions(-) diff --git a/examples/General.ps1 b/examples/General.ps1 index c07dd22..9a88ce6 100644 --- a/examples/General.ps1 +++ b/examples/General.ps1 @@ -18,35 +18,42 @@ Write-Host "Original TimeSpan: $($timespan.ToString())" Write-Host "Formatted: $(Format-TimeSpan $timespan)" Write-Host "Formatted with precision 3: $(Format-TimeSpan $timespan -Precision 3 -FullNames)" -# Example 2: Get TimeSpan to future event -Write-Host "`n2. Getting TimeSpan to future events:" -ForegroundColor Yellow +# Example 2: Get TimeSpan using default behavior (returns Zero) +Write-Host "`n2. Default behavior (both Start and End use current time):" -ForegroundColor Yellow +$defaultResult = Get-TimeSpan +Write-Host "Get-TimeSpan with no parameters: $($defaultResult.ToString())" + +# Example 3: Get TimeSpan to future event +Write-Host "`n3. Getting TimeSpan to future events:" -ForegroundColor Yellow $futureEvent = [DateTime]::Now.AddHours(3).AddMinutes(45) -$countdown = Get-TimeSpan -Target $futureEvent +$countdown = Get-TimeSpan -End $futureEvent Write-Host "Event in future: $($futureEvent.ToString('yyyy-MM-dd HH:mm:ss'))" Write-Host "Time until event: $($countdown.ToString())" Write-Host "Formatted countdown: $(Format-TimeSpan $countdown -Precision 2 -FullNames)" -# Example 3: Get TimeSpan for past events (age calculation) -Write-Host "`n3. Getting age/elapsed time:" -ForegroundColor Yellow -$pastEvent = [DateTime]::Now.AddDays(-30).AddHours(-5) -$age = Get-TimeSpan -Target $pastEvent -AsAge -Write-Host "Past event: $($pastEvent.ToString('yyyy-MM-dd HH:mm:ss'))" -Write-Host "Time since event: $($age.ToString())" -Write-Host "Formatted age: $(Format-TimeSpan $age -Precision 2 -FullNames)" +# Example 4: Get TimeSpan between two specific times +Write-Host "`n4. Getting TimeSpan between specific Start and End times:" -ForegroundColor Yellow +$startTime = [DateTime]::Now.AddHours(-2) +$endTime = [DateTime]::Now.AddHours(1) +$duration = Get-TimeSpan -Start $startTime -End $endTime +Write-Host "Start time: $($startTime.ToString('yyyy-MM-dd HH:mm:ss'))" +Write-Host "End time: $($endTime.ToString('yyyy-MM-dd HH:mm:ss'))" +Write-Host "Duration: $($duration.ToString())" +Write-Host "Formatted duration: $(Format-TimeSpan $duration -Precision 2 -FullNames)" -# Example 4: Handling negative values -Write-Host "`n4. Handling negative TimeSpan values:" -ForegroundColor Yellow +# Example 5: Handling negative values +Write-Host "`n5. Handling negative TimeSpan values:" -ForegroundColor Yellow $pastDeadline = [DateTime]::Now.AddHours(-2) -$defaultResult = Get-TimeSpan -Target $pastDeadline -$allowNegativeResult = Get-TimeSpan -Target $pastDeadline -AllowNegative +$defaultResult = Get-TimeSpan -End $pastDeadline +$stopAtZeroResult = Get-TimeSpan -End $pastDeadline -StopAtZero Write-Host "Past deadline: $($pastDeadline.ToString('yyyy-MM-dd HH:mm:ss'))" -Write-Host "Default result (Zero): $($defaultResult.ToString())" -Write-Host "Allow negative result: $($allowNegativeResult.ToString())" -Write-Host "Formatted negative: $(Format-TimeSpan $allowNegativeResult -FullNames)" +Write-Host "Default result (allows negative): $($defaultResult.ToString())" +Write-Host "StopAtZero result: $($stopAtZeroResult.ToString())" +Write-Host "Formatted negative: $(Format-TimeSpan $defaultResult -FullNames)" -# Example 5: Pipeline usage -Write-Host "`n5. Pipeline usage:" -ForegroundColor Yellow +# Example 6: Pipeline usage +Write-Host "`n6. Pipeline usage:" -ForegroundColor Yellow $events = @( [DateTime]::Now.AddMinutes(15), [DateTime]::Now.AddHours(2), diff --git a/src/functions/public/Get-TimeSpan.ps1 b/src/functions/public/Get-TimeSpan.ps1 index fbb35d0..971cef7 100644 --- a/src/functions/public/Get-TimeSpan.ps1 +++ b/src/functions/public/Get-TimeSpan.ps1 @@ -1,63 +1,74 @@ function Get-TimeSpan { <# .SYNOPSIS - Gets a TimeSpan representing the difference between a target DateTime and the current time. + Gets a TimeSpan representing the difference between two DateTime values. .DESCRIPTION - This function calculates the time difference between a specified target DateTime and the current time. - By default, it calculates Target - Now, which gives a positive value for future times and negative for past times. - The function can return zero for negative values or the actual negative TimeSpan based on the AllowNegative parameter. - It can also calculate elapsed time (age) by using the AsAge parameter, which calculates Now - Target. + This function calculates the time difference between a Start DateTime and End DateTime. + By default, both Start and End parameters default to the current time ([DateTime]::Now). + If neither Start nor End is provided (both use defaults), the function returns TimeSpan.Zero. + The function allows negative values by default, but can return zero for negative values using the StopAtZero parameter. .EXAMPLE $futureTime = [DateTime]::Now.AddMinutes(30) - Get-TimeSpan -Target $futureTime + Get-TimeSpan -End $futureTime Output: ```powershell 00:30:00 ``` - Returns a TimeSpan representing 30 minutes until the target time. + Returns a TimeSpan representing 30 minutes until the end time. .EXAMPLE $pastTime = [DateTime]::Now.AddMinutes(-30) - Get-TimeSpan -Target $pastTime + Get-TimeSpan -End $pastTime Output: ```powershell - 00:00:00 + -00:30:00 ``` - Returns TimeSpan.Zero since the target time is in the past and AllowNegative is not specified. + Returns a negative TimeSpan showing the end time was 30 minutes ago. .EXAMPLE $pastTime = [DateTime]::Now.AddMinutes(-30) - Get-TimeSpan -Target $pastTime -AllowNegative + Get-TimeSpan -End $pastTime -StopAtZero Output: ```powershell - -00:30:00 + 00:00:00 ``` - Returns a negative TimeSpan showing the target time was 30 minutes ago. + Returns TimeSpan.Zero since the result would be negative and StopAtZero is specified. .EXAMPLE - $pastTime = [DateTime]::Now.AddHours(-2) - Get-TimeSpan -Target $pastTime -AsAge + $startTime = [DateTime]::Now.AddHours(-2) + $endTime = [DateTime]::Now + Get-TimeSpan -Start $startTime -End $endTime Output: ```powershell 02:00:00 ``` - Returns a positive TimeSpan showing the age/elapsed time since the target. + Returns a positive TimeSpan showing the duration between start and end times. + + .EXAMPLE + Get-TimeSpan + + Output: + ```powershell + 00:00:00 + ``` + + Returns TimeSpan.Zero when both Start and End use their default values. .OUTPUTS System.TimeSpan .NOTES - The TimeSpan representing the difference between the target DateTime and now. + The TimeSpan representing the difference between the Start and End DateTime values (End - Start). .LINK https://psmodule.io/TimeSpan/Functions/Get-TimeSpan/ @@ -65,30 +76,33 @@ function Get-TimeSpan { [CmdletBinding()] [OutputType([TimeSpan])] param( - # The target DateTime to calculate the time difference from. - [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] - [DateTime] $Target, + # The start DateTime. Defaults to current time. + [Parameter(ValueFromPipelineByPropertyName)] + [DateTime] $Start = [DateTime]::Now, - # If specified, allows returning negative TimeSpan values instead of TimeSpan.Zero for past dates. - [Parameter()] - [switch] $AllowNegative, + # The end DateTime. Defaults to current time. + [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] + [DateTime] $End = [DateTime]::Now, - # If specified, calculates elapsed time (Now - Target) instead of remaining time (Target - Now). + # If specified, returns TimeSpan.Zero instead of negative values. [Parameter()] - [switch] $AsAge + [switch] $StopAtZero ) process { - if ($AsAge) { - # Calculate elapsed time: Now - Target - $timeSpan = [DateTime]::Now - $Target - } else { - # Calculate remaining time: Target - Now - $timeSpan = $Target - [DateTime]::Now + # Check if both parameters are using their default values + $startIsDefault = $PSBoundParameters.Keys -notcontains 'Start' + $endIsDefault = $PSBoundParameters.Keys -notcontains 'End' + + if ($startIsDefault -and $endIsDefault) { + return [TimeSpan]::Zero } - # Handle negative values based on AllowNegative parameter - if ($timeSpan.TotalSeconds -lt 0 -and -not $AllowNegative) { + # Calculate the time difference: End - Start + $timeSpan = $End - $Start + + # Handle negative values based on StopAtZero parameter + if ($timeSpan.TotalSeconds -lt 0 -and $StopAtZero) { return [TimeSpan]::Zero } diff --git a/tests/PSModuleTest.Tests.ps1 b/tests/PSModuleTest.Tests.ps1 index 0ecb8ef..c8178a6 100644 --- a/tests/PSModuleTest.Tests.ps1 +++ b/tests/PSModuleTest.Tests.ps1 @@ -47,50 +47,64 @@ } Describe 'Get-TimeSpan' { - Context 'Get-TimeSpan - Future DateTime' { - It 'Get-TimeSpan - Returns positive TimeSpan for future datetime' { + Context 'Get-TimeSpan - Default Behavior' { + It 'Get-TimeSpan - Returns Zero when both Start and End use defaults' { + $result = Get-TimeSpan + $result | Should -Be ([TimeSpan]::Zero) + } + } + + Context 'Get-TimeSpan - Future End DateTime' { + It 'Get-TimeSpan - Returns positive TimeSpan for future end datetime' { $future = [DateTime]::Now.AddMinutes(30) - $result = Get-TimeSpan -Target $future + $result = Get-TimeSpan -End $future $result.TotalMinutes | Should -BeGreaterThan 29 $result.TotalMinutes | Should -BeLessThan 31 } } - Context 'Get-TimeSpan - Past DateTime without AllowNegative' { - It 'Get-TimeSpan - Returns Zero for past datetime' { + Context 'Get-TimeSpan - Past End DateTime' { + It 'Get-TimeSpan - Returns negative TimeSpan for past end datetime by default' { $past = [DateTime]::Now.AddMinutes(-30) - $result = Get-TimeSpan -Target $past - $result | Should -Be ([TimeSpan]::Zero) + $result = Get-TimeSpan -End $past + $result.TotalMinutes | Should -BeLessThan -29 + $result.TotalMinutes | Should -BeGreaterThan -31 } - } - Context 'Get-TimeSpan - Past DateTime with AllowNegative' { - It 'Get-TimeSpan - Returns negative TimeSpan for past datetime when AllowNegative is specified' { + It 'Get-TimeSpan - Returns Zero for past end datetime with StopAtZero' { $past = [DateTime]::Now.AddMinutes(-30) - $result = Get-TimeSpan -Target $past -AllowNegative - $result.TotalMinutes | Should -BeLessThan -29 - $result.TotalMinutes | Should -BeGreaterThan -31 + $result = Get-TimeSpan -End $past -StopAtZero + $result | Should -Be ([TimeSpan]::Zero) } } - Context 'Get-TimeSpan - AsAge parameter' { - It 'Get-TimeSpan - Returns positive elapsed time for past datetime with AsAge' { - $past = [DateTime]::Now.AddHours(-2) - $result = Get-TimeSpan -Target $past -AsAge + Context 'Get-TimeSpan - Start and End Parameters' { + It 'Get-TimeSpan - Calculates difference between Start and End' { + $start = [DateTime]::Now.AddHours(-2) + $end = [DateTime]::Now + $result = Get-TimeSpan -Start $start -End $end $result.TotalHours | Should -BeGreaterThan 1.9 $result.TotalHours | Should -BeLessThan 2.1 } - It 'Get-TimeSpan - Returns negative elapsed time for future datetime with AsAge and AllowNegative' { - $future = [DateTime]::Now.AddHours(2) - $result = Get-TimeSpan -Target $future -AsAge -AllowNegative - $result.TotalHours | Should -BeLessThan -1.9 - $result.TotalHours | Should -BeGreaterThan -2.1 + It 'Get-TimeSpan - Returns negative when End is before Start' { + $start = [DateTime]::Now + $end = [DateTime]::Now.AddHours(-1) + $result = Get-TimeSpan -Start $start -End $end + $result.TotalHours | Should -BeLessThan -0.9 + $result.TotalHours | Should -BeGreaterThan -1.1 + } + + It 'Get-TimeSpan - Returns Zero for negative difference with StopAtZero' { + $start = [DateTime]::Now + $end = [DateTime]::Now.AddHours(-1) + $result = Get-TimeSpan -Start $start -End $end -StopAtZero + $result | Should -Be ([TimeSpan]::Zero) } } Context 'Get-TimeSpan - Pipeline Support' { - It 'Get-TimeSpan - Accepts DateTime from pipeline' { + It 'Get-TimeSpan - Accepts DateTime from pipeline as End parameter' { $future = [DateTime]::Now.AddMinutes(15) $result = $future | Get-TimeSpan $result.TotalMinutes | Should -BeGreaterThan 14 @@ -98,12 +112,12 @@ } } - Context 'Get-TimeSpan - Exact Zero Case' { - It 'Get-TimeSpan - Returns Zero for exactly current time' { - $now = [DateTime]::Now - $result = Get-TimeSpan -Target $now - # Allow for small timing differences (should be very close to zero) - [Math]::Abs($result.TotalMilliseconds) | Should -BeLessThan 100 + Context 'Get-TimeSpan - Exact Same Time' { + It 'Get-TimeSpan - Returns near Zero for same Start and End times' { + $time = [DateTime]::Now + $result = Get-TimeSpan -Start $time -End $time + # Should be exactly zero for same time + $result.TotalMilliseconds | Should -Be 0 } } }