Skip to content

Commit

Permalink
Fixed New-BusinessTimeSpan for Windows PowerShell close #1
Browse files Browse the repository at this point in the history
  • Loading branch information
codaamok committed Oct 5, 2022
1 parent c70230b commit c2f7b49
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
56 changes: 55 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
{
"label": "Build",
"type": "process",
"command": "powershell",
"args": ["-noprofile","-command","Invoke-Build","-File","./invoke.build.ps1","-Author","'codaamok'","-ModuleName","'PSBusinessTime'"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": []
},
{
"label": "Build (pwsh)",
"type": "process",
"command": "pwsh",
"args": ["-noprofile","-command","Invoke-Build","-File","./invoke.build.ps1","-Author","'codaamok'","-ModuleName","'PSBusinessTime'"],
"group": "build",
Expand All @@ -22,6 +38,25 @@
{
"label": "Build (with docs)",
"type": "process",
"command": "powershell",
"args": ["-noprofile","-command","Invoke-Build","-File","./invoke.build.ps1","-Author","'codaamok'","-ModuleName","'PSBusinessTime'","-UpdateDocs","$true"],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": []
},
{
"label": "Build (with pwsh & docs)",
"type": "process",
"command": "pwsh",
"args": ["-noprofile","-command","Invoke-Build","-File","./invoke.build.ps1","-Author","'codaamok'","-ModuleName","'PSBusinessTime'","-UpdateDocs","$true"],
"group": {
Expand All @@ -39,7 +74,7 @@
"problemMatcher": []
},
{
"label": "Tests",
"label": "Tests (with pwsh)",
"type": "process",
"command": "pwsh",
"args": ["-noprofile", "-file", "./tests/invoke.tests.ps1"],
Expand All @@ -57,5 +92,24 @@
},
"problemMatcher": []
},
{
"label": "Tests",
"type": "process",
"command": "powershell",
"args": ["-noprofile", "-file", "./tests/invoke.tests.ps1"],
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": []
},
]
}
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
- `New-BusinessTimeSpan` threw an exception in some scenarios for Windows PowerShell - see issue #1

## [0.3.0] - 2022-05-04
### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Public/New-BusinessTimeSpan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function New-BusinessTimeSpan {
$NumberOfWorkingDays--
}

$InBetweenHours = $NumberOfWorkingDays * $WorkingHours
$InBetweenHours = New-TimeSpan -Seconds ($NumberOfWorkingDays * $WorkingHours.TotalSeconds)
$InBetweenHours + $ElapsedTime
}
}
2 changes: 1 addition & 1 deletion tests/Public/New-BusinessTimeSpan.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Describe "New-BusinessTimeSpan" {
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'
(New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalMinutes | Should -Be 143.2
[decimal](New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalMinutes | Should -Be 143.2
}

It "should be 10 hours, across 1 full day and 1 partial day, where both are working days" {
Expand Down

0 comments on commit c2f7b49

Please sign in to comment.