Repository navigation
Add -AsUTC to the Get-Date cmdlet - #11611
Conversation
| public SwitchParameter AsUTC | ||
| { | ||
| get { return _asUTC; } | ||
|
|
||
| set { _asUTC = value; } | ||
| } | ||
|
|
||
| private SwitchParameter _asUTC = false; |
There was a problem hiding this comment.
Please don't use private fields.
public SwitchParameter AsUTC { get; set; }
There was a problem hiding this comment.
done.
(fwiw, I was trying to replicate how other fields in this Cmdlet are handled with public/private fields)
There was a problem hiding this comment.
fwiw, the Codacy PR tool disagrees with you :)
https://app.codacy.com/manual/TravisEz13/PowerShell_PowerShell/pullRequest?prid=4837266
| Get-date -Date:"2020-01-01T00:00:00" -Format:"MMM-dd-yy hh:mm" | Should -Be "Jan-01-20 12:00" | ||
| Get-date -Date:"2020-01-01T00:00:00" -Format:"MMM-dd-yy hh:mm" -AsUTC | Should -Be "Jan-01-20 08:00" |
There was a problem hiding this comment.
I guess the tests fail because CI VMs has already UTC time zone. In any case we should take into account time zone.
Perhaps follow will be more reliable test:
(Get-date -Date:"2020-01-01T00:00:00").Kind | Should -Be [DateTimeKind]::Local
(Get-date -Date:"2020-01-01T00:00:00" -AsUTC).Kind | Should -Be [DateTimeKind]::UtcThere was a problem hiding this comment.
Done
(I had to modify the test a little from what you wrote, but I think it captures the same thing)
|
Brendan Burns (@brendandburns) Please don't edit/trim "PR Checklist". |
|
Comments addressed, apologies for clipping the checklist, still learning the ropes around here :) Please take another look. |
4348684 to
a42e077
Compare
a42e077 to
fecac84
Compare
Ilya (iSazonov)
left a comment
There was a problem hiding this comment.
LGTM with one comment
|
Brendan Burns (@brendandburns) Thank you! |
|
🎉 Handy links: |
PR Summary
Adds a
-AsUTCflag to convert a date to UTC before formatting.PR Context
Requested in #11410
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header