function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Admin Admin 31Admin Admin 31 

Weird behavior of method Date.newInstance

What should be printed for this piece of code?

Date f1 = date.newinstance(2014,19,13);   // yyyy, MM, dd for my timezone...meaning the month is invalid
system.debug(f1);

It is printing:  2015-07-13 00:00:00  
..meaning it is adding the extra months to the date!!!! it should throw an exception as any language would do!!!
OR...the behavior should be documented in the dev docs.
 
SonamSonam (Salesforce Developers) 
Yes, did try that and am able to see this conversion..Let me check internally to see if its working as designed..will keep you posted.
SonamSonam (Salesforce Developers) 
So it seems like the Date function behaves exactly like the Java Date class. There it is possible and documented.
reference:
https://docs.oracle.com/javase/7/docs/api/java/util/Date.html 
"for example, a date may be specified as January 32 and is interpreted as meaning February 1."