Returned validTime
on items is not parseable by JavaScript. Cannot recognize lexical duration. What is this for?
#331
Replies: 5 comments
-
To save time, here is a the console output for running this ^^^
|
Beta Was this translation helpful? Give feedback.
-
As you've noticed, the reason you can't parse it with The only thing you can assume regarding the UTC offset is that we will provide it via expressing the time instant in ISO8601 format. We do tend towards putting everything in UTC internally but this is not guaranteed, so use something that can parse ISO8601 and do not assume UTC. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer! Moment actually cannot parse this date string. I have tried that as well. I'm not sure there's a way to parse the entirety of the string without pre-processing (chopping the end off and using it or tossing it) in JavaScript. What does the lexical duration represent? It ranges anywhere from 1-7 in my response, and I don't understand how to interpret it. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I meant to say I understood that moment can't parse the string as-is, but it can deal with the two components of it. The interval is the length of time for which that value is valid. So Grid values generally start at one-hour resolution, with reduced resolution (up to 3- and 6-hour intervals) as we get farther out from the present and things become more uncertain. We also do run-length compression, so if multiple consecutive hours have the same value, we will present that as a longer duration interval (PT3H) rather than multiple one-hour intervals. I hope that explains a bit about interpreting the data. It may help to look at the raw data alongside the hourly forecast. |
Beta Was this translation helpful? Give feedback.
-
That makes perfect sense. Thank you so much for the detailed explanation :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm querying the API in Node and parsing the results. I want to pass each
validTime
property to anew Date()
, but I getInvalid Date
.I figured out it was the lexical duration
PT2H
at the end of each date. So, in other words, this works:new Date('2020-06-26T08:00:00+00:00')
and this does not:
new Date('2020-06-26T08:00:00+00:00/PT1H')
So, I have a some questions:
00:00
in all of them, is that the returned times are in UTC. Is this correct?Here is the repository I'm using for this (that I created): https://github.com/joelworsham/sunniest-time/tree/debugging-date-parse
If you pull that down, have node installed, and run the
./index
file, you should see what I'm talking about.Beta Was this translation helpful? Give feedback.
All reactions