Summary of the new feature/enhancement
PR #12179 added FromUnixTime parameter to the Get-Date command.
In PowerShell 7.1.0-preview.3, the following command causes an error.
PS /> Get-Date -Date -1 -FromUnixTime
Get-Date: Cannot bind parameter 'Date'. Cannot convert value "-1" to type "System. DateTime". Error: "String '-1' was not recognized as a valid DateTime."
This command should support negative unix time.
On Ubuntu, the following commands will not return an error.
$ date --date "@-1"
Wed Dec 31 23:59:59 UTC 1969
Proposed technical implementation details (optional)
The Date parameter of the Get-Date command has type DateTime. If an integer value is passed for this parameter, it will be interpreted as Ticks. This must be a positive value.
In other words, the following code is invalid.
PS /> [datetime] -1
InvalidArgument: Cannot convert value "-1" to type "System.DateTime". Error: "Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. (Parameter 'ticks')"
Unix time can take a negative value, meaning that it is before Unix Epoch.
To allow the Date parameter to take a negative integer value, the type of this parameter must be changed to long.
But this is a breaking change.
I think the FromUnixTime parameter should be able to take a value, as was suggested in #11719.
Summary of the new feature/enhancement
PR #12179 added FromUnixTime parameter to the Get-Date command.
In PowerShell 7.1.0-preview.3, the following command causes an error.
This command should support negative unix time.
On Ubuntu, the following commands will not return an error.
Proposed technical implementation details (optional)
The Date parameter of the Get-Date command has type DateTime. If an integer value is passed for this parameter, it will be interpreted as Ticks. This must be a positive value.
In other words, the following code is invalid.
Unix time can take a negative value, meaning that it is before Unix Epoch.
To allow the Date parameter to take a negative integer value, the type of this parameter must be changed to long.
But this is a breaking change.
I think the FromUnixTime parameter should be able to take a value, as was suggested in #11719.