Google Charts json date format - json

I am using Google Charts and trying to generate my own JSON format to render the chart rather than using the libraries. All is well except for trying to figure out how to represent a date format in json that google chart will understand...
Spec:
JSON does not support JavaScript Date values (for example, "new Date(2008,1,28,0,31,26)"; the API implementation does. However, the API does now support a custom valid JSON representation of dates as a string in the following format: Date(year, month, day[,hour, minute, second[, millisecond]]) where everything after day is optional, and months are zero-based.
Reference:
https://developers.google.com/chart/interactive/docs/dev/implementing_data_source#jsondatatable
Reading the above spec would seem to indicate that having the date format represented in json as Date(year, date, month) would work but this does not appear to work for me.
Error:
Uncaught Error: Type mismatch. Value Date(2012, 10, 3) does not match type date in column index 0
json response:
{"type":"ComboChart","cols":[["date","Date"],["number","Overall"],["number","Current"],["number","Rating Count"]],"rows":[["Date(2012, 10, 3)",4.0,4.0,69],["Date(2012, 10, 4)",4.0,4.0,69]],"options":{"title":"Rating for FI","chartArea":{"width":"90%","height":"75%"},"hAxis":{"title":"Date"},"legend":"top","curveType":"none","pointSize":8,"seriesType":"bars","series":{"0":{"type":"bars","targetAxisIndex":0},"2":{"type":"line","targetAxisIndex":1}},"vAxes":{"0":{"title":"Rating","minValue":0,"maxValue":5},"1":{"title":"Rating Count"}}}}
Nothing is jumping out at me as this should be following the spec required format. What am I missing?

your syntax is wrong, i think...
you should try something like that:
{"type":"ComboChart","cols":[["date","Date"],["number","Overall"],["number","Current"],["number","Rating Count"]],"rows":[["Date(2012, 10, 3)"]],["Date(2012, 10, 4)"]],"options":{"title":"Rating for FI","chartArea":{"width":"90%","height":"75%"},"hAxis":{"title":"Date"},"legend":"top","curveType":"none","pointSize":8,"seriesType":"bars","series":{"0":{"type":"bars","targetAxisIndex":0},"2":{"type":"line","targetAxisIndex":1}},"vAxes":{"0":{"title":"Rating","minValue":0,"maxValue":5},"1":{"title":"Rating Count"}}}}
for me, this code worked:
{"c":[{"v":"Date(2012,11)"},{"v":6657}.....
but this is to change the month, not the day and using json....

Related

How should I be encoding dates and times?

I'm converting date columns from an internal date/time format to something Vega-Lite can parse, and am uncertain what my target should be. In version 4, there was a date time definition object, that went something like this {"year": 2006, "month": "jan", "date": 1}, and I seem to remember that working. However some recent plots fail silently when I do that, and I seem to need to use ISO-8601 string formats.
What's the proper way to encode a date and time column in version 5?
You can specify a format object with a parse property to parse your dates in whatever format they're in.
https://vega.github.io/vega-lite/docs/data.html
Specific date formats can be provided (e.g., {foo: "date:'%m%d%Y'"}),
using the d3-time-format syntax.

Azure Logic Apps - Convert JSON Epoch Timestamp to DateTime String

I am working on an Azure Logic App that is triggered via an HTTP call and returns a JSON response. Internally, the logic app retrieves JSON data from a web API and then converts the response JSON data to a format that is acceptable to the calling client of the logic app.
The problem I'm having is that the web API is returning dates in the format "/Date(1616371200000)/" and I need the date format to look like "2021-03-32T19:00:00Z". I don't see any built-in logic app function that can work with or convert the Epoch timestamp as-is (unless I'm missing something).
To clarify...
Source Data:
{
"some_silly_date": "/Date(1616371200000)/"
}
Desired Data:
{
"some_silly_date": "2021-03-32T19:00:00Z"
}
The following solution would theoretically work if the source date wasn't wrapped with "/Date(...)/":
"#addToTime('1970-01-01T00:00:00Z', 1616371200000, 'Second')"
Parsing that text off the timestamp before converting it would lead to a really ugly expression. Is there a better way to convert the timestamp that I'm not aware of?
Note that using the Liquid JSON-to-JSON templates is not an option. I was using that and found this action apparently has to JIT compile before use which is causing my logic app to time-out when being called after a long period of inactivity.
Can you get the value "/Date(1616371200000)/" from the JSON into a variable? If so, a little string manipulation would do the trick:
int(replace(replace(variables('data_in'),'/Date(',''),')/',''))
Then use the variable in the addToTime function.
Result:
The following expression seems to be working and returns a timestamp in UTC. Note that the substring() function is only using a length of 10 instead of 13. I'm intentionally trimming-off the milliseconds from the Epoch timestamp because the addToTime() function only handles seconds.
{
"some_silly_date": "#addToTime('1970-01-01T00:00:00Z', int(substring(item()?['some_silly_date'],6,10)), 'Second')"
}
As an added bonus, if the timestamp value is null in the source JSON, do the following:
{
"some_silly_date": "#if(equals(item()?['some_silly_date'], null), null, addToTime('1970-01-01T00:00:00Z', int(substring(item()?['some_silly_date'],6,10)), 'Second'))"
}
Quite possibly the ugliest code I've ever written.

Restkit JSON error parsing dates in range 1969/12/07 to 1970/01/25 GMT

Running Restkit 0.23 and iOS7.1.2 and iOS8gms when dates in range 1969/12/08 to 1970/01/25 GMT are encountered the parsing to JSON fails with an error: [datasource.table.values.property]: Parsing date N was not recognized as a date format... where N is a number of seconds.
I am unable to determine the JSON parser that is in use.
Restkit documentation refers to either YAJL or SBJSON being pluggable.
If someone can advise how to identify the parser in use and to change to another parser that would be much appreciated. Otherwise if anyone can advise an alternative resolution that would also be helpful.
This was a problem with the backend which is using FlexJSON and is a known feature of FlexJSON:
(http://sourceforge.net/p/flexjson/discussion/686321/thread/029d17be/).
Trying to use JSONDeserializer but Flexjson is having issues parsing the Unix TimeStamps into Date objects, only if the date is in the range of Dec. 7th, 1969 to Jan. 25th, 1970. All other dates outside of that range are parsed fine. The error that it's giving is: [JSONException: : Parsing date 21600000 was not recognized as a date format]
So no problem at all with the iOS native JSON parser which is what RestKit is using, RestKit is simply faithfully passing back the server error messages.

Map time with RestKit

I've iOS project which is using RestKit 0.21.0 component responsible to get, parse and store in Core Data responses from remote server. In one of the backend JSON response I have something like that:
"response": [
{
"id": 1,
"start_time": "10:00:00",
"end_time": "14:00:00",
"name": "Object name"
},
.
.
.
]
In Model.xcdatamodeld I've defined entity with fields startTime and endTime type of Date. Generally all mappings JSON response to objects works correctly, but I have problem with JSON fields start_time and end_time.
do you have any advices how could be done correctly mapping time fields to data which could be stored in Core Data (SQLite datatbase)?
Create an NSDateFormatter with the appropriate format to parse your time strings. Add the date formatter with [[RKValueTransformer defaultValueTransformer] insertValueTransformer:dateFormatter atIndex:0];. Now RestKit will search through all your defined date formatters as well as the default ones whenever it needs to map to an NSDate destination.
Have inherited an app that is making extensive use of RestKit and is at 0.21 release now and its great. Needed to add date to string conversion in YYYY-MM-DD HH:MM:SS.SSS and followed the advice above to add the required date formatter to the default compound formatters at index 0. However found calls to RKObjectMapping overrode this by adding ISO8601 formatter at index 0 for backward compatibility in +(void)initialize. Commented those lines out and I am getting the correct result. I guess it is possibly the way the app is structured, there are any number of calls to RKObjectMapping and it was not possible to add the date formatter in the right place without the change to RKObjectMapping.

What type of date/time format is this?

I'm currently attempting to use HighStock charts on my site. I'll be using a PHP file to generate the data for the chart, my only question is what date/time format does HighStock use? Here's an example file they have on their site: http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json
[1107129600000,38.45]
Above is a line of data in the json file where 1107129600000 is the date and 38.45 is the stock price. Hopefully someone will know the date/time type. Thanks.
It looks like a UNIX timestamp. It's the number of seconds(or in your case, milliseconds) since January 1 1970. Most programming languages will let you convert this into more natural date/time formats.
Here's a tool to help you convert to see for yourself: http://www.epochconverter.com/
Further reference: http://en.wikipedia.org/wiki/Unix_time