any one knows where I could find (or I could make) a function that calculate moon phase ? (AS3)
<p>I'm looking for a small fucntion in ActionScript 3 that could calculate Moon Phases. 
I've tried to search on google. The only result is a website that gives this code but I think it's a wrong code. </p>

<pre><code>//return frame number for moon phase display
function getMoonPhase(yr:Number, m:Number, d:Number):int{
//based on http://www.voidware.com/moon_phase.htm
//calculates the moon phase (frames 1-30 )

if (m &lt; 3) { yr -= 1; m += 12; } //
m += 1; 
var c:Number = 365.25*yr; 
var e:Number = 30.6*m; //jd is total days elapsed 
//divide by the moon cycle (29.53 days) 
var jd:Number = (c+e+d-694039.09)/29.53; //subtract integer to leave fractional part
jd = jd - int(jd); //range fraction from 0-30 and round by adding 0.5 
var frame:int = Math.round(jd*30 + 0.5);
return frame; 
} 
//test: september 23, 2002, not a full moon? //
</code></pre>

<p>Weirdly, sometimes the code is extremely accurate, but sometimes it's wrong..</p>

<p>Example : On the 16 september 2016 it's a full moon. 
But if I enter this date in the code the result is "15" (16 is full moon)....</p>

<p>Any idea why ? or another way to calculate moon phases ? </p>

<p>Thx</p>