473,809 Members | 2,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lunar months?

Is there any way of determining when the first day of a *lunar* month
(far eastern lunar months if it makes a difference) falls, using
javascript?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #1
9 3277
"Fabian" <la****@hotmail .com> writes:
Is there any way of determining when the first day of a *lunar* month
(far eastern lunar months if it makes a difference) falls, using
javascript?


If it is possible to calculate when it happens, then it is possible in
Javascript. Javascript is Turing complete after all (anything that can
be calculated in any language can also be calculated in Javscript).

So, the answer to your question is "yes" (I bet that wasn't what you
really wanted to ask :).

Now, how do you do it.
Since lunar months are (according to a Google search):
29 days, 12 hours, 44 minutes and 2.87 seconds
I.e., 2551442870 ms, you can start with one point in time where
a lunar month started, and add this number to get the next month's
start.

So, assume you find one date and time that stats a lunar cycle (as exact
as possible, enter it on the first line):

var lunarDayMS = Date.UTC(startY ear,startMonth-1,startDay,
startHour,start Min,startSec,st artMS).valueOf( );
var msPerLunarMonth = 2551442870;
// find first day of this lunar month
var todayMS = new Date().valueOf( );
// subtract how far into this lunar cycle we are:
var thisStartMS = todayMS - (todayMS - lunarDayMS)%msP erLunarMonth;
var startDay = new Date(thisStartM S);

Add msPerLunarMonth to thisStartMS to get the start of the next lunar
month.

The difficult part is to find the date *and* time of the start of
the lunar month. You might want to enter it as an UTC-date instead
of just using new Date()

