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
Conversation
Documents the -DateKind parameter that is part of the PR PowerShell/PowerShell#20925.
dc666e5
to
d630c18
Compare
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.
@mklement0 Could please review and confirm this work as you expect? |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
Thanks, @iSazonov - I have one small question (see above), but otherwise it looks great. Thank you for tackling this, @jborean93. |
src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs
Outdated
Show resolved
Hide resolved
…Cmdlet/JsonObject.cs
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
Documents the -DateKind parameter that is part of the PR PowerShell/PowerShell#20925.
Documents the -DateKind parameter that is part of the PR PowerShell/PowerShell#20925.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great addition
📣 Hey @jborean93, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
@jborean93 Thanks for your contribution! |
Thanks for the review everyone! |
Documents the -DateKind parameter that is part of the PR PowerShell/PowerShell#20925.
Documents the -DateKind parameter that is part of the PR PowerShell/PowerShell#20925.
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.
Documents the -DateKind parameter that is part of the PR PowerShell/PowerShell#20925.
* 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>
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 specificDateTime
with theLocal
orUtc
kind.Fixes: #13598
Docs PR for this change: MicrosoftDocs/PowerShell-Docs#10737
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).