#Moonbeams
Javscript library for doing astronomical calculations
var moonbeams = require('moonbeams');
var spring95 = moonbeams.season(0, 1995);
Only methods backed up by tests will be listed here
Convert a given year, month, and day into a decimal julian day
Year and month should be integers, day can be a decimal. To convert hours, minutes, and seconds into decimal see hmsToDay
Cannot convert from a date that would result in a negative julian day
Convert a given decimal julian day into a calendar day. Given julian day must be positive. Returns an object with year
, month
, and day
attributes. day
will be a decimal you can pass to dayToHms
to get the hours, minutes, and seconds from.
Convert a given hour, minute, and second to decimal. Second can be a decimal to represent precision higher than 1 second.
var day = 8;
var hour = 13;
var minute = 30;
var second = 45.2;
var fullDay = day + moonbeams.hmsToDay(hour, minute, second);
//fullDay will now be `8.563...`
Retrieve the hour, minute, and second from the decimal portion of a day. Returns an object with attributes hour
, minute
, and second
. Second may be a decimal number.
Convert a given hour, minute, and arcsecond to right ascention. Second can be a decimal to represent precision higher than 1 arcsecond.
Convert a given decimal right ascention into hours, minutes, and (arc)seconds. Returns an object with attributes for hour
, minute
, and second
. Second may be a decimal number.
Returns the integer portion of a given decimal number. This is different than Math.floor
as it doesn't round down, but rounds towards zero
Returns the current julian cycle, aka the julian cycle since Jan 1, 2000
So, moonbeams.INT(4.999)
is 4
and moonbeams.INT(-4.999)
is -4
Takes an integer year and returns true
if that year is a leap year
Returns integer day of week (0-6 where 0 is Sunday) for given julian day
Returns integer day of year (1-365 or 366) for given julian day
Calculate the calendar day of a given day of the year and year. Returns an object with year
, month
, and day
attributes.
Returns the mean sidereal Time at Greenwich for given julian day
Find the decimal julian day that a given season starts in a given year. seasonIndex
is as follows
- 0 - March Equinox
- 1 - June Solstice
- 2 - September Equinox
- 3 - December Solstice
Year must be between -1000 and 3000.
Years should be integers, positive or negative. BC years are simply negative years, for example the year 585 BC is really -584.
#License MIT
Most of the calculations in this library are from Astronomical Algorythms by John Meeus without which libraries like this would likely never exist.
Unless specifically stated otherwise, all julian days are in dynamical time and can be decimal