Skip to content

Commit

Permalink
Updated Get-ElapsedBusinessTime
Browse files Browse the repository at this point in the history
  • Loading branch information
codaamok committed Apr 14, 2022
1 parent 6cfcc2c commit ba0f783
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Public/Get-ElapsedBusinessTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -174,7 +175,7 @@ function Get-ElapsedBusinessTime {
$NumberOfWorkingDays--
}

$InBetweenHours = $NumberOfWorkingDays * $WorkingHours.Hours
(New-TimeSpan -Hours $InBetweenHours) + $ElapsedTime
$InBetweenHours = $NumberOfWorkingDays * $WorkingHours
$InBetweenHours + $ElapsedTime
}
}
6 changes: 6 additions & 0 deletions tests/Public/Get-ElapsedBusinessTime.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}

0 comments on commit ba0f783

Please sign in to comment.