It isn't that easy unfortunately. There is not timedelta class (like Python) in Actionscript. This makes finding the distance between dates a bit of a pain. It isn't too bad if you can guarantee that the dates will always be within the same month (e.g. 1-31 within a given month). Then you can use something like:
package
{
import flash.display.Sprite;
public class TestXML extends Sprite
{
public function TestXML()
{
var xml:XML =
<a>
<u date="2009-04-10" value="543"/>
<u date="2009-04-11" value="234"/>
<u date="2009-04-13" value="321"/>
<u date="2009-04-14" value="66"/>
<u date="2009-04-16" value="234"/>
<t date="2009-04-01" value="43"/>
<t date="2009-04-02" value="67"/>
<t date="2009-04-03" value="432"/>
<t date="2009-04-08" value="123"/>
<t date="2009-04-09" value="65"/>
<l date="2009-04-01" value="12"/>
<l date="2009-04-02" value="76"/>
<l date="2009-04-03" value="123"/>
<l date="2009-04-04" value="6543"/>
<l date="2009-04-05" value="123"/>
<l date="2009-04-06" value="65"/>
<l date="2009-04-15" value="234"/>
<l date="2009-04-16" value="65"/>
</a>; // / // <-- need this for stack overflow parse bug :(
fillBlanks(xml, xml..u);
fillBlanks(xml, xml..t);
fillBlanks(xml, xml..l);
}
private function fillBlanks(rootNode:XML, list:XMLList):void
{
var dateString:String;
var matches:Array;
var currentDate:Date;
var lastDate:Date;
for each(var node:XML in list)
{
dateString = [email protected]();
matches = dateString.match(/(\d+)\-(\d+)\-(\d+)/);
currentDate = new Date(matches[1], matches[2], matches[3]);
while(lastDate && (currentDate.date - lastDate.date) != 1)
{
rootNode.insertChildBefore(node, new XML(
"<" + node.name() + " date=\"" +
lastDate.fullYear +
"-" +
lastDate.month +
"-" +
(lastDate.date + 1) +
"\" value=\"0\" />"));
lastDate = new Date(lastDate.fullYear, lastDate.month, lastDate.date + 1);
}
lastDate = currentDate;
}
}
}
}
This doesn't do fancy stuff like pad "0" before months or dates that are less than 10. It also will not handle if your ranges cross month barriers. The first is really easy to fix so I leave it to you. The second is not very easy at all (especially if the dates cross year boundaries as well) and again I'll leave it to you.