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.

Quotes from JSON (Timezones Not Treated As UTC)

See original GitHub issue

I’m pulling crypto price quotes from a JSON API. It works, except for one issue: the dates it receives are always “ahead” by a day, thus it’s not actually showing the latest quote - it’s showing the quote from one day prior.

My assumption is that this is an issue of timezone: although the JSON API is providing standard times in UTC, the software seems to be treating them as “local time.” As a result, it thinks the latest quote is one day in the future, and instead displays yesterday’s quote for today.

I’ve experienced this issue with 3 different JSON APIs, so it definitely seems to be on the side of PP. It’s true whether the API returns the timestamp as a string (i.e. “2021-02-26T06:19:00Z”) or epoch (i.e. “1614297600”).

Here’s an example of an API you can try as-is, without needing a key:

URL: https://min-api.cryptocompare.com/data/v2/histoday?fsym=EWT&tsym=USD&limit=5
Path To Date: $.Data.Data[*].time
Path To Close: $.Data.Data[*].close

My local system is in Pacific Standard Time. The chart at the bottom of the “Historical Quotes” dialog shows all the correct quotes - but the latest quote is shown as tomorrow’s date, and the quote actually used by the software is always one day behind (aka the second quote in the list).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:31 (28 by maintainers)

github_iconTop GitHub Comments

2reactions
metal450commented, Apr 11, 2021

I figured out a way to workaround this (on Linux), if/until it gets fixed. If you launch it like:

TZ=UTC /opt/portfolio/PortfolioPerformance

You’ll fool it into running as UTC timezone, & then quotes & amounts will show the proper values.

1reaction
buchencommented, Jan 23, 2022

as having to set my clock back & forth every day for the past year is indescribably cumbersome

That is an argument. I have now merged your short-term fix. I have slightly edited the change to a) only apply to the latest prices (in order to not the move the historical prices by a date) and b) avoid that the resulting list has two prices for the same date

I believe the short-term fix should not change the behavior for Australian users. You are (just as I am) before UTC. On the date boundary, it moves only the latest quote up by one day (that will be overwritten in later updates with the end of day closing).

For the long term fix outlined above, I need more time (also to get the storage format right).

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON deserialization assumes local timezone if not provided ...
I was able to coax Json.Net to treat DateTimeOffset without an offset as UTC with the following settings:
Read more >
Storing UTC is not a silver bullet | Jon Skeet's coding blog
The general advice of “just convert all local date/time data to UTC and store that” is overly broad in my view. For future...
Read more >
Grails is parsing date not with UTC but with local time zone
Problem is that in JSON date format there are milliseconds ( .S ) in the end. My quick fix for this is new...
Read more >
Two timezones in JSON log - Beats - Discuss the Elastic Stack
We want to change the timezone in the JSON lines. Now is always in UTC (as indicated by Z ) but... How we...
Read more >
DateTime and DateTimeOffset support in System.Text.Json
WriteLine(e.Message); } } } // The example displays the following output: // The JSON value could not be converted to System.DateTime. Path ...
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