You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Get-Date -FromUnixTime should support negative values. #12976
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues
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.
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.
Reacted by Ikiru Yoshizaki, Michael Klement and SilkyFowl
Rather than take the value in from -Date it almost seems better to just split the parameter set, and have -FromUnixTime take a value rather than be a switch parameter. 🤔
Reacted by Ikiru Yoshizaki, aetos, Keith Hill and SilkyFowl
Yeah, I think that makes the most sense. That does appear to have been the original proposal, too, but that didn't carry through to the initial implementation, it seems.
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues
Activity
iSazonov commentedon Jun 17, 2020
We need to see real scenarios where the feature could be useful.
vexx32 commentedon Jun 17, 2020
Rather than take the value in from
-Dateit almost seems better to just split the parameter set, and have-FromUnixTimetake a value rather than be a switch parameter. 🤔rkeithhill commentedon Jun 17, 2020
Rain Sallow (/u/ta11ow) (@vexx32) Agreed. BTW that's how I assumed it worked. Because of positional binding, it "appears" to work that way:
iSazonov commentedon Jun 17, 2020
What is a type of the parameter? Signed long?
vexx32 commentedon Jun 17, 2020
Yeah, I think that makes the most sense. That does appear to have been the original proposal, too, but that didn't carry through to the initial implementation, it seems.