Skip to content

Commit

Permalink
example testing ps7 json conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Dec 5, 2023
1 parent b0dc0f3 commit 3ff0fdb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Pwsh/Json/Test-ConvertFrom-DoesItAlwaysConvertToLocal-FromUTC.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<#
context:
I feel like I've asked this before, but is there a way to make ConvertFrom-Json in PS7 not convert UTC timestamps to local time?
really throws me when looking at objects pulled from our services, b/c all our logs are in UTC
#>
Set-Alias 'Json' 'ConvertTo-Json'
Set-Alias 'Json.From' 'ConvertFrom-Json'
$Now = [Datetime]::Now
$NowUtc = [Datetime]::UtcNow

[ordered]@{
GetDate = Get-Date
Now = $Now
NowUtc = $NowUtc

Js_Now =
$Now | Json
Js_Now_FromManualUtc =
$Now.ToUniversalTime() | Json

Js_NowUtc =
$NowUtc | Json

R_Now =
$Now | Json | Json.from

R_Now2 =
$Now.ToUniversalTime() | Json | Json.From

H_1 =
# "2023-12-05T18:25:48.2587934Z"
# ["2023-12-05T18:25:48.2587934Z"]
'["2023-12-05T18:25:48.2587934Z"]' | Json.From
H_ManualToUni2 =
('["2023-12-05T18:25:48.2587934Z"]' | Json.From).ToUniversalTime()

}

<#
output
Name Value
---- -----
GetDate 12/5/2023 12:28:49 PM
Now 12/5/2023 12:28:49 PM
NowUtc 12/5/2023 6:28:49 PM
Js_Now "2023-12-05T12:28:49.1778662-06:00"
Js_Now_FromManualUtc "2023-12-05T18:28:49.1778662Z"
Js_NowUtc "2023-12-05T18:28:49.1778723Z"
R_Now 12/5/2023 12:28:49 PM
R_Now2 12/5/2023 6:28:49 PM
H_1 12/5/2023 6:25:48 PM
H_ManualToUni2 12/5/2023 6:25:48 PM
#>

0 comments on commit 3ff0fdb

Please sign in to comment.