Skip to content

ConvertFrom-Json: Add -DateKind parameter - #20925

Merged
Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
jborean93:from-json-datekind
Feb 13, 2024
Merged

Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
jborean93:from-json-datekind

Conversation

@jborean93

@jborean93 Jordan Borean (jborean93) commented Dec 14, 2023

Copy link
Copy Markdown
Collaborator

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

Jordan Borean (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
Jordan Borean (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 Jordan Borean (jborean93) changed the title Add -DateKind to ConvertFrom-Json ConvertFrom-Json: Add -DateKind parameter Dec 14, 2023
@iSazonov Ilya (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
Copy Markdown
Collaborator

Michael Klement (@mklement0) Could please review and confirm this work as you expect?

@iSazonov Ilya (iSazonov) left a comment

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.

LGTM.

/// 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
Copy Markdown
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?

@jborean93 Jordan Borean (jborean93) Dec 14, 2023

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
Contributor

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

@pull-request-quantifier-deprecated

Copy link
Copy Markdown

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
Jordan Borean (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.
Jordan Borean (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.

@SteveL-MSFT Steve Lee (SteveL-MSFT) left a comment

Copy link
Copy Markdown
Member

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
Ilya (iSazonov) merged commit 7103554 into PowerShell:master Feb 13, 2024
@microsoft-github-policy-service

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

Copy link
Copy Markdown
Contributor

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

🔗 https://aka.ms/PSRepoFeedback

@iSazonov

Copy link
Copy Markdown
Collaborator

Jordan Borean (@jborean93) Thanks for your contribution!

@jborean93
Jordan Borean (jborean93) deleted the from-json-datekind branch February 13, 2024 04:05
@jborean93

Copy link
Copy Markdown
Collaborator Author

Thanks for the review everyone!

Jordan Borean (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.
Jordan Borean (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.
Sean Wheeler (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.
Sean Wheeler (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 <[email protected]>
Chris Dent (chrisdent-de) pushed a commit to chrisdent-de/PowerShell that referenced this pull request Sep 12, 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.
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
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.
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

Development

Successfully merging this pull request may close these issues.

Add a -DateKind parameter to ConvertFrom-Json to control how System.DateTime / System.DateTimeOffset values are constructed

4 participants