data curled, parsed and uploaded to a MySql database
charts created for each sensor
Problem with Intermittent JSON “time”
I have created a function to parse the JSON “time” value, extract the datetime informaton and ignore the mSecs/Seconds, etc. I would prefer to use the far simpler PHP strtotime(…) function…
To ask what seems to be obvious: so all times with more than 8 digits in the decimal part of the seconds cause it to fail?
As far as I know, ISO 8601 does not specify a maximum number of decimals, so I’m tempted to say that’s a PHP bug, not a bug in the JSON output.
If stored as the ISO 8601 string that the JSON gives you, then I guess the following would do the trick. (That should also work if the decimal part is shorter than 8 digits, I think.)
I noticed the additional numeric character in the trailing milliseconds and had to truncate the milliseconds to make the date MySqli friendly.
Further investigation revealed the following post which appears to pinpoint the problem to Golang. I can appreciate why Golang is used because it excels in handling large numbers of simultaneous HTTP Requests. It is a pity Golang sometimes returns an incorrect JSON “time” format
It appears that PHP rejects incorrect formatted datetimes and returns a negative boolean result.
Just as an aside, as for why the string is sometimes shorter: I assume it’s due to leaving out trailing zeroes. Your:
…shows that about 10% fails, and when evenly distributed then about 1/10th of the times would indeed have a trailing zero. So I guess you might also see strings that are even shorter, as 1/100th of the values will have 2 trailing zeroes, and so on.
I still don’t think it’s invalid. It’s not per ISO 8601.