Skip to content
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

ConvertFrom-Json: Add -DateKind parameter #20925

Merged
merged 2 commits into from Feb 13, 2024

Conversation

jborean93
Copy link
Collaborator

@jborean93 jborean93 commented Dec 14, 2023

PR Summary

Adds the -DateKind parameter to the ConvertFrom-Json that allows the caller to control how DateTime strings are converted into an object. The default behaviour is to create a DateTime value with the Kind being Unspecified if no TZ is set, Utc if the TZ Z is set, Local (after conversion) if an explicit TZ is set. This adds a Utc, Local to explicitly set the Kind as desired as well as a Offset and String value to create a DateTimeOffset or keep as a string.

PR Context

Provides the user the ability to create a DateTimeOffset value so that the underlying time zone information is preserved. Also gives the user the ability to keep it as a string or a specific DateTime with the Local or Utc kind.

Fixes: #13598

Docs PR for this change: MicrosoftDocs/PowerShell-Docs#10737

PR Checklist

jborean93 added a commit to jborean93/PowerShell-Docs that referenced this pull request Dec 14, 2023
Documents the -DateKind parameter that is part of the PR
PowerShell/PowerShell#20925.
@jborean93 jborean93 force-pushed the from-json-datekind branch 2 times, most recently from dc666e5 to d630c18 Compare December 14, 2023 06:13
Adds the -DateKind parameter to the ConvertFrom-Json that allows the
caller to control how DateTime strings are converted into an object. The
default behaviour is to create a DateTime value with the Kind being
Unspecified if no TZ is set, Utc if the TZ Z is set, Local (after
conversion) if an explicit TZ is set. This adds a Utc, Local to
explicitly set the Kind as desired as well as a Offset and String value
to create a DateTimeOffset or keep as a string.
@jborean93 jborean93 changed the title Add -DateKind to ConvertFrom-Json ConvertFrom-Json: Add -DateKind parameter Dec 14, 2023
@iSazonov iSazonov added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed labels Dec 14, 2023
@iSazonov
Copy link
Collaborator

@mklement0 Could please review and confirm this work as you expect?

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.

@@ -151,16 +151,68 @@ public static object ConvertFromJson(string input, bool returnHashtable, out Err
/// if the <paramref name="returnHashtable"/> parameter is true.</returns>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Justification = "Preferring Json over JSON")]
public static object ConvertFromJson(string input, bool returnHashtable, int? maxDepth, out ErrorRecord error)
=> ConvertFromJson(input, returnHashtable, maxDepth, jsonDateKind: JsonDateKind.Local, out error);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be JsonDateKind.Default?

Copy link
Collaborator Author

@jborean93 jborean93 Dec 14, 2023

Choose a reason for hiding this comment

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

Yes it should be, sorry was playing around with comparing the defaults and never fixed this up when finalizing on the values.

Thanks for picking it up.

@mklement0
Copy link
Contributor

Thanks, @iSazonov - I have one small question (see above), but otherwise it looks great. Thank you for tackling this, @jborean93.

This PR has 183 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +182 -1
Percentile : 56.6%

Total files changed: 4

Change summary by file extension:
.cs : +41 -1
.ps1 : +141 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Dec 22, 2023
jborean93 added a commit to jborean93/PowerShell-Docs that referenced this pull request Jan 29, 2024
Documents the -DateKind parameter that is part of the PR
PowerShell/PowerShell#20925.
jborean93 added a commit to jborean93/PowerShell-Docs that referenced this pull request Jan 29, 2024
Documents the -DateKind parameter that is part of the PR
PowerShell/PowerShell#20925.
Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM, great addition

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Feb 12, 2024
@iSazonov iSazonov merged commit 7103554 into PowerShell:master Feb 13, 2024
38 checks passed
Copy link
Contributor

microsoft-github-policy-service bot commented Feb 13, 2024

📣 Hey @jborean93, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@iSazonov
Copy link
Collaborator

@jborean93 Thanks for your contribution!

@jborean93 jborean93 deleted the from-json-datekind branch February 13, 2024 04:05
@jborean93
Copy link
Collaborator Author

Thanks for the review everyone!

jborean93 added a commit to jborean93/PowerShell-Docs that referenced this pull request Feb 13, 2024
Documents the -DateKind parameter that is part of the PR
PowerShell/PowerShell#20925.
jborean93 added a commit to jborean93/PowerShell-Docs that referenced this pull request Feb 14, 2024
Documents the -DateKind parameter that is part of the PR
PowerShell/PowerShell#20925.
dkattan pushed a commit to dkattan/PowerShell that referenced this pull request Feb 19, 2024
Adds the -DateKind parameter to the ConvertFrom-Json that allows the
caller to control how DateTime strings are converted into an object. The
default behaviour is to create a DateTime value with the Kind being
Unspecified if no TZ is set, Utc if the TZ Z is set, Local (after
conversion) if an explicit TZ is set. This adds a Utc, Local to
explicitly set the Kind as desired as well as a Offset and String value
to create a DateTimeOffset or keep as a string.
sdwheeler pushed a commit to jborean93/PowerShell-Docs that referenced this pull request Feb 23, 2024
Documents the -DateKind parameter that is part of the PR
PowerShell/PowerShell#20925.
sdwheeler added a commit to MicrosoftDocs/PowerShell-Docs that referenced this pull request Feb 23, 2024
* ConvertFrom-Json: Add -DateKind parameter

Documents the -DateKind parameter that is part of the PR
PowerShell/PowerShell#20925.

* Fix formatting, style, and wording

---------

Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
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 Medium PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed
Projects
None yet
4 participants