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 13, 2022
1 parent f17d4c1 commit d70b681
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"label": "Tests",
"type": "process",
"command": "powershell",
"command": "pwsh",
"args": ["-noprofile", "-file", "./tests/invoke.tests.ps1"],
"group": {
"kind": "test",
Expand Down
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 where the number of working days between `-StartDate` and `-EndDate` was 1 but the date range spanned more than 1 calendar day, e.g. Sunday through to Monday.

## [0.1.1] - 2022-04-12
### Fixed
Expand Down
19 changes: 19 additions & 0 deletions src/Public/Get-ElapsedBusinessTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ function Get-ElapsedBusinessTime {
New-TimeSpan
}
elseif ($WorkingDays.Count -eq 1) {
if (-not (Test-WorkingDay -Date $StartDate -StartHour $StartHour -FinishHour $FinishHour @CommonParams)) {
$StartDate = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $WorkingDays.Year,
$WorkingDays.Month,
$WorkingDays.Day,
$StartHour.Hour,
$StartHour.Minute,
$StartHour.Second)
}

if (-not (Test-WorkingDay -Date $EndDate -StartHour $StartHour -FinishHour $FinishHour @CommonParams)) {
$EndDate = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $WorkingDays.Year,
$WorkingDays.Month,
$WorkingDays.Day,
$FinishHour.Hour,
$FinishHour.Minute,
$FinishHour.Second)

}

$Params = @{
StartDate = $StartDate
EndDate = $EndDate
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 @@ -35,6 +35,12 @@ Describe "Get-ElapsedBusinessTime" {
$EndDate = Get-Date '2022-04-08 08:00:00'
(Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 9
}

It "should be 143 minutes, across 2 consecutive days, where 1 is a working days" {
$StartDate = Get-Date '2022-04-10 13:52:12'
$EndDate = Get-Date '2022-04-11 10:23:12'
(Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).TotalMinutes | Should -Be 143.2
}

It "should be 10 hours, across 1 full day and 1 partial day, where both are working days" {
$StartDate = Get-Date '2022-04-07 08:00:00'
Expand Down

0 comments on commit d70b681

Please sign in to comment.