I have a JSON reponse.
Input JSON Data:
[
{
“created_date”: “2010-01-01T00:00:00”,
“end_date”: “2010-03-01T00:00:00”,
“price”: “A”,
“created_by”: “ABC”
},
{
“created_date”: “2010-03-01T00:00:00”,
“end_date”: “2010-06-01T00:00:00”,
“price”: “A”,
“created_by”: “ABC”
},
{
“created_date”: “2010-09-01T00:00:00”,
“end_date”: “2010-12-01T00:00:00”,
“price”: “B”,
“created_by”: “XYZ”
},
{
“created_date”: “2010-12-01T00:00:00”,
“end_date”: “2011-03-01T00:00:00”,
“price”: “B”,
“created_by”: “XYZ”
},
{
“created_date”: “2011-03-01T00:00:00”,
“end_date”: “2011-06-01T00:00:00”,
“price”: “B”,
“created_by”: “XYZ”
},
{
“created_date”: “2011-06-01T00:00:00”,
“end_date”: “2011-12-01T00:00:00”,
“price”: “B”,
“created_by”: “XYZ”
},
{
“created_date”: “2012-06-01T00:00:00”,
“end_date”: “2012-12-01T00:00:00”,
“price”: “C”,
“created_by”: “PQR”
}
]
First object from above array :
{
“created_date”: “2010-01-01T00:00:00”,
“end_date”: “2010-03-01T00:00:00”,
“price”: “A”,
“created_by”: “ABC”
}
When I passed “InputPassdate” then it generate new response with below three output cases.
Three cases:
A) If “InputPassdate” is smaller than first object of both created_date and end_date i.e. “2009-12-31T00:00:00” then display all others objects in array.
Input :
“InputPassdate” : “2009-12-31T00:00:00”
Output JSON:
[
{
“created_date”: “2010-01-01T00:00:00”,
“end_date”: “2010-06-01T00:00:00”,
“price”: “A”,
“created_by”: “ABC”
},
{
“created_date”: “2010-09-01T00:00:00”,
“end_date”: “2011-12-01T00:00:00”,
“price”: “B”,
“created_by”: “XYZ”
},
{
“created_date”: “2012-06-01T00:00:00”,
“end_date”: “2012-12-01T00:00:00”,
“price”: “C”,
“created_by”: “PQR”
}
]
B) If “InputPassdate” is greater than first object of created_date and smaller than first object of end_date i.e. “2010-02-01T00:00:00” then it display all corresponding objects in array.
Input :
“InputPassdate” : “2010-04-01T00:00:00”
Output JSON:
[
{
“created_date”: “2010-01-01T00:00:00”,
“end_date”: “2010-06-01T00:00:00”,
“price”: “A”,
“created_by”: “ABC”
},
{
“created_date”: “2010-09-01T00:00:00”,
“end_date”: “2011-12-01T00:00:00”,
“price”: “B”,
“created_by”: “XYZ”
},
{
“created_date”: “2012-06-01T00:00:00”,
“end_date”: “2012-12-01T00:00:00”,
“price”: “C”,
“created_by”: “PQR”
}
]
C) If “InputPassdate” is greater than first and second object or many more of both created_date and end_date i.e. “2010-07-01T00:00:00” then it avoid those obejects and display others obejects in array.
Input :
“InputPassdate” : “2010-07-01T00:00:00”
Output JSON:
[
{
“created_date”: “2010-09-01T00:00:00”,
“end_date”: “2011-12-01T00:00:00”,
“price”: “B”,
“created_by”: “XYZ”
},
{
“created_date”: “2012-06-01T00:00:00”,
“end_date”: “2012-12-01T00:00:00”,
“price”: “C”,
“created_by”: “PQR”
}
]