I have JSON from a SQL query [{date, text, desc},{,,,}] and I need to compare the date (date1, date2, ...) to multiple other JS date objects (b1, b2, ...) efficiently.
The problem is: currently I have to convert each JSON date into a JS date object before I can compare them, for example:
(date1->a1) then (a1 to b1)
else (date2->a2) then (a2 to b1)
else (daten->an) then (an to b1)
... then
(date1->a1) then (a1 to b2)
else (date2->a2) then (a2 to b2)
else (daten->an) then (an to b2)
... and again for each b
I am looking for a more efficient method of doing this conversion-comparison as there could be ~90 'a's and 30-90 'b's.
Additional info:
- JSON dates are DESC
- JS dates are ASC
- The comparison is implemented like How do I format a Microsoft JSON date?
- When the dates match, return the JSON object to be processed
- If no dates match, return false
- I do have an early exit if b > a, but early on many won't fall into this criteria
I am using this in a JS function to insert the 'text' field into a table for Google Charts.
Thank you so much in advance for taking a look at my problem!
Example JSON:
[
{
"id": 797,
"title": "test",
"description": "test",
"annotationDate": {
"date": "2013-06-02 00:00:00",
"timezone_type": 3,
"timezone": "America\/Los_Angeles"
},
"discr": "annotation"
},
{
"id": 806,
"title": "recent",
"description": null,
"annotationDate": {
"date": "2013-06-01 00:00:00",
"timezone_type": 3,
"timezone": "America\/Los_Angeles"
},
"discr": "annotation"
}
]
Example JS date objects:
Date {Sat Jun 01 2013 11:19:35 GMT-0700 (PDT)}
Date {Sun Jun 02 2013 11:19:35 GMT-0700 (PDT)}
Date {Mon Jun 03 2013 11:19:35 GMT-0700 (PDT)}
Date {Tue Jun 04 2013 11:19:35 GMT-0700 (PDT)}