Hi, all;

I'm working on making an app that will allow users to navigate from 
one month to the next based on a start date and end date.  I noticed 
some interesting effects with the date object and days that fall 
outside the 1-31 range (http://tinyurl.com/5qc46j), so I thought I'd 
try something similar with months.

What I find is if the current month is 11 and you add 1 to it, you'll 
actually wind up with a date that's not in the _next_ year, but one 
in the year following.

Here's my code

public function makeDisplayedMonths(beginDate:Date, endDate:Date):void
{
                        var today:Date= new Date();
                        //set up date for loop
                        var parseDate:Date = beginDate;
                        //equalize parsedate and enddate
                        parseDate.setDate(1);
                        endDate.setDate(1);
                        while (parseDate <= endDate) {
                                //update date
                                parseDate.setMonth(++parseDate.month);
                                trace(parseDate, endDate);
                        } 
}

the trace is this

Tue Jul 1 00:00:00 GMT-0500 2008 Thu Jan 1 00:00:00 GMT-0600 2009
Fri Aug 1 00:00:00 GMT-0500 2008 Thu Jan 1 00:00:00 GMT-0600 2009
Mon Sep 1 00:00:00 GMT-0500 2008 Thu Jan 1 00:00:00 GMT-0600 2009
Wed Oct 1 00:00:00 GMT-0500 2008 Thu Jan 1 00:00:00 GMT-0600 2009
Sat Nov 1 00:00:00 GMT-0500 2008 Thu Jan 1 00:00:00 GMT-0600 2009
Mon Dec 1 00:00:00 GMT-0600 2008 Thu Jan 1 00:00:00 GMT-0600 2009
Fri Jan 1 00:00:00 GMT-0600 2010 Thu Jan 1 00:00:00 GMT-0600 2009

Note that it goes from Dec 1 2008 to Jan 1 2010, skipping 2009 
altogether.

Obviously now I know this I can code around it, but it seems like it 
should either throw an error that the month is out of range or just 
keep incrementing.

Or have I missed something here?

Thanks;

Amy

Reply via email to