Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method invocation failed because [System.TimeSpan] does not contain a method named 'op_Multiply'. #1

Closed
taxitorloseit opened this issue Sep 19, 2022 · 1 comment

Comments

@taxitorloseit
Copy link

Environment

Name                      Value                  
----                      -----                  
PSVersion                 5.1.19041.1682         
PSEdition                 Desktop                
PSCompatibleVersions      {1.0, 2.0, 3.0, 4.0...}
BuildVersion              10.0.19041.1682        
CLRVersion                4.0.30319.42000        
WSManStackVersion         3.0                    
PSRemotingProtocolVersion 2.3                    
SerializationVersion      1.1.0.1                

Current (as of 0.3.0)

Input

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')

Output

Method invocation failed because [System.TimeSpan] does not contain a method named 'op_Multiply'.
At C:\Users\...\Documents\WindowsPowerShell\Modules\PSBusinessTime\0.3.0\PSBusinessTime.psm1:409 char:9
+         $InBetweenHours = $NumberOfWorkingDays * $WorkingHours
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Multiply:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Workaround

Patch

PSBusinessTime.psm1
Line 313

From:

$WorkingHours = New-TimeSpan -Start $StartHour -End $FinishHour

To:

$WorkingHours = (New-TimeSpan -Start $StartHour -End $FinishHour).TotalHours

PSBusinessTime.psm1
Line 409

From:

$InBetweenHours = $NumberOfWorkingDays * $WorkingHours

To:

$InBetweenHours = New-TimeSpan -Hours ($NumberOfWorkingDays * $WorkingHours)

Input

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')

Output

Days              : 7
Hours             : 3
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 6156000000000
TotalDays         : 7.125
TotalHours        : 171
TotalMinutes      : 10260
TotalSeconds      : 615600
TotalMilliseconds : 615600000
@codaamok
Copy link
Owner

codaamok commented Oct 5, 2022

Thanks for taking the time to let me know and apologies for the delay in following up. I foolishly assumed New-TimeSpan was unchanged between Windows PowerShell and pwsh, but it looks like a multiply operator for it is new in pwsh. I just pushed 0.3.2 which should resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants