Powershell: Consider supporting Get-Date of infinity

Created on 8 Nov 2018  Â·  3Comments  Â·  Source: PowerShell/PowerShell

PowerShell supports an Infinity object which is returned for a float division by zero, which often happens when calculating the progress or the duration of some process (especially at the beginning when there is 0 progress). Unfortunately Get-Date throws an error for Infinity objects, which requires additional checks when calculating progress. As Infinity is a concept of time, I want to suggest supporting Infinity as input for Get-Date.

Steps to reproduce

PS /> $Infinity = 1/0.0
PS /> $Infinity.PSObject.BaseObject
∞
PS /> Get-Date $Infinity
Get-Date : Cannot bind parameter 'Date'. Cannot convert value "Infinity" to type "System.DateTime". Error: "The string 'Infinity' was not recognized as a valid DateTime. There is an unknown word starting at index '0'."

Expected behavior

PS /> $Infinity = 1/0.0
PS /> $Infinity.PSObject.BaseObject
∞
PS /> Get-Date $Infinity
∞

Environment data

PS /Users/florianfeldhaus/IdeaProjects/S3-Client> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Question Resolution-External

All 3 comments

The datetime data type is inherited from .NET Core. If anyone should implement this, it's really up to them; I would file an issue on the CoreFX repo instead.

However, given that a date of 'infinity' is about as meaningful as a simple numeral and doesn't really add... Anything... To the picture, I don't know if it's something they will go for.

Agree with @vexx32. 1/0.0 is actually represented by the [Double] class (i.e. [Double]::PositiveInfinity). Not sure there's a great way to mesh this with [DateTime] short of maybe returning some like [DateTime]::MaxValue when [Double]::PositiveInfinity is passed as a parameter. Sort of a hack.

This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.

Was this page helpful?
0 / 5 - 0 ratings