Skip to content

Add -AsUTC to the Get-Date cmdlet #11611

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

Merged
merged 3 commits into from
Jan 24, 2020
Merged

Conversation

brendandburns
Copy link
Contributor

PR Summary

Adds a -AsUTC flag to convert a date to UTC before formatting.

PR Context

Requested in #11410

PR Checklist

@ghost ghost assigned anmenaga Jan 17, 2020
Comment on lines 224 to 231
public SwitchParameter AsUTC
{
get { return _asUTC; }

set { _asUTC = value; }
}

private SwitchParameter _asUTC = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use private fields.
public SwitchParameter AsUTC { get; set; }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.
(fwiw, I was trying to replicate how other fields in this Cmdlet are handled with public/private fields)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 28 to 29
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"
Copy link
Collaborator

@iSazonov iSazonov Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]::Utc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
(I had to modify the test a little from what you wrote, but I think it captures the same thing)

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 17, 2020
@iSazonov iSazonov added this to the 7.1.0-preview.1 milestone Jan 17, 2020
@iSazonov
Copy link
Collaborator

@brendandburns Please don't edit/trim "PR Checklist".

@brendandburns
Copy link
Contributor Author

Comments addressed, apologies for clipping the checklist, still learning the ropes around here :)

Please take another look.
Thanks!

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one comment

@anmenaga anmenaga merged commit 0b4c43b into PowerShell:master Jan 24, 2020
@anmenaga
Copy link

@brendandburns Thank you!

@ghost
Copy link

ghost commented Mar 26, 2020

🎉v7.1.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants