Skip to content

Add -UnixTimeSeconds to Get-Date to allow Unix time input - #13084

Merged
Dongbo Wang (daxian-dbw) merged 19 commits into
PowerShell:masterfrom
aetos382:add-unixtime-to-get-date
Aug 12, 2020
Merged

Dongbo Wang (daxian-dbw) merged 19 commits into
PowerShell:masterfrom
aetos382:add-unixtime-to-get-date

Conversation

@aetos382

@aetos382 aetos (aetos382) commented Jul 2, 2020 •

Copy link
Copy Markdown
Contributor

PR Summary

Add the -UnixTimeSeconds parameter to the Get-Date command.
This allows the time in seconds elapsed since 1970-01-01T00:00:00Z (aka Unix Time).

PR #12179 has already been submitted, but my proposal is more like the specification proposed in #11719.
This proposal also supports negative values (meaning time before the Unix epoch), therefore improving compatibility with the DateTimeOffset class and the Linux date utility.

The following is an example of its use.

> Get-Date -UnixTimeSeconds 1593696159

Thursday, July 2, 2020 1:22:39 PM

> Get-Date -UnixTimeSeconds -1

Wednesday, December 31, 1969 11:59:59 PM

The parameter has -UnixTime alias, because 'Unix Time' generally means a value expressed in seconds.
Also, consider the possibility of adding a parameter in the future that takes values expressed in milliseconds.

The parameter is named UnixTimeSeconds, not FromUnixTime.
This is for consistency with the Date parameter (it's not FromDate).

PR Context

Close #12976

Compatibility Notes

This proposal is basically compatible with PowerShell 7.0.2, but not compatible with 7.1.0-preview.4, including #12179.

It also includes a parameter set name changes. It's classified as Non-Public surface in the guideline.

PR Checklist

@iSazonov

Copy link
Copy Markdown
Collaborator

@daxian-dbw

Copy link
Copy Markdown
Member

Travis Plunk (@TravisEz13) and Ilya (@iSazonov), since both of you reviewed and approved #12179, can you please also review this PR?

@iSazonov Ilya (iSazonov) Jul 15, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Our common pattern is to use consts without extra static class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is preferred to use TestCases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did so.

@ghost ghost added the Review - Needed The PR is being reviewed label Jul 23, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@iSazonov Ilya (iSazonov) added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jul 23, 2020
@iSazonov

Copy link
Copy Markdown
Collaborator

aetos (@aetos382) Please address my comments.

@ghost ghost removed Review - Needed The PR is being reviewed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Jul 23, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is parameter set names. So I'd add this in the consts:

Suggested change
private const string DateAndFormat = "DateAndFormat";
private const string DateAndFormatParameterSet = "DateAndFormat";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that if the parameter set name constants have the suffix ParameterSet, it would be better to make them members of the static inner class, as before.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is our common pattern. If you see a const with the suffix in code you understand that it is a parameter set name.

@daxian-dbw

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Thanks for the review!
Travis Plunk (@TravisEz13) can you please also take a look?

@ghost ghost added the Review - Needed The PR is being reviewed label Aug 7, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 11, 2020 •

Copy link
Copy Markdown
Member

aetos (@aetos382) and Ilya (@iSazonov), I notice the PR has a breaking change comparing to the existing 7.1 preview versions -- FromUnixTime is removed. Is that breaking change intentional? (just want to confirm).

Other than that, aetos (@aetos382) can you please resolve the conflict? Then it should be ready for merging.

@ghost ghost removed the Review - Needed The PR is being reviewed label Aug 11, 2020
@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log label Aug 11, 2020
aetos (aetos382) and others added 15 commits August 12, 2020 11:04
Since it was difficult to implement exclusivity between Date and UnixTimeSeconds, and Format and UFormat using parameter set, I checked Format and UFormat at runtime.
If UFormat is specified, DateTime is never returned.
To pass CodeFactor's static check, the value of the summary element now begins with an alphabetic character.
By changing the validation attribute of the UFormat parameter from ValidateNotNullOrEmpty to Mandatory
This test is not necessary because ParameterSet is used to ensure that Format and UFormat are not used together, and is not determined by an if statement.
…DateCommand.cs

Co-authored-by: Ilya <darpa@yandex.ru>
…DateCommand.cs

Co-authored-by: Ilya <darpa@yandex.ru>
@aetos382

Copy link
Copy Markdown
Contributor Author

Dongbo Wang (@daxian-dbw)

Is that breaking change intentional? (just want to confirm).

Yes. I am aware from the beginning that this PR is not compatible with the 7.1.0 preview.

@iSazonov

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Yes, new approach looks more good and it better to replace previous commit before RC and release.
I think we have no need use "Breaking-Change" label because it is used only for real breaking changes with released versions. Otherwise docs and release notes will confuse users.

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit ede1085 into PowerShell:master Aug 12, 2020
@daxian-dbw Dongbo Wang (daxian-dbw) added the Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers label Aug 12, 2020
@daxian-dbw

Copy link
Copy Markdown
Member

Thank you both for the clarification.
I will leave the "breaking change" label on for now and marked this PR to be reviewed by maintainers, so we can conclude on how to deal with breaking changes that happen within the preview releases.

@iSazonov

Copy link
Copy Markdown
Collaborator

aetos (@aetos382) Thanks for your contribution!

@aetos382

aetos (aetos382) commented Aug 12, 2020 •

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) Dongbo Wang (@daxian-dbw) Michael Klement (@mklement0) Steve Lee (@SteveL-MSFT) Travis Plunk (@TravisEz13) Thank you all!

@aetos382
aetos (aetos382) deleted the add-unixtime-to-get-date branch August 12, 2020 17:30
Sean Wheeler (sdwheeler) added a commit to MicrosoftDocs/PowerShell-Docs that referenced this pull request Aug 12, 2020
… the FromUnixTime parameter (#6264)

* Add UnixTimeSeconds parameter and Remove FromUnixTime parameter

PowerShell/PowerShell#13084

* docs: change date

* docs: Use full parameter name

* docs: change 'added' to 'introduced'

For consistency with other documents

* Fix parameter set names

Changed to reflect the merged PowerShell code.

* Update Get-Date.md

Reads better

Co-authored-by: Chase Wilson <31453523+chasewilson@users.noreply.github.com>
Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
@ghost

Copy link
Copy Markdown

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

Handy links:

@scotthardwick

Copy link
Copy Markdown

aetos (@aetos382) Thank you so much for your work on this! I wrote #11719 and am glad to see this come to completion. It will be very useful. Also look forward to your work on Timezones in #13312
Finally, if you get a chance, please feel free to look at my issue #11714 and make any suggestions too. It is also tied up with Unix Date/Times.

@rjmholt Rob Holt (rjmholt) removed the Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers label Feb 2, 2021
@iSazonov Ilya (iSazonov) added this to the 7.2.0-preview.3 milestone Feb 6, 2021
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log 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.

Get-Date -FromUnixTime should support negative values.

6 participants