question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When parsing a JSON object with ISO 8601 date strings, Powershell 7 does not convert the date Correctly If it’s relevant, calling [datetime]::parse() directly on either 5.1 or 7 does work

Steps to reproduce

$datePs1 = [PSCustomObject]@{
    "Date" = "2020-05-03T15:13:01Z"
}

$dateJSON =  $datePs1 | convertto-json

write-host "Powershell Version: " $PSVersionTable.PSVersion
write-host "Original Date String: "  $datePS1.date
write-host "Parsed Original Date: "  ([datetime]::parse($datePs1.date))
write-host "Json Object: " $dateJSON
$dateFromJson = $dateJson | ConvertFrom-Json

write-host "`nConverted JSON Date String: "  $dateFromJson.date
write-host "Converted JSON Date Type: "  $dateFromJson.date.gettype().name
if($PSVersionTable.PSVersion -ne "7.0.0" ) {
    write-host "Parsed Converted JSON Date: "  ([datetime]::parse($dateFromJson.date))
}

Expected behavior

Powershell Version:  5.1.18362.628
Original Date String:  2020-05-03T15:13:01Z
Parsed Original Date:  4/05/2020 1:13:01 AM
Json Object:  {
    "Date":  "2020-05-03T15:13:01Z"        
}

Converted JSON Date String:  2020-05-03T15:13:01Z
Converted JSON Date Type:  String
Parsed Converted JSON Date:  4/05/2020 1:13:01 AM

Actual behavior

Powershell Version:  7.0.0
Original Date String:  2020-05-03T15:13:01Z
Parsed Original Date:  4/05/2020 1:13:01 AM
Json Object:  {
  "Date": "2020-05-03T15:13:01Z"
}

Converted JSON Date String:  3/05/2020 3:13:01 PM
Converted JSON Date Type:  DateTime

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}       
PSRemotingProtocolVersion      2.3    
SerializationVersion           1.1.0.1
WSManStackVersion              3.0    

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
iSazonovcommented, May 5, 2020

I hope in next release we will be on new .Net Json API.

0reactions
TristanJamesBallcommented, May 5, 2020

OK - this is my confusion then - I actually expected the resulting date to be presented in local time - this is what [datetime]::parse actually does (Sunday, May 3, 2020 3:13:01 PM UTC == Monday, May 4, 2020 1:13:01 AM local time here in Melbourne/Australia)

Separately, I had actually tried to do that conversion, but got badly wrong results - but that’s clearly a bug on my side…

OK - thats my bad… if I use a .tolocaltime() on the converted date, I get the correct local time.

Sorry everyone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capture and read bug reports | Android Studio
A bug report contains device logs, stack traces, and other diagnostic information to help you find and fix bugs in your app.
Read more >
My Bug Reports - EVE Community
You can still let us know if you come across any bugs by using the bug reporting form in the client or through...
Read more >
Reading bug reports
Android bug reports contain dumpsys , dumpstate , and logcat data in text (.txt) format, enabling you to easily search for specific content....
Read more >
Bug Reporting - Apple Developer
Send us your feedback and report bugs. Developer feedback is vital to making the ... Expected results: The event should appear and stay...
Read more >
How to Write a Good Bug Report? Tips and Tricks
A good bug report helps fix the bugs more effectively. Here's the procedure on how to write an excellent bug report.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found