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
Add -AsLocal switch to Get-Date #11731
Comments
Great idea. I assume the intent of the We have to be careful about the logic of interpreting the input, however: From what I can tell, only The tricky part is that
Therefore, as also implied by your last example command: # NOTE: Interprets the given date *as UTC*
PS> (Get-Date "1/12/2020 4:00pm").ToLocalTime()
Sunday, January 12, 2020 11:00:00 AM # e.g., in the US Eastern time zone
This is .NET's behavior, over which we have no control, but I wonder if surfacing this behavior via # !! If we just call .ToLocalTime() behind the scenes, we get the same behavior as above:
# !! The given date is interpreted *as UTC* and then *converted to a local date*.
Get-Date "1/12/2020 4:00pm" -AsLocal My expectation would be that the nominal date given (in text form) would be interpreted as-is as a local date; which is the equivalent of: PS> [datetime]::new((Get-Date "1/12/2020 4:00pm").Ticks, 'Local') | Select DateTime, Kind
DateTime Kind
-------- ----
Sunday, January 12, 2020 4:00:00 PM Local Note how the unspecified input date string was now interpreted as a local time, as reflected in the output |
+1 @mklement0. I would expect it to use: [datetime]::Parse(
'4pm',
[cultureinfo]::CurrentCulture,
[Globalization.DateTimeStyles]::AssumeLocal) |
Thanks, @SeeminglyScience, but note that since the Therefore, I think |
@mklement0 and @SeeminglyScience Thanks for joining in! If we are including all three DateTimeKind options, do you think we need a parameter more like -AsUTC hasn't been part of a formal release yet, so now would be the time to change it if the PowerShell team was going to? |
I'd say, given that there's only 3 enumeration values whose number is unlikely to grow, it's easier on users to use distinct switches, |
@mklement0 Fair point. I can accept that ;-) |
Then again, for invocation with programmatically constructed parameters something like Having our cake and eating it too (providing |
;-) I have only started posting suggestions for PowerShell in the last few days and I hate to ask for the moon, so I am trying to be semi-conservative in my asks. I will take it either way ;-) |
Since we're adding multiple options here for the kind it should be an enum not switch parameter. Right now if we add |
As stated before, for programmatic construction of arguments In short: I'm personally fine with only implementing However, we should then act quickly, before 7.0 GA ships with the recently implemented |
Do you have any examples of a alias switch parameter mapping to another parameter? |
The one that readily comes to mind is |
More relatable examples:
I'm curious, though, @ThomasNieto: Are you asking not just because you were curious / weren't convinced that there is such a thing, or are you philosophically opposed to the concept? |
@mklement0 I was unaware of them or had used them without knowing. The concern I have with them is that you can get into scenarios like this where you can pass conflicting parameters. Normally tab completion will prevent a user from passing parameters that cannot be used together. In the first example To sum it up, I think convenience parameters have a place where they can be used in conjunction with the other parameter. PowerShell has done a good job with parameter sets protecting the user from passing parameters that cannot be used together through tab completion and help. C:\> Import-Module AssignedAccess -Global -Scope Local
Import-Module: The 'Global' and 'Scope' parameters cannot be specified together. Remove one of these parameters, and then try running the command again. C:\> Get-ChildItem -Attributes Directory -Hidden
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d--hs 12/4/2019 10:42 PM $Recycle.Bin
l--hs 12/4/2019 11:35 PM Documents and Settings -> C:\Users
d--h- 2/3/2020 10:09 AM ProgramData
d--hs 12/4/2019 11:35 PM Recovery
d--hs 2/5/2020 6:09 PM System Volume Information |
That's a testament to their usefulness.
While you can squeeze combinations out of # Allowed, but nonsensical
Get-ChildItem -File -Attributes directory
# The more intuitive way to write your example, using shortcut aliases only
Get-ChildItem -Directory -Hidden The far more typical case is to use one or the other; if there's something you cannot model with combining the shortcut aliases alone, you're better off using just With single-choice enumerations - as in the case of As such, these single-choice scenarios strike me as the ideal use case for shortcut aliases. That Similarly, the fact that implementing such mutual exclusion is currently cumbersome is not an argument - it just means that we need to make implementing this easier, as has been attempted before, in this since-withdrawn RFC: https://github.com/PowerShell/PowerShell-RFC/blob/master/X-Withdrawn/RFC0001-Mutual-Exclusion-Parameters-and-Properties.md
|
To continue the discussion from #13084 (comment), where @iSazonov wrote:
Agreed that Therefore, it makes sense to support it more fully, and to also offer A possible alternative is to eliminate the
This would mean that commands such as Technically, though, it is a breaking change. |
AsUTC was added in Preview only (#11611) and we can replace it with general parameter like /cc @brendandburns |
I think it would be complete to take TimeZoneInfo (or its For example, I may want to know what time '10:00 AM PDT' is in Japanese time (this format is often used as the start time for some event).
But, time zone abbreviations such as 'PDT' and 'JST' are not specified in ISO 8601 and are not official. This command will accept the following formats.
|
I think we should be cautious about using |
@aetos382 RE: parameter sets - yes, that's how it's designed, you're not supposed to be able to use them together. Switches supporting a As for the time zone suggestion, it would be best if you requested that in a new issue as it is an entirely separate request IMO. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
2 similar comments
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
Similar to the recent PR that added the -AsUTC switch to Get-Date, we should also have the ability to set Local DateTimeKind as well.
Examples of how this would work:
The text was updated successfully, but these errors were encountered: