RE: Strange behavior with setMonth method of Date object

2014-03-31 Thread Maurice Amsellem
This is because April has only 30 days.  31 of april does not exit.
So you should set setDate(1) before doing setMonth(3)

Maurice

-Message d'origine-
De : after24 [mailto:vinc...@after24.net] 
Envoyé : lundi 31 mars 2014 18:47
À : dev@flex.apache.org
Objet : Strange behavior with setMonth method of Date object

Hello,

I'm facing a strange behavior with the Date object :

var myDate:Date = new Date();
myDate.setFullYear(2014);
myDate.setMonth(3);
trace(myDate);  // return Thu May 1 18:31:07 GMT+0200 2014 myDate.setMonth(3); 
trace(myDate); // return Tue Apr 1 18:31:07 GMT+0200 2014

The returned month is false the first time. This behavior seems to occur only 
today(Mar 31, 2014), if I change my system date, the two trace statements 
returns the same date.

Is it a flash player bug (the only thing I found on the Adobe bugbase is
https://bugbase.adobe.com/index.cfm?event=bugid=2927909
https://bugbase.adobe.com/index.cfm?event=bugid=2927909  ) or am I missing 
something ? 



--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/Strange-behavior-with-setMonth-method-of-Date-object-tp36525.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: Strange behavior with setMonth method of Date object

2014-03-31 Thread after24
Sorry,

I should have post this message in the flex users list.

The problem seems to be due to the fact that the day is not set initially.
So the runtime uses the system current date (March 31). But as april has
only 30 days, when setMonth(3) is executed, the date is automatically set to 
may...

So it seems to be be a very bad idea to build a date like I did :

var myDate:Date = new Date();

myDate.setFullYear(year);
myDate.setMonth(month);
myDate.setDate(day);

Instead of :

var myDate:Date = new Date(year, month, day);






--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/Strange-behavior-with-setMonth-method-of-Date-object-tp36525p36527.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.


RE: Strange behavior with setMonth method of Date object

2014-03-31 Thread after24
Hi Maurice,

I didn't see your response before responding to myself.

Thank you :-)



--
View this message in context: 
http://apache-flex-development.247.n4.nabble.com/Strange-behavior-with-setMonth-method-of-Date-object-tp36525p36528.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.