Skip to content

Conversation

@aetos382
Copy link
Contributor

@aetos382 aetos382 commented Jul 2, 2020

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

@ghost ghost assigned daxian-dbw Jul 2, 2020
@iSazonov
Copy link
Collaborator

iSazonov commented Jul 2, 2020

@jackdcasey @mklement0 Please review.

@daxian-dbw
Copy link
Member

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

Copy link
Collaborator

@iSazonov iSazonov Jul 15, 2020

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
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
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
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

ghost commented Jul 23, 2020

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 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
Collaborator

@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
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
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
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
Member

@iSazonov Thanks for the review!
@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

ghost commented Aug 7, 2020

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
Copy link
Member

daxian-dbw commented Aug 11, 2020

@aetos382 and @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, @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 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
aetos382 and others added 16 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
Contributor Author

@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
Collaborator

@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 daxian-dbw merged commit ede1085 into PowerShell:master Aug 12, 2020
@daxian-dbw 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
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
Collaborator

@aetos382 Thanks for your contribution!

@aetos382
Copy link
Contributor Author

aetos382 commented Aug 12, 2020

@iSazonov @daxian-dbw @mklement0 @SteveL-MSFT @TravisEz13 Thank you all!

@aetos382 aetos382 deleted the add-unixtime-to-get-date branch August 12, 2020 17:30
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

ghost commented Aug 17, 2020

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

Handy links:

@scotthardwick
Copy link

@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 rjmholt removed the Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers label Feb 2, 2021
@iSazonov iSazonov added this to the 7.2.0-preview.3 milestone Feb 6, 2021
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