diff --git a/CHANGELOG.md b/CHANGELOG.md index 124f5b4..4648aec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- `Get-ElapsedBusinessTime` did not return correct result if range between `-StartHour` and `-FinishHour` was not whole, ie was a span of time where minutes and seconds also needed consideration ## [0.1.4] - 2022-04-14 ### Fixed diff --git a/src/Public/Get-ElapsedBusinessTime.ps1 b/src/Public/Get-ElapsedBusinessTime.ps1 index 2f2aba8..96856a8 100644 --- a/src/Public/Get-ElapsedBusinessTime.ps1 +++ b/src/Public/Get-ElapsedBusinessTime.ps1 @@ -131,6 +131,7 @@ function Get-ElapsedBusinessTime { else { $NumberOfWorkingDays = $WorkingDays.Count $ElapsedTime = New-TimeSpan + $InBetweenHours = New-TimeSpan $FirstDayEndDate = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $StartDate.Year, $StartDate.Month, @@ -174,7 +175,7 @@ function Get-ElapsedBusinessTime { $NumberOfWorkingDays-- } - $InBetweenHours = $NumberOfWorkingDays * $WorkingHours.Hours - (New-TimeSpan -Hours $InBetweenHours) + $ElapsedTime + $InBetweenHours = $NumberOfWorkingDays * $WorkingHours + $InBetweenHours + $ElapsedTime } } \ No newline at end of file diff --git a/tests/Public/Get-ElapsedBusinessTime.Tests.ps1 b/tests/Public/Get-ElapsedBusinessTime.Tests.ps1 index 5fb4b75..7d066f1 100644 --- a/tests/Public/Get-ElapsedBusinessTime.Tests.ps1 +++ b/tests/Public/Get-ElapsedBusinessTime.Tests.ps1 @@ -169,5 +169,11 @@ Describe "Get-ElapsedBusinessTime" { $EndDate = Get-Date '2022-04-11 03:00:00' (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 0 } + + It "should be 2016.41666666667, across 4 consecutive days, where 3 are working days" { + $StartDate = Get-Date '24 March 2022 07:23:33' + $EndDate = Get-Date '28 March 2022 01:04:35' + (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate -StartHour (Get-Date '07:00:00') -FinishHour (Get-Date '23:59:59')).TotalMinutes | Should -Be '2016.41666666667' + } } } \ No newline at end of file