JSFiddle - React, Tailwind, and code Playground
JavaScript
var date1 = '2015-06-01';
var date2 = '2015-06-10';
var xmlText = '<forecast><product><ProductID>001005011</ProductID><days><day><date>2015-06-04</date> <value>2.9</value> </day><day> <date>2015-04-09</date> <value>3.1</value></day> </days> </product> <product> <ProductID>001015006</ProductID> <days> <day> <date>2015-06-08</date> <value>1.1</value> </day><day> <date>2015-04-09</date> <value>1.2</value> </day> </days></product></forecast>';
var noOfDays = daysBetween(date1, date2);
var forecastDetail = [];
for (var i = 0; i < noOfDays; i++) {
var DeliveryDate = new Date(date1);
//DeliveryDate = ACN.convertAnsiDate2Date(ACN.addDays2AnsiFullDate(DeliveryDate, i));
var DeliveryDate1 = new Date(DeliveryDate.setDate(DeliveryDate.getDate() + i));
var forecastData = getQuantityByDate($.parseXML(xmlText), DeliveryDate1);
forecastDetail.push(forecastData[0] + "," +
}
function treatAsUTC(date) {
var result = new Date(date);
result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
return result;
}
function daysBetween(startDate, endDate) {
var millisecondsPerDay = 24 * 60 * 60 * 1000;
return (treatAsUTC(endDate) - treatAsUTC(startDate)) / millisecondsPerDay;
}
function getQuantityByDate(xml, forecastDate) {
var qty = 0;
var forecastData = [];
var sourceDate = forecastDate.getFullYear() + "-" + (forecastDate.getMonth() + 1) + "-" + forecastDate.getDate();
$(xml).find('product').each(function () {
var productId = $(this).find('ProductID').text();
$(this).find('day').each(function () {
var myDeliveryDate = treatAsUTC($(this).find('date').text());
var destinationDate = myDeliveryDate.getFullYear() + "-" + (myDeliveryDate.getMonth() + 1) + "-" + myDeliveryDate.getDate();
if (sourceDate == destinationDate)
{
//qty = parseFloat($(this).find('value').text());
forecastData.push(productId + "," +...