From b93f538b42dd49215f685a4e19e3adac46022ba9 Mon Sep 17 00:00:00 2001 From: codaamok Date: Fri, 22 Apr 2022 19:31:09 +0100 Subject: [PATCH] Renamed Get-ElapsedBusinessTime +semver:minor --- .github/workflows/pipeline.yml | 2 +- CHANGELOG.md | 16 +-- GitVersion.yml | 2 +- README.md | 4 +- ...usinessTime.md => New-BusinessTimeSpan.md} | 27 +++-- ...inessTime.ps1 => New-BusinessTimeSpan.ps1} | 100 +++++++++--------- ...sts.ps1 => New-BusinessTimeSpan.Tests.ps1} | 58 +++++----- 7 files changed, 105 insertions(+), 104 deletions(-) rename docs/{Get-ElapsedBusinessTime.md => New-BusinessTimeSpan.md} (75%) rename src/Public/{Get-ElapsedBusinessTime.ps1 => New-BusinessTimeSpan.ps1} (61%) rename tests/Public/{Get-ElapsedBusinessTime.Tests.ps1 => New-BusinessTimeSpan.Tests.ps1} (70%) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 558a81d..75f5bab 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -113,4 +113,4 @@ jobs: - name: Custom post-release tasks if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} run: Invoke-Build -File "custom.build.ps1" -ModuleName $env:GH_PROJECTNAME -Author $env:GH_USERNAME -Version $env:GitVersion_SemVer -NewRelease $true -Task PostRelease - shell: pwsh + shell: pwsh \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1957f3d..db42bde 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] +### Changed +- Renamed `Get-ElapsedBusinessTime` to `New-BusinessTimeSpan`, and changed parameters `-StartDate` and `-EndDate` to `-Start` and `-End`, similar to `New-TimeSpan` and its datetime parameters. ## [0.2.2] - 2022-04-15 ### Fixed @@ -12,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.2.1] - 2022-04-15 ### 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 +- `New-BusinessTimeSpan` 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.2.0] - 2022-04-14 ### Added @@ -21,29 +23,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.1.7] - 2022-04-14 ### Changed - `Test-WorkingDay` now has parameter validation to ensure `-StartHour` is less then `-FinishHour` -- `Get-ElapsedBusinessTime` now has parameter validation to ensure `-StartHour` is less then `-FinishHour` +- `New-BusinessTimeSpan` now has parameter validation to ensure `-StartHour` is less then `-FinishHour` ## [0.1.6] - 2022-04-14 ### 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 +- `New-BusinessTimeSpan` 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 -- `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 +- `New-BusinessTimeSpan` 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 -- `Get-ElapsedBusinessTime` did not return correct result when either the start date or end date were outside of business hours +- `New-BusinessTimeSpan` did not return correct result when either the start date or end date were outside of business hours - Added line breaks in between each line for all comment based help ## [0.1.2] - 2022-04-13 ### 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. +- `New-BusinessTimeSpan` 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 - Some typo and grammar issues in comment based help -- `Get-WorkingDates` would not return the correct number of working dates, which also impacted `Get-ElapsedBusinessTime` +- `Get-WorkingDates` would not return the correct number of working dates, which also impacted `New-BusinessTimeSpan` ## [0.1.0] - 2022-04-11 ### Added diff --git a/GitVersion.yml b/GitVersion.yml index 9763f72..a9bb3d1 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -5,4 +5,4 @@ branches: regex: ^(hot)?fix(es)?[/-] ignore: sha: [] -merge-message-formats: {} \ No newline at end of file +merge-message-formats: {} diff --git a/README.md b/README.md index be7da62..20588cf 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Inspired by https://pleasework.robbievance.net/howto-calculate-elapsed-business- ## Functions - [Add-WorkingDays](docs/Add-WorkingDays.md) -- [Get-ElapsedBusinessTime](docs/Get-ElapsedBusinessTime.md) +- [New-BusinessTimeSpan](docs/New-BusinessTimeSpan.md) - [Get-WorkingDates](docs/Get-WorkingDates.md) - [Test-WorkingDay](docs/Test-WorkingDay.md) @@ -37,7 +37,7 @@ Get-Command -Module PSBusinessTime ## Examples ```powershell -Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-01 00:00:00') -EndDate (Get-Date '2022-04-30 23:59:59') -NonWorkingDates (Get-Date '2022-04-15'), (Get-Date '2022-04-18') +New-BusinessTimeSpan -StartDate (Get-Date '2022-04-01 00:00:00') -EndDate (Get-Date '2022-04-30 23:59:59') -NonWorkingDates (Get-Date '2022-04-15'), (Get-Date '2022-04-18') ``` The function will return a timespan object of 171 hours: diff --git a/docs/Get-ElapsedBusinessTime.md b/docs/New-BusinessTimeSpan.md similarity index 75% rename from docs/Get-ElapsedBusinessTime.md rename to docs/New-BusinessTimeSpan.md index 3800b4f..c8d3ea1 100644 --- a/docs/Get-ElapsedBusinessTime.md +++ b/docs/New-BusinessTimeSpan.md @@ -5,7 +5,7 @@ online version: schema: 2.0.0 --- -# Get-ElapsedBusinessTime +# New-BusinessTimeSpan ## SYNOPSIS Get the elapsed time between two dates, where the time measured is only inbetween "business hours". @@ -13,9 +13,8 @@ Get the elapsed time between two dates, where the time measured is only inbetwee ## SYNTAX ``` -Get-ElapsedBusinessTime [-StartDate] [-EndDate] [[-StartHour] ] - [[-FinishHour] ] [[-NonWorkingDaysOfWeek] ] [[-NonWorkingDates] ] - [] +New-BusinessTimeSpan [-Start] [-End] [[-StartHour] ] [[-FinishHour] ] + [[-NonWorkingDaysOfWeek] ] [[-NonWorkingDates] ] [] ``` ## DESCRIPTION @@ -35,7 +34,7 @@ This function does consider both date and time while calculating the elapsed tim ### EXAMPLE 1 ``` -Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-11 10:00:00') -EndDate (Get-Date '2022-04-11 10:37:00') +New-BusinessTimeSpan -Start (Get-Date '2022-04-11 10:00:00') -End (Get-Date '2022-04-11 10:37:00') ``` The function will return a timespan object of 37 minutes. @@ -43,7 +42,7 @@ The function will return a timespan object of 37 minutes. ### EXAMPLE 2 ``` -Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-11 08:00:00') -EndDate (Get-Date '2022-04-12 08:00:00') +New-BusinessTimeSpan -Start (Get-Date '2022-04-11 08:00:00') -End (Get-Date '2022-04-12 08:00:00') ``` The function will return a timespan object of 9 hours. @@ -51,7 +50,7 @@ The function will return a timespan object of 9 hours. ### EXAMPLE 3 ``` -Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-11 13:00:00') -EndDate (Get-Date '2022-04-13 13:00:00') +New-BusinessTimeSpan -Start (Get-Date '2022-04-11 13:00:00') -End (Get-Date '2022-04-13 13:00:00') ``` The function will return a timespan object of 18 hours. @@ -59,7 +58,7 @@ The function will return a timespan object of 18 hours. ### EXAMPLE 4 ``` -Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-01 00:00:00') -EndDate (Get-Date '2022-04-30 23:59:59') -NonWorkingDates (Get-Date '2022-04-15'), (Get-Date '2022-04-18') +New-BusinessTimeSpan -Start (Get-Date '2022-04-01 00:00:00') -End (Get-Date '2022-04-30 23:59:59') -NonWorkingDates (Get-Date '2022-04-15'), (Get-Date '2022-04-18') ``` The function will return a timespan object of 162 hours. @@ -68,7 +67,7 @@ The function will return a timespan object of 162 hours. ### EXAMPLE 5 ``` -Get-ElapsedBusinessTime -StartDate (Get-Date '2022-01-01 00:00:00') -EndDate (Get-Date '2022-12-31 23:59:59') -NonWorkingDates (Get-Date '2022-01-03'), (Get-Date '2022-04-15'), (Get-Date '2022-04-18'), (Get-Date '2022-05-02'), (Get-Date '2022-06-02'), (Get-Date '2022-06-03'), (Get-Date '2022-08-29'), (Get-Date '2022-12-26'), (Get-Date '2022-12-27') +New-BusinessTimeSpan -Start (Get-Date '2022-01-01 00:00:00') -End (Get-Date '2022-12-31 23:59:59') -NonWorkingDates (Get-Date '2022-01-03'), (Get-Date '2022-04-15'), (Get-Date '2022-04-18'), (Get-Date '2022-05-02'), (Get-Date '2022-06-02'), (Get-Date '2022-06-03'), (Get-Date '2022-08-29'), (Get-Date '2022-12-26'), (Get-Date '2022-12-27') ``` The function will return a timespan object of 2259 hours. @@ -77,7 +76,7 @@ All dates passed to -NonWorkingDates are considered non-working dates (public ho ### EXAMPLE 6 ``` -Get-ElapsedBusinessTime -StartDate (Get-Date '2022-01-01 00:00:00') -EndDate (Get-Date '2022-12-31 23:59:59') -NonWorkingDaysOfWeek 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday' +New-BusinessTimeSpan -Start (Get-Date '2022-01-01 00:00:00') -End (Get-Date '2022-12-31 23:59:59') -NonWorkingDaysOfWeek 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday' ``` The function will return a timespan object of 0 hours. @@ -86,9 +85,9 @@ All days passed to -NonWorkingDaysOfWeek are considered non-working days, hence ## PARAMETERS -### -StartDate +### -Start The datetime object to start calculating the elapsed time from. -It must be an older datetime than -EndDate. +It must be an older datetime than -End. ```yaml Type: DateTime @@ -102,9 +101,9 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -EndDate +### -End The datetime object to end calculating the elapsed time to. -It must be a newer datetime than -StartDate. +It must be a newer datetime than -Start. ```yaml Type: DateTime diff --git a/src/Public/Get-ElapsedBusinessTime.ps1 b/src/Public/New-BusinessTimeSpan.ps1 similarity index 61% rename from src/Public/Get-ElapsedBusinessTime.ps1 rename to src/Public/New-BusinessTimeSpan.ps1 index fa7d561..f3e4157 100644 --- a/src/Public/Get-ElapsedBusinessTime.ps1 +++ b/src/Public/New-BusinessTimeSpan.ps1 @@ -1,4 +1,4 @@ -function Get-ElapsedBusinessTime { +function New-BusinessTimeSpan { <# .SYNOPSIS Get the elapsed time between two dates, where the time measured is only inbetween "business hours". @@ -14,10 +14,10 @@ function Get-ElapsedBusinessTime { You can also specify particular dates, or days of the week, to be regarded as non-working dates via the -NonWorkingDates and -NonWorkingDaysOfWeek parameters. This function does consider both date and time while calculating the elapsed time. - .PARAMETER StartDate - The datetime object to start calculating the elapsed time from. It must be an older datetime than -EndDate. - .PARAMETER EndDate - The datetime object to end calculating the elapsed time to. It must be a newer datetime than -StartDate. + .PARAMETER Start + The datetime object to start calculating the elapsed time from. It must be an older datetime than -End. + .PARAMETER End + The datetime object to end calculating the elapsed time to. It must be a newer datetime than -Start. .PARAMETER StartHour The starting hour of a typical working day. The default starting hour is 08:00 (AM). @@ -37,27 +37,27 @@ function Get-ElapsedBusinessTime { Dates specified in this parameter will not be considered as working days. .EXAMPLE - Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-11 10:00:00') -EndDate (Get-Date '2022-04-11 10:37:00') + New-BusinessTimeSpan -Start (Get-Date '2022-04-11 10:00:00') -End (Get-Date '2022-04-11 10:37:00') The function will return a timespan object of 37 minutes. 2022-04-11 is a Monday and the whole time inbetween the date range given is within the default parameters. .EXAMPLE - Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-11 08:00:00') -EndDate (Get-Date '2022-04-12 08:00:00') + New-BusinessTimeSpan -Start (Get-Date '2022-04-11 08:00:00') -End (Get-Date '2022-04-12 08:00:00') The function will return a timespan object of 9 hours. 2022-04-11 is a Monday and 2022-04-12 is a Tuesday, and only 9 hours is considered "working hours" within the default parameters. .EXAMPLE - Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-11 13:00:00') -EndDate (Get-Date '2022-04-13 13:00:00') + New-BusinessTimeSpan -Start (Get-Date '2022-04-11 13:00:00') -End (Get-Date '2022-04-13 13:00:00') The function will return a timespan object of 18 hours. 2022-04-11 through 2022-04-13 is Monday through Wednesday, and only 18 hours is considered "working hours" within the default parameters. .EXAMPLE - Get-ElapsedBusinessTime -StartDate (Get-Date '2022-04-01 00:00:00') -EndDate (Get-Date '2022-04-30 23:59:59') -NonWorkingDates (Get-Date '2022-04-15'), (Get-Date '2022-04-18') + New-BusinessTimeSpan -Start (Get-Date '2022-04-01 00:00:00') -End (Get-Date '2022-04-30 23:59:59') -NonWorkingDates (Get-Date '2022-04-15'), (Get-Date '2022-04-18') The function will return a timespan object of 162 hours. 2022-04-01 through 2022-04-30 is an entire calendar month, and only 162 hours is considered "working hours" within the defined parameters. '2022-04-15' and '2022-04-18' are considered non-working dates. .EXAMPLE - Get-ElapsedBusinessTime -StartDate (Get-Date '2022-01-01 00:00:00') -EndDate (Get-Date '2022-12-31 23:59:59') -NonWorkingDates (Get-Date '2022-01-03'), (Get-Date '2022-04-15'), (Get-Date '2022-04-18'), (Get-Date '2022-05-02'), (Get-Date '2022-06-02'), (Get-Date '2022-06-03'), (Get-Date '2022-08-29'), (Get-Date '2022-12-26'), (Get-Date '2022-12-27') + New-BusinessTimeSpan -Start (Get-Date '2022-01-01 00:00:00') -End (Get-Date '2022-12-31 23:59:59') -NonWorkingDates (Get-Date '2022-01-03'), (Get-Date '2022-04-15'), (Get-Date '2022-04-18'), (Get-Date '2022-05-02'), (Get-Date '2022-06-02'), (Get-Date '2022-06-03'), (Get-Date '2022-08-29'), (Get-Date '2022-12-26'), (Get-Date '2022-12-27') The function will return a timespan object of 2259 hours. 2022-01-01 through 2022-12-31 is an entire year, and only 2259 hours is considered "working hours" within the defined parameters. All dates passed to -NonWorkingDates are considered non-working dates (public holidays in the UK for 2022). .EXAMPLE - Get-ElapsedBusinessTime -StartDate (Get-Date '2022-01-01 00:00:00') -EndDate (Get-Date '2022-12-31 23:59:59') -NonWorkingDaysOfWeek 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday' + New-BusinessTimeSpan -Start (Get-Date '2022-01-01 00:00:00') -End (Get-Date '2022-12-31 23:59:59') -NonWorkingDaysOfWeek 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday' The function will return a timespan object of 0 hours. 2022-01-01 through 2022-12-31 is an entire year, and 0 hours is considered "working hours" within the defined parameters. All days passed to -NonWorkingDaysOfWeek are considered non-working days, hence the result of 0 hours. .INPUTS @@ -68,13 +68,13 @@ function Get-ElapsedBusinessTime { [CmdletBinding()] param( [Parameter(Mandatory)] - [datetime]$StartDate, + [datetime]$Start, [Parameter(Mandatory)] [ValidateScript({ - if ($StartDate -gt $_) { throw "-StartDate must be less than -EndDate." } else { return $true } + if ($Start -gt $_) { throw "-Start must be less than -End." } else { return $true } })] - [datetime]$EndDate, + [datetime]$End, [Parameter()] [DateTime]$StartHour = '08:00:00', @@ -99,7 +99,7 @@ function Get-ElapsedBusinessTime { } $WorkingHours = New-TimeSpan -Start $StartHour -End $FinishHour - $WorkingDays = Get-WorkingDates -StartDate $StartDate -EndDate $EndDate @CommonParams + $WorkingDays = Get-WorkingDates -StartDate $Start -EndDate $End @CommonParams if ($null -eq $WorkingDays) { New-TimeSpan @@ -110,32 +110,32 @@ function Get-ElapsedBusinessTime { FinishHour = $FinishHour } - $_StartDate = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $WorkingDays.Year, - $WorkingDays.Month, - $WorkingDays.Day, - $StartHour.Hour, - $StartHour.Minute, - $StartHour.Second) + $_Start = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $WorkingDays.Year, + $WorkingDays.Month, + $WorkingDays.Day, + $StartHour.Hour, + $StartHour.Minute, + $StartHour.Second) - if ($StartDate -le $_StartDate) { - $Params["StartDate"] = $_StartDate + if ($Start -le $_Start) { + $Params["StartDate"] = $_Start } else { - $Params["StartDate"] = $StartDate + $Params["StartDate"] = $Start } - $_EndDate = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $WorkingDays.Year, - $WorkingDays.Month, - $WorkingDays.Day, - $FinishHour.Hour, - $FinishHour.Minute, - $FinishHour.Second) + $_End = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $WorkingDays.Year, + $WorkingDays.Month, + $WorkingDays.Day, + $FinishHour.Hour, + $FinishHour.Minute, + $FinishHour.Second) - if ($EndDate -gt $_EndDate) { - $Params["EndDate"] = $_EndDate + if ($End -gt $_End) { + $Params["EndDate"] = $_End } else { - $Params["EndDate"] = $EndDate + $Params["EndDate"] = $End } $Result = GetElapsedTime @Params @@ -152,45 +152,45 @@ function Get-ElapsedBusinessTime { $ElapsedTime = New-TimeSpan $InBetweenHours = New-TimeSpan - $FirstDayEndDate = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $StartDate.Year, - $StartDate.Month, - $StartDate.Day, + $FirstDayEnd = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $Start.Year, + $Start.Month, + $Start.Day, $FinishHour.Hour, $FinishHour.Minute, $FinishHour.Second) - if (Test-WorkingDay -Date $StartDate -StartHour $StartHour -FinishHour $FinishHour @CommonParams) { + if (Test-WorkingDay -Date $Start -StartHour $StartHour -FinishHour $FinishHour @CommonParams) { $Params = @{ - StartDate = $StartDate - EndDate = $FirstDayEndDate + StartDate = $Start + EndDate = $FirstDayEnd StartHour = $StartHour FinishHour = $FinishHour } $ElapsedTime += (GetElapsedTime @Params) $NumberOfWorkingDays-- } - elseif ($StartDate -gt $FirstDayEndDate) { + elseif ($Start -gt $FirstDayEnd) { $NumberOfWorkingDays-- } - $LastDayStartDate = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $EndDate.Year, - $EndDate.Month, - $EndDate.Day, - $StartHour.Hour, - $StartHour.Minute, - $StartHour.Second) + $LastDayStart = Get-Date ('{0}/{1}/{2} {3}:{4}:{5}' -f $End.Year, + $End.Month, + $End.Day, + $StartHour.Hour, + $StartHour.Minute, + $StartHour.Second) - if (Test-WorkingDay -Date $EndDate -StartHour $StartHour -FinishHour $FinishHour @CommonParams) { + if (Test-WorkingDay -Date $End -StartHour $StartHour -FinishHour $FinishHour @CommonParams) { $Params = @{ - StartDate = $LastDayStartDate - EndDate = $EndDate + StartDate = $LastDayStart + EndDate = $End StartHour = $StartHour FinishHour = $FinishHour } $ElapsedTime += (GetElapsedTime @Params) $NumberOfWorkingDays-- } - elseif ($EndDate -lt $LastDayStartDate) { + elseif ($End -lt $LastDayStart) { $NumberOfWorkingDays-- } diff --git a/tests/Public/Get-ElapsedBusinessTime.Tests.ps1 b/tests/Public/New-BusinessTimeSpan.Tests.ps1 similarity index 70% rename from tests/Public/Get-ElapsedBusinessTime.Tests.ps1 rename to tests/Public/New-BusinessTimeSpan.Tests.ps1 index 500d913..36bb804 100644 --- a/tests/Public/Get-ElapsedBusinessTime.Tests.ps1 +++ b/tests/Public/New-BusinessTimeSpan.Tests.ps1 @@ -10,134 +10,134 @@ BeforeAll { } } -Describe "Get-ElapsedBusinessTime" { +Describe "New-BusinessTimeSpan" { Context "Date times which start and end within working hours" { It "should be 37 minutes on the same day" { $StartDate = Get-Date '2022-04-07 10:00:00' $EndDate = Get-Date '2022-04-07 10:37:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Minutes | Should -Be 37 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Minutes | Should -Be 37 } It "should be 2 hours on the same day" { $StartDate = Get-Date '2022-04-07 10:00:00' $EndDate = Get-Date '2022-04-07 12:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 2 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 2 } It "should be 9 hours on the same day" { $StartDate = Get-Date '2022-04-07 08:00:00' $EndDate = Get-Date '2022-04-07 17:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 9 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 9 } It "should be 9 hours on the same day" { $StartDate = Get-Date '2022-04-07 07:00:00' $EndDate = Get-Date '2022-04-07 18:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 9 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 9 } It "should be 1 hour, across 2 consecutive days, where both are working days" { $StartDate = Get-Date '2022-04-07 16:00:00' $EndDate = Get-Date '2022-04-08 03:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 1 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 1 } It "should be 1 hour, across 2 consecutive days, where both are working days" { $StartDate = Get-Date '2022-04-07 22:00:00' $EndDate = Get-Date '2022-04-08 09:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 1 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 1 } It "should be 9 hours, across 2 consecutive days, where both are working days" { $StartDate = Get-Date '2022-04-07 08:00:00' $EndDate = Get-Date '2022-04-08 08:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 9 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 9 } It "should be 9 hours, across 3 consecutive days, where all are working days" { $StartDate = Get-Date '2022-04-06 22:00:00' $EndDate = Get-Date '2022-04-08 02:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 9 + (New-BusinessTimeSpan -Start $StartDate -End $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 + (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" { $StartDate = Get-Date '2022-04-07 08:00:00' $EndDate = Get-Date '2022-04-08 09:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 10 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 10 } It "should be 10 hours, across 1 partial day and 1 full day, where both are working days" { $StartDate = Get-Date '2022-04-07 16:00:00' $EndDate = Get-Date '2022-04-08 17:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 10 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 10 } It "should be 18 hours, across 2 consecutive days, where both are working days" { $StartDate = Get-Date '2022-04-07 08:00:00' $EndDate = Get-Date '2022-04-08 17:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 18 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 18 } It "should be 18 hours, across 3 consecutive days, where all are working days" { $StartDate = Get-Date '2022-04-06 13:00:00' $EndDate = Get-Date '2022-04-08 13:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 18 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).Hours | Should -Be 18 } It "should be 45 hours, across 5 consecutive days, where all are working days" { $StartDate = Get-Date '2022-04-04 08:00:00' $EndDate = Get-Date '2022-04-08 17:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).TotalHours | Should -Be 45 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalHours | Should -Be 45 } It "should be 45 hours, across 7 consecutive days, where 5 are working days and 2 are not" { $StartDate = Get-Date '2022-04-07 08:00:00' $EndDate = Get-Date '2022-04-13 17:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).TotalHours | Should -Be 45 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalHours | Should -Be 45 } It "should be 90 hours, across 14 consecutive days, where 10 are working days and 4 are not" { $StartDate = Get-Date '2022-04-07 08:00:00' $EndDate = Get-Date '2022-04-20 17:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).TotalHours | Should -Be 90 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalHours | Should -Be 90 } It "should be 90 hours, across 17 consecutive days, where 13 are working days and 6 are not" { $StartDate = Get-Date '2022-04-07 08:00:00' $EndDate = Get-Date '2022-04-25 17:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).TotalHours | Should -Be 117 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalHours | Should -Be 117 } It "should be 171 hours, across 29 consecutive days, where 19 are working days and 11 are not" { $StartDate = Get-Date '2022-04-01 00:00:00' $EndDate = Get-Date '2022-04-30 23:59:59' $NonWorkingDates = (Get-Date '2022-04-15'), (Get-Date '2022-04-18') - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate -NonWorkingDates $NonWorkingDates).TotalHours | Should -Be 171 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate -NonWorkingDates $NonWorkingDates).TotalHours | Should -Be 171 } It "should be 162 hours, across 29 consecutive days, where 18 are working days and 11 are not" { $StartDate = Get-Date '2022-04-02 00:00:00' $EndDate = Get-Date '2022-05-01 23:59:59' $NonWorkingDates = (Get-Date '2022-04-15'), (Get-Date '2022-04-18') - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate -NonWorkingDates $NonWorkingDates).TotalHours | Should -Be 162 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate -NonWorkingDates $NonWorkingDates).TotalHours | Should -Be 162 } It "should be 180 hours, across 29 consecutive days, where 20 are working days and 10 are not" { $StartDate = Get-Date '2022-04-02 00:00:00' $EndDate = Get-Date '2022-05-01 23:59:59' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).TotalHours | Should -Be 180 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalHours | Should -Be 180 } It "should be 2340 hours, across 365 consecutive days, where 260 are working days and 105 are not" { $StartDate = Get-Date '2022-01-01 00:00:00' $EndDate = Get-Date '2022-12-31 23:59:59' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).TotalHours | Should -Be 2340 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate).TotalHours | Should -Be 2340 } It "should be 2259 hours, across 365 consecutive days, where 251 are working days and 20 are not" { @@ -154,44 +154,44 @@ Describe "Get-ElapsedBusinessTime" { Get-Date '2022-12-26' # Boxing Day Get-Date '2022-12-27' # Christmas Day ) - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate -NonWorkingDates $NonWorkingDates).TotalHours | Should -Be 2259 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate -NonWorkingDates $NonWorkingDates).TotalHours | Should -Be 2259 } It "should be 0 hours, across 365 consecutive days, where 0 are working days and 365 are not" { $StartDate = Get-Date '2022-01-01 00:00:00' $EndDate = Get-Date '2022-12-31 23:59:59' $NonWorkingDaysOfWeek = 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate -NonWorkingDaysOfWeek $NonWorkingDaysOfWeek).TotalHours | Should -Be 0 + (New-BusinessTimeSpan -Start $StartDate -End $EndDate -NonWorkingDaysOfWeek $NonWorkingDaysOfWeek).TotalHours | Should -Be 0 } It "should be 0 hours, across 2 consecutive days, where 2 are working days" { $StartDate = Get-Date '2022-04-07 18:00:00' $EndDate = Get-Date '2022-04-08 03:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 0 + (New-BusinessTimeSpan -Start $StartDate -End $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 + (New-BusinessTimeSpan -Start $StartDate -End $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 18:00:00' $EndDate = Get-Date '2022-04-07 19:00:00' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 0 + (New-BusinessTimeSpan -Start $StartDate -End $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' - (Get-ElapsedBusinessTime -StartDate $StartDate -EndDate $EndDate).Hours | Should -Be 0 + (New-BusinessTimeSpan -Start $StartDate -End $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' + (New-BusinessTimeSpan -Start $StartDate -End $EndDate -StartHour (Get-Date '07:00:00') -FinishHour (Get-Date '23:59:59')).TotalMinutes | Should -Be '2016.41666666667' } } } \ No newline at end of file