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 36aa09f commit a723333
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 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 `-StartDate` and `-EndDate` were on the same day, but it was a working day, and its time for both dates were outside of working hours

## [0.1.5] - 2022-04-14
### Fixed
Expand Down
25 changes: 16 additions & 9 deletions src/Public/Get-ElapsedBusinessTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function Get-ElapsedBusinessTime {
NonWorkingDates = $NonWorkingDates
}

$WorkingHours = New-TimeSpan -Start $StartHour -End $FinishHour
$WorkingHours = New-TimeSpan -Start $StartHour -End $FinishHour
$WorkingDays = Get-WorkingDates -StartDate $StartDate -EndDate $EndDate @CommonParams

if ($null -eq $WorkingDays) {
Expand All @@ -107,6 +107,7 @@ function Get-ElapsedBusinessTime {
$StartHour.Hour,
$StartHour.Minute,
$StartHour.Second)
$j++
}

if (-not (Test-WorkingDay -Date $EndDate -StartHour $StartHour -FinishHour $FinishHour @CommonParams)) {
Expand All @@ -116,17 +117,23 @@ function Get-ElapsedBusinessTime {
$FinishHour.Hour,
$FinishHour.Minute,
$FinishHour.Second)

$j++
}

$Params = @{
StartDate = $StartDate
EndDate = $EndDate
StartHour = $StartHour
FinishHour = $FinishHour
if ($j -eq 2) {
# This is if both start and end datetimes are outside of working hours
New-TimeSpan
}
else {
$Params = @{
StartDate = $StartDate
EndDate = $EndDate
StartHour = $StartHour
FinishHour = $FinishHour
}

GetElapsedTime @Params
}

GetElapsedTime @Params
}
else {
$NumberOfWorkingDays = $WorkingDays.Count
Expand Down
6 changes: 6 additions & 0 deletions tests/Public/Get-ElapsedBusinessTime.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ Describe "Get-ElapsedBusinessTime" {
(Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 0
}

It "should be 0 hours, across 1 consecutive day, where 1 is a working day" {
$StartDate = Get-Date '2022-04-07 01:00:00'
$EndDate = Get-Date '2022-04-07 03:00:00'
(Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 0
}

It "should be 0 hours, across 4 consecutive days, where 2 are working days" {
$StartDate = Get-Date '2022-04-08 18:00:00'
$EndDate = Get-Date '2022-04-11 03:00:00'
Expand Down

0 comments on commit a723333

Please sign in to comment.