While I'm not sure on the status of this as a bug, I would suggest
anyway to use the setDate() and getDate() methods instead. On a date
object, you can call setDate() with an arbitrary value and have the date
automatically adjust to stay consistent. That is, consider this example:
var today:Date = new Date( 2006, 9, 16, 22, 49, 18, 0 );
var result:Date = new Date( 2006, 9, today.getDate() + 16, 22, 49, 18, 0 );
trace( today ); // Mon Oct 16 22:49:18 GMT-0400 2006
trace( result ); // Wed Nov 1 22:49:18 GMT-0500 2006
Since October 32nd doesn't exist, he Date object was smart enough to
know to roll over to November when you try to set a "date" value more
than the number of days in the month. Note in this example, the
timezone changes as well, but thats because of daylight savings time.
As a general rule, if you want to add days to a date, just use setDate(
getDate() + value ).. value can be positive or negative, it doesn't matter.
-d
Mike Crowe wrote:
>
> Hi folks,
>
> I submitted this bug to Adobe today. I was trying to figure out why
> my Date routines wouldn't work. Here's a test function which fails:
>
> The following code appears to mis-compute the result date. This is
> adding 16 days to the current date:
>
> public function testMike():void {
> var tday:Date;
> var res:Date;
> var test:Date;
>
> tday = new Date(2006,9,16,22,49,18,0);
> res = new Date(tday.getTime() + 16*24*60*60*1000);
> test = new Date(2006,10,1,22,49,18,0);
> assertTrue( "Test: 16 via addDays(),\nNeed: 2006-11-01
> 22:49:18\nComp: "+res+"\nTest: "+test+"\n", res==test);
>
> }
>
> Results:
>
> Error: Test: 16 via addDays(),
> Need: 2006-11-01 22:49:18
> Comp: Wed Nov 1 21:49:18 GMT-0500 2006
> Test: Wed Nov 1 22:49:18 GMT-0500 2006
> - expected true but was false
>
> My unit-test goes from 1-100 days (by 5), All dates below 16 days
> work.
>
> Anybody else see this?
> TIA
> Mike
>
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/