(and now we just need Dr. John R. Stockton to tell me where I forgot
something :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
JRS: In article <u1**********@h otpop.com>, seen in
news:comp.lang. javascript, Lasse Reichstein Nielsen <lr*@hotpop.com >
posted at Thu, 20 Nov 2003 00:05:30 :-
"Fabian" <la****@hotmail .com> writes:
Is there any way of determining when the first day of a *lunar* month
(far eastern lunar months if it makes a difference) falls, using
javascript?

It does make a difference.

The Hebrew Calendar uses a month of length exactly defined in days (29
days 12 hours 793 halakhim); the Islamic Calendar defines the start of
the month by observations taken at the time, except for the Saudis who
have a definite fixed algorithm that they change from time to time.
Astronomers will have a definition explicitly based on Solar System
geometry.

Any Far Eastern method can agree with at most one of those.

The Islamic observational month has a long-term drift in its length in
days, because that is how the Moon and Earth actually behave; the
Hebrews are in error currently by about 0.17ppm, a day in about 16,000
years.
If it is possible to calculate when it happens, then it is possible in
Javascript. Javascript is Turing complete after all (anything that can
be calculated in any language can also be calculated in Javscript).
Subject to implementation limits on the number of bits available.

So, the answer to your question is "yes" (I bet that wasn't what you
really wanted to ask :).
Now, how do you do it.
Since lunar months are (according to a Google search):
29 days, 12 hours, 44 minutes and 2.87 seconds
I.e., 2551442870 ms, you can start with one point in time where
a lunar month started, and add this number to get the next month's
start.
That will presumably be an estimate of the *current* astronomical value.
BTW, Date.UTC(1970, 0, 30, 12, 44, 2, 870) does the conversion to
numeric milliseconds.

So, assume you find one UTC date and time that stats a lunar cycle (as exact
as possible, enter it on the first line):

var lunarDayMS = Date.UTC(startY ear,startMonth-1,startDay,
startHour,start Min,startSec,st artMS).valueOf( );
// .valueOf() is superfluous there; ECMA-232 15.9.4.3.
var msPerLunarMonth = 2551442870;
// find first day of this lunar month
var todayMS = new Date().valueOf( );
// subtract how far into this lunar cycle we are:
var thisStartMS = todayMS - (todayMS - lunarDayMS)%msP erLunarMonth;
var startDay = new Date(thisStartM S);

Add msPerLunarMonth to thisStartMS to get the start of the next lunar
month.
That new UTC will occur at all times of the actual day, of course.
The difficult part is to find the date *and* time of the start of
the lunar month. You might want to enter it as an UTC-date instead
of just using new Date()


No, he *must*, unless the code is only executed at a fixed offset from
GMT, or the offset is specified either in a string given to new Date()
(but see below and js-dates1.htm#TI) or otherwise.

The instant must be derivable from astronomical ephemerides, which
should be findable.

There will need to be a rule saying, in effect, what GMT or UTC the New
Moon must precede for the corresponding day to be the start of the Lunar
Month. Note that China and Japan are in different Time Zones, and have
no Summer Time; if there is Summer Time in parts of the Far East, that
could make a difference.

Of course, many Far Easterners are Muslim, and will follow similar rules
to those of the Near East, perhaps adapted.
Fabian's location is unclear; he has a .uk Website, but posts from time
+0900, which includes part of Russia, both Koreas, Japan, and somewhere
whose present name I do not recall. He should consult a local sage of
the appropriate persuasion, to determine what the actual rules are.

- - -

Date strings can accept a trailing field designating the offset from
GMT; but this seems unreliable. Using my MSIE 4 :-

Date.parse("200 0/01/01 +0830") represents 1999/12/31 15:30 GMT
Date.parse("200 0/01/01 -0830") gives NaN
Date.parse("200 0/01/01 +-0830") represents 2000/01/01 08:30 GMT
Date.parse("200 0/01/01 -+0830") represents 1999/12/31 15:30 GMT

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3
Dr John Stockton wrote:
JRS: In article <u1**********@h otpop.com>, seen in
news:comp.lang. javascript, Lasse Reichstein Nielsen <lr*@hotpop.com >
posted at Thu, 20 Nov 2003 00:05:30 :-
"Fabian" <la****@hotmail .com> writes:
Is there any way of determining when the first day of a *lunar* month
(far eastern lunar months if it makes a difference) falls, using
javascript?


It does make a difference.

<explanation snipped>


And of course, if the user's computer clock is set to anything other then the
*exact* time (by whatever criteria you consider the time "correct"), knowing the
lunar cycle down to the millisecond is rather pointless. As is worrying about the
cycle being off a day in 16,000 years, since the amount their system time is
different from the "correct" time is probably greater then any difference between
Ethiopian Standard Chronological Man-In-The-Moon Difference Fluxation and
Mongolian Algorithm For Calculating Green Cheese Aging.

Knowing *precisely* what day and time something happens is certainly important in
some applications, but it definitely isn't in a client-side JavaScript
application where you can't even be sure the system clock will be keep proper
elapsed time between page loads.

In client-side JavaScript, I can write a cookie and store the time something
happens, I can read that cookie on the next page load and subtract the two to see
how long has elapsed, but I can't even be guaranteed that the value will be
greater on the second load then the first, since I have no control over the clock
being used to determine that information. The user may have loaded my page, reset
their system time, and reloaded the page, making the second value smaller then
the first, or larger by a ridiculous amount.

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #4
JRS: In article <3F************ ***@agricoreuni ted.com>, seen in
news:comp.lang. javascript, Grant Wagner <gw*****@agrico reunited.com>
posted at Fri, 21 Nov 2003 17:30:05 :-
Dr John Stockton wrote:
JRS: In article <u1**********@h otpop.com>, seen in
news:comp.lang. javascript, Lasse Reichstein Nielsen <lr*@hotpop.com >
posted at Thu, 20 Nov 2003 00:05:30 :-
>"Fabian" <la****@hotmail .com> writes:
>
>> Is there any way of determining when the first day of a *lunar* month
>> (far eastern lunar months if it makes a difference) falls, using
>> javascript?


It does make a difference.

<explanation snipped>


And of course, if the user's computer clock is set to anything other then the
*exact* time (by whatever criteria you consider the time "correct"), knowing the
lunar cycle down to the millisecond is rather pointless.
... ...


Determining when something occurs, in English, does not require use of
the computer clock. Showing an alert at that moment, which does, is a
different matter.

I can tell you that Gregorian Easter Sunday in the year 5702000 will
fall on St George's Day (provided that St G's D does not get moved)
without any reference whatsoever to a timepiece.

If the relevant Far Easterners have festivals fixed to the Lunar Month
in a known manner, the OP, having acquired a predictor for the right
sort of Lunar Month, will be able to determine in which years, for
example, a Festival coincides with his (Gregorian-linked) birthday. To
get this correct, and in agreement with the yet-to-be-printed Official
Calendar of Festivals, it may well be necessary to know *exactly* which
side of midnight (or Sunset, which is harder), a New Moon is deemed to
fall.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #5
> > Is there any way of determining when the first day of a *lunar* month
(far eastern lunar months if it makes a difference) falls, using
javascript?
If it is possible to calculate when it happens, then it is possible in
Javascript. Javascript is Turing complete after all (anything that can
be calculated in any language can also be calculated in Javscript).


You guys are so smart!

How about what time the moon rises (western calendar) on a given date?

I've never seen that formula, but I imagine that it could be trivial or
terribly complex!

Any idea?

Cheers,
Jeff
So, the answer to your question is "yes" (I bet that wasn't what you
really wanted to ask :).

Now, how do you do it.
Since lunar months are (according to a Google search):
29 days, 12 hours, 44 minutes and 2.87 seconds
I.e., 2551442870 ms, you can start with one point in time where
a lunar month started, and add this number to get the next month's
start.

So, assume you find one date and time that stats a lunar cycle (as exact
as possible, enter it on the first line):

var lunarDayMS = Date.UTC(startY ear,startMonth-1,startDay,
startHour,start Min,startSec,st artMS).valueOf( );
var msPerLunarMonth = 2551442870;
// find first day of this lunar month
var todayMS = new Date().valueOf( );
// subtract how far into this lunar cycle we are:
var thisStartMS = todayMS - (todayMS - lunarDayMS)%msP erLunarMonth;
var startDay = new Date(thisStartM S);

Add msPerLunarMonth to thisStartMS to get the start of the next lunar
month.

The difficult part is to find the date *and* time of the start of
the lunar month. You might want to enter it as an UTC-date instead
of just using new Date()

(and now we just need Dr. John R. Stockton to tell me where I forgot
something :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #6
Jeff Thies hu kiteb:
Is there any way of determining when the first day of a *lunar*
month (far eastern lunar months if it makes a difference) falls,
using javascript?


If it is possible to calculate when it happens, then it is possible
in Javascript. Javascript is Turing complete after all (anything
that can
be calculated in any language can also be calculated in Javscript).


You guys are so smart!

How about what time the moon rises (western calendar) on a given date?


That would also depend on latitude and longitude, but is not impossible
to calculate. Astrologers have been doing that for centuries. At least,
they used to. These days, they ask teh astronomers for help.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #7
JRS: In article <BR************ ******@newsread 1.news.atl.eart hlink.net>
, seen in news:comp.lang. javascript, Jeff Thies <no****@nospam. net>
posted at Sat, 22 Nov 2003 04:45:21 :-

How about what time the moon rises (western calendar) on a given date?

I've never seen that formula, but I imagine that it could be trivial or
terribly complex!


If you read Peter Duffett-Smith's "Practical Astronomy with your
Calculator" as far as the end of Section 66, you will have seen how to
do it; javascript can do all that is needed. It might be easier to use
one of his later books, which deal with using computers.

There is no need to restrict it to the Western Calendar; the result, in
UTC for a specific location, can be converted to any other predictable
calendar. It could get interesting when dealing with calendars where
the start of the month depends explicitly on the rising of the Moon.

For an exact result, you will need to allow for the local terrain and
current atmospheric pressure (refraction) (and possibly humidity). The
Moon travels at about 1 km/s, so for accuracy greater than about a
second you will also need to consider the exact figure of the Moon.

For a rough approximation, treating all motion as circular and co-
planar, it is fairly trivial; Moonrise is delayed by a constant amount
per day, until a day is missed. For accuracy adequate to support
navigation by lunar sightings, it is not - but the Tables could be
calculated by hand centuries ago, IIRC.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jul 20 '05 #8
Fox


Lasse Reichstein Nielsen wrote:

"Fabian" <la****@hotmail .com> writes:
Is there any way of determining when the first day of a *lunar* month
(far eastern lunar months if it makes a difference) falls, using
javascript?
If it is possible to calculate when it happens, then it is possible in
Javascript. Javascript is Turing complete after all (anything that can
be calculated in any language can also be calculated in Javscript)

So, the answer to your question is "yes" (I bet that wasn't what you
really wanted to ask :).

Now, how do you do it.
Since lunar months are (according to a Google search):
29 days, 12 hours, 44 minutes and 2.87 seconds


unfortunately, nothing astronomical is this easy...

Synodic periods of the moon are almost *never* this length -- this is
simply the average (or the "mean") synodic period. The synodic month
varies from 29d06h35m to 29d19h55m [min and max for the last 100 years]
-- and close to these extrema every 19 years. Many factors are involved
-- mostly gravitational (mainly solar), but also simple motion [the
earth speeds up and slows down in it's orbit depending on proximity to
perigee and apogee -- as does every body in elliptical orbit (including
the moon)] and other not so obvious influences like rotation and "wobble".

The synodic month from new moon @ 23Nov to new moon 23Dec is 29d 10h 44m
-- from 23Dec to 21Jan04 is 29d 11h 22m -- that's a difference of 38
minutes from this month to the next.

I.e., 2551442870 ms, you can start with one point in time where
a lunar month started, and add this number to get the next month's
start.

So, assume you find one date and time that stats a lunar cycle (as exact
as possible, enter it on the first line):

var lunarDayMS = Date.UTC(startY ear,startMonth-1,startDay,
startHour,start Min,startSec,st artMS).valueOf( );
var msPerLunarMonth = 2551442870;
// find first day of this lunar month
var todayMS = new Date().valueOf( );
// subtract how far into this lunar cycle we are:
var thisStartMS = todayMS - (todayMS - lunarDayMS)%msP erLunarMonth;
var startDay = new Date(thisStartM S);

Add msPerLunarMonth to thisStartMS to get the start of the next lunar
month.
I've seen a site using this approach last updated in April 2000 -- it is
currently 5 days off from the actual day of the new moon (23 Nov 22:59
UT). That page is displaying the next new moon as 28Nov.

The difficult part is to find the date *and* time of the start of
the lunar month.


http://aa.usno.navy.mil/data/docs/MoonPhase.html [years from 1700 - 2035
available at this site].

Data to the minute for all phases of the moon (that's about all the
accuracy you can hope for -- there are many problems concerning the
apparent [visual] position of the moon [like parallax, refraction, etc...]).

You can get "nearer" the actual event of the new moon (and not relying
on the computer's clock) with this:
var jde = 2451550.09765 + 29.530588853 * k +
t2 * ( 0.0001337 - t * (0.000000150 - t *
0.00000000073)) ;

where k is a whole number for the new moon, k + 0.25 for the first
quarter, k + 0.50 for the full moon and k + 0.75 for the last quarter...
NO OTHER VALUES have any meaning in this formula (meaning, you cannot
estimate the position of the moon at, say, k + 0.333333333...) k = 0
corresponds to the new moon of 6 Jan 2000. [negative k will give phases
before 2000].

k is originally approximated (e.g., picking today as a starting point) and
is calculated by:

k = (year - 2000) * 12.3685; // where year is the decimal year.

You can get close to the decimal year value with:

var today = new Date();

var year = today.getFullYe ar() +
(today.getMonth ()*30.3634 + today.getDate() )/365;

// for leap years, use:
// var year = today.getFullYe ar() +
// (today.getMonth ()*30.4545 + today.getDate() )/366;
// this is very "quick and dirty"

t is the time in julian centuries from epoch 2000.0. (decimalYear -
2000.0 divided by 100)

t is calculated from k as:

t = k/1236.85; // 12.3685 from above * 100 thus already in jcenturies

// and t2 = t * t;

All you need to do now is convert back from julian days to
a JS date object:

function
datefromjd(jd)
{
var jd_int_part;
var alpha;
var temp;
var A;
var B;
var C;
var D;
var E;
var jd_frac_part;
var m;
var d;
var y;
var retval;

jd_int_part = Math.floor(jd + 0.5);
jd_frac_part = (jd + 0.5) - jd_int_part;

if(jd_int_part < 2299161)
A = jd_int_part;
else
{
alpha = Math.floor((jd_ int_part - 1867216.25)/36524.25);
A = jd_int_part + 1 + alpha - Math.floor(alph a/4);
}

B = A + 1524;

C = Math.floor((B - 122.1)/365.25);

D = Math.floor(365. 25 * C);

E = Math.floor((B-D)/30.6001);

temp = Math.floor(30.6 001 * E);
d = Math.floor(B - D - temp + jd_frac_part);

if(E < 14) E -= 1;
if(E >= 14) E -= 13;
m = E;

y = C - 4715 - (m > 2 ? 1 : 0);
jd_frac_part *= 86400;

var h = Math.floor(jd_f rac_part/3600);
var min = Math.round((jd_ frac_part/60)%60); // changed from floor
var sec = 0; //Math.floor(jd_f rac_part % 60);

// seconds generally not used with phase times
// so minutes are rounded here...
// otherwise, change min and sec back for
// use with other JD calculations

return new Date(y, m-1, d, h, min, sec);

}
If more accuracy is required:
//*************** ******* routines to calculate moon phase
Date.prototype. decimalYear = function()
{
var year = this.getFullYea r();
var days = [0,31,59,90,120, 151,181,212,243 ,273,304,334];
var leap = this.getMonth() > 1 && ((year % 4 == 0 && year % 100 != 0) ||
year % 400 == 0) ? 1 : 0;

var daypart = (this.getHours( ) + this.getMinutes ()/60 + this.getSeconds ()/3600)/24;

return this.getFullYea r() + (days[this.getMonth()] + leap +
this.getDate() + daypart)/(365 + leap);

}
function
dr(n) { return n * Math.PI/180; } // convert degrees to radians

function
MoonPhase(date, phase)
{

var phases = { "new" : 0.0,
"first quarter" : 0.25,
"full" : 0.50,
"last quarter" : 0.75 };

var phaseAdj = phases[phase];

var quarterSpecific =
phase.indexOf(" quarter") != -1 ? phase.indexOf(" first") != -1 ? 1
: -1 : 0;

var useCoef = phase.indexOf(" quarter") != -1 ? "quarter" : phase;
var year = date.decimalYea r();

var k = Math.floor((yea r - 2000) * 12.3685) + phaseAdj;
var t = k/1236.85;

var t2 = t * t;

var jde = 2451550.09765 + 29.530588853 * k +
t2 * ( 0.0001337 - t * (0.000000150 -
t * 0.00000000073)) ;
// calculate solar and lunar mean anomalies
// lunar argument of latitude (F)
// lunar ascending node
// earth eccentricity (E)

var solMA = 2.5534 + 29.10535669 * k - t2 * (0.0000218 + t * 0.00000011);

var lunMA = 201.5643 + 385.81693528 * k + t2 * (0.0107438 + t *
(0.00001239 - t * 0.000000058));

var lunF = 160.7108 + 390.67050274 * k - t2 * (0.0016341 + t *
(0.00000227 - t * 0.000000011));

var lunAscNode = 124.7746 - 1.56375580 * k + t2 * (0.0020691 + t * 0.00000215);

var E = 1 - t * (0.002516 - t * 0.0000074);
// effects due to planetary motion [most significant terms]

var planetaryArgs =
[
299.77 + 0.107408 * k - 0.009173 * t * t,
251.88 + 0.016321 * k ,
251.83 + 26.651886 * k ,
349.42 + 36.412478 * k ,
84.66 + 18.206239 * k ,
141.74 + 53.303771 * k ,
207.14 + 2.453732 * k ,
154.84 + 7.30686 * k ,
34.52 + 27.261239 * k ,
207.19 + 0.121824 * k ,
291.34 + 1.844379 * k ,
161.72 + 24.198154 * k ,
239.56 + 25.513099 * k ,
331.55 + 3.592518 * k
];
// lunar correction coefficients [new, full, and quarter]

var correctionCoefs ={ "new": [
-0.4072,
0.17241 * E,
0.01608,
0.01039,
0.00739 * E,
-0.00514 * E,
0.00208 * E * E,
-0.00111,
-0.00057,
0.00056 * E,
-0.00042,
0.00042 * E,
0.00038 * E,
-0.00024 * E,
-0.00017,
-0.00007,
0.00004,
0.00004,
0.00003,
0.00003,
-0.00003,
0.00003,
-0.00002,
-0.00002,
0.00002
],
"full" : [
-0.40614,
0.17302 * E,
0.01614,
0.01043,
0.00734 * E,
-0.00515 * E,
0.00209 * E * E,
-0.00111,
-0.00057,
0.00056 * E,
-0.00042,
0.00042 * E,
0.00038 * E,
-0.00024 *E,
-0.00017,
-0.00007,
0.00004,
0.00004,
0.00003,
0.00003,
-0.00003,
0.00003,
-0.00002,
-0.00002,
0.00002
],
"quarter" : [
-0.62801,
0.17172 * E,
-0.01183 * E,
0.00862,
0.00804,
0.00454 * E,
0.00204 * E * E,
-0.00180,
-0.00070,
-0.00040,
-0.00034 * E,
0.00032 * E,
0.00032 * E,
-0.00028 * E * E,
0.00027 * E,
-0.00017,
-0.00005,
0.00004,
-0.00004,
0.00004,
0.00003,
0.00003,
0.00002,
0.00002,
-0.00002
]};

// to be used with new/full coefs
var multipliers = [
lunMA,
solMA,
2 * lunMA,
2 * lunF,
lunMA - solMA,
lunMA + solMA,
2 * solMA,
lunMA - 2 * lunF,
lunMA + 2 * lunF,
2 * lunMA + solMA,
3 * lunMA,
solMA + 2 * lunF,
solMA - 2 * lunF,
2 * lunMA - solMA,
lunAscNode,
lunMA + 2 * solMA,
2 * lunMA - 2 * lunF,
3* solMA,
lunMA + solMA - 2 * lunF,
2 * lunMA + 2 * lunF,
lunMA + solMA + 2 * lunF,
lunMA - solMA + 2 * lunF,
lunMA - solMA - 2 * lunF,
3 * lunMA + solMA,
4 * lunMA
];

// to be used with first/last quarter coefs
var qmultipliers = [
lunMA,
solMA,
lunMA + solMA,
2 * lunMA,
2 * lunF,
lunMA - solMA,
2 * solMA,
lunMA - 2 * lunF,
lunMA + 2 * lunF,
3 * lunMA,
2 * lunMA - solMA,
solMA + 2 * lunF,
solMA - 2 * lunF,
lunMA + 2 * solMA,
2 * lunMA + solMA,
lunAscNode,
lunMA - solMA - 2 * lunF,
2 * lunMA + 2 * lunF,
lunMA + solMA + 2 * lunF,
lunMA - 2 * solMA,
lunMA + solMA - 2 * lunF,
3 * solMA ,
2 * lunMA - 2 * lunF,
lunMA - solMA + 2 * lunF,
3 * lunMA + solMA

];
// only required for first || last quarter
var forQuarters = 0.00306 - 0.00038 * E * Math.cos(dr(sol MA)) +
0.00026 * Math.cos(dr(lun MA)) -
0.00002 * Math.cos(dr(lun MA - solMA)) +
0.00002 * Math.cos(dr(lun MA + solMA)) +
0.00002 * Math.cos(dr(2 * lunF));
// correction calcs are sums of series
var corrections = 0;

var mults = useCoef == "quarter" ? qmultipliers : multipliers;

for(var i = 0; i < multipliers.len gth; i++)
corrections += correctionCoefs[useCoef][i] * Math.sin(dr(mul ts[i]));

var allphasecoefs = [
0.000325,
0.000165,
0.000164,
0.000126,
0.000110,
0.000062,
0.000060,
0.000056,
0.000047,
0.000042,
0.000040,
0.000037,
0.000035,
0.000023
];

var addcorrections = 0;

for (var i = 0; i < allphasecoefs.l ength; i++)
addcorrections += allphasecoefs[i] * Math.sin(dr(pla netaryArgs[i]));
// deltaT for 23Nov2003
// "close enough" for +/- a few years if necessary...
// but better if "accurate"
// deltaT is in seconds -- convert to "days"

var deltaT = -64.5659/86400; // deltaT is subtracted from terrestial time
var timeofphase = jde + deltaT + corrections +
addcorrections + quarterSpecific * forQuarters;
return datefromjd(time ofphase); // date is UT -- apply timezone for
local time
}
alert( "new moon: " + MoonPhase(today , "new") + "\n" +

"first quarter: " + MoonPhase(today , "first quarter") +"\n"
+

"full moon: " + MoonPhase(today , "full") +"\n" +

"last quarter: " + MoonPhase(today , "last quarter"));

//compare with usno data from moon phase url above


Notes:

whereas we generally know to take into account leap year days in
calendar calculations, we often forget about all the leap seconds that
have been added to our time over the last 45+ years [from about 1958].
The necessity for adding new leap seconds cannot be known (or
predicted!) until the "drift" of our time keeping devices from ephemeris
time is detected and adjusted [ephemeris time is defined as the measure
of time that brings the observed positions of the celestial bodies into
accord with the Newtonian dynamical theory of motion]. Currently, that
drift is about 65 seconds.

deltaT does NOT vary uniformly -- the observatory database maintains
data for each day!

here's a short "table" that can be used "in a pinch":

observedDeltaT = [63.83, 64.09, 64.30, 64.47, 65.8, 66, 67, 68, 69, 70,
70, 71, 72, 73];

values from 2000.0 to 2014.0 -- the whole number values are predictions
(as is index 4)...

using this array and interpolating to the end of november/beginning of december:
var curDeltaT = observedDeltaT[y - 2000] +
(observedDeltaT[y+1-2000] - observerdDeltaT[y-2000]) * dayNum/(365
+ leap);

for y = 2003 (e.g., this year)
and dayNum = 334 [1 december]
the result is ~65.687 seconds [and this is very close to the current
observed value]

so interpolating (for the near present) is a viable way to handle deltaT
from lookup tables for "our time" [or simply use the value from the
array index for the entire year]
Observed values for deltaT are available from the US Naval Observatory
online
(http://aa.usno.navy.mil/data -- time services dept - systems of time).
There are also formulae for estimating deltaT in the near future [see
http://maia.usno.navy.mil/ser7/ser7.dat -- under PREDICTIONS]

For formulae to estimate deltaT in the "far past", check out:
http://www.phys.uu.nl/~vgent/astro/deltatime.htm [or from Astronomical
Algorithms, Meeus]
All other moon phase formulae from Jean Meeus' Astronomical Algorithms...

If you have access to php or other serverside language, the deltaT
values can be fetched from usno and plugged into the javascript.
The accuracy of the routine above is within 0.5 minutes (more like <10
seconds) from at least 1993.0 until at least 2006.0 (even with the
"fixed" deltaT) -- there seems to be a difference in rounding at around
the 30 second mark -- otherwise, the data is consistent with USNO --
that's pretty damn good for JavaScript. Remember that only the *most*
signicant terms of the correction series are used. The accumulation of
error from the ignored terms will increase with time further away from
1Jan2000 (both in the past and in the future).
Jul 20 '05 #9
JRS: In article <3F************ ***@fxmahoney.c om>, seen in
news:comp.lang. javascript, Fox <fo*@fxmahoney. com> posted at Sun, 23 Nov
2003 00:59:51 :-
Date.prototype .decimalYear = function()
{
var year = this.getFullYea r();
var days = [0,31,59,90,120, 151,181,212,243 ,273,304,334];
var leap = this.getMonth() > 1 && ((year % 4 == 0 && year % 100 != 0) ||
year % 400 == 0) ? 1 : 0;

var daypart = (this.getHours( ) + this.getMinutes ()/60 +
this.getSecond s()/3600)/24;

return this.getFullYea r() + (days[this.getMonth()] + leap +
this.getDate() + daypart)/(365 + leap);

}

I see two problems with that.

The calculation of moon phase must depend on true time, not clock time;
yet that is not UTC-based.

Var leap depends both on whether the year is Leap and on whether it is
March or later; and it is used to calculate the length of the year. A
leap year has 366 days all year long, not just after Feb 29.

The following seems better, but gives a different answer :

Date.prototype. DY = function() {
var Yr = this.getFullYea r() // or getUTCFullYear( )
var T0 = Date.UTC(Yr), T1 = Date.UTC(Yr+1)
return Yr + (this-T0)/(T1-T0) }

It gives the present moment as a fraction of the UTC year of the same
number as the present year. Those presently on GMT will see no
difference.

Astro calculations need to be done in UTC, with some final caution if
events for "today" are involved.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links;
some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2337
by: bryanilton | last post by:
I was hoping someone could help me with this.. I'm not very familiar with javascript but I'm pretty sure it can help me with what I need to accomplish. I've tried piecing several pieces of script together but I've had no luck so far. What I need to do is have a user input for Year, Month and day (preferably drop down) and compare the input to today's date and display the difference in months. Any help with this would be appreciated.
1
2432
by: Lisa | last post by:
Hello! I need help to organize the working time spent by each employee on projects. I have many projects going on, staring at different dates, and each employee can work on 0/N projects, for # months. I built three tables: Projects, Employees, Manmonths Manmonths contains: project_id, empl_id and number of months. WHen I ask for a report, I would like to see if a man is working on too many projects, e.g. is working for more than 12 months...
6
27999
by: carl.barrett | last post by:
Hi, I have a continuous form based on a query ( I will also be creating a report based on the same query). There are 2 fields: Date Obtained and Date Of Expiry I want a further 3 columns to the right of these 2 fields to show the
5
2003
by: Rajat Tandon | last post by:
Hello Everybody, Please guide me so that I can fulfill this challenging assisnment ... I have been asked to "Restructure a Windows application" from scratch in 2 months. The existing application which is working but it is very heavy as no proper application architecture and layering has been followed for this. It was really hard to maintain (as I was maintaing it till now) . First let me tell u a bit about my application ...
4
1876
by: joder2006 | last post by:
So I'm working on this class and I have a major problem. This class happens to be for a rocket, it's a game that you play and you try to see it you can land safely from 1000 meters up in the air. The problem is when I input the throttle the program ignores it. It doesn't matter what i input into the throttle i get the same result. There are also other problems as well.
11
2471
by: Harlin Seritt | last post by:
Is there a module that can pull str values for say the last 3 months? Something like: print lastMonths(3) Thanks
1
3673
by: =?Utf-8?B?bGF3ODc4Nw==?= | last post by:
i am looking for some MS Excel formula or MS Visal Basic Marco for converting Date to Lunar Date. tks
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.