/** * Calculates the nutation in longitude * * * @param int|float $year The year, for example: 2000, -1000, 0, or a Julian day * @param int|bool $month The month, from 1 to 12, or false if the previous parameter is a Julian day * @param int|float $day The day, from 1 to 31, or with decimals * @param int $hours The hours, from 0 to 23 * @param int $minutes The minutes, from 0 to 59 * @param float $seconds The seconds, from 0 to 59, or with decimals * @param string $format The format of the nutation in longitude: DEGREES, RADIANS, SECONDS, default = SECONDS * @param bool $use_cache Caches the arguments of the nutation during the calculation, default = true * @return float The nutation in longitude */ function aa_nutation_in_longitude($year, $month, $day = null, $hours = null, $minutes = null, $seconds = null, $format = null, $use_cache = true) { global $_aa_nutation_periodic_terms; if ($month === false) { // the year is actually a Julian day $julian_day = $year; } else { // a date is passed, calculates the Julian day $julian_day = aa_date_to_julian_day($year, $month, $day, $hours, $minutes, $seconds); if ($julian_day === false) { return false; } } $T = ($julian_day - 2451545) / 36525; $nutation_arguments = aa_nutation_arguments($T, $use_cache); $nutation_in_longitude = 0; foreach ($_aa_nutation_periodic_terms as $index => $terms) { list(, , , , , $coef0_sin, $coef1_sin) = $terms; $nutation_in_longitude += ($coef0_sin + $coef1_sin * $T) * sin($nutation_arguments[$index]) * 0.0001; } if ($format !== null) { $nutation_in_longitude = aa_seconds_to_format($nutation_in_longitude, $format); } return $nutation_in_longitude; }
/** * Calculates the day of the week for a given date * * @param int $year The year, for example: 2000, -1000, 0 * @param int $month The month, from 1 to 12 * @param float $day The day, from 1 to 31, or with decimals * @return int|bool The day of the week, for example: 0, 1, 2, 3, 4, 5, 6, or false on error */ function aa_day_of_week($year, $month, $day) { $julian_day = aa_date_to_julian_day($year, $month, (int) $day); if ($julian_day === false) { return false; } $julian_day += 1.5; $day_of_week = $julian_day % 7; return $day_of_week; }
/** * Calculates the number of days between two dates * * The calendar in which each date falls is automatically detected. * This algorithm is invalid for negative Julian days. * @param int $year_from The year from, for example: 2000, -1000, 0 * @param int $month_from The month from , from 1 to 12 * @param float $day_from The day from, from 1 to 31, or also: 1.5, 2.75, 30.25 * @param int $year_to The year to, for example: 2000, -1000, 0 * @param int $month_to The month to , from 1 to 12 * @param float $day_to The day to, from 1 to 31, or also: 1.5, 2.75, 30.25 * @return float|bool The number of days or false on error */ function aa_date_difference($year_from, $month_from, $day_from, $year_to, $month_to, $day_to) { $julian_day_from = aa_date_to_julian_day($year_from, $month_from, $day_from); if ($julian_day_from === false) { return false; } $julian_day_to = aa_date_to_julian_day($year_to, $month_to, $day_to); if ($julian_day_to === false) { return false; } $days = $julian_day_to - $julian_day_from; return $days; }
/** * Adds a number of days to a date * * The calendar in which the date falls is automatically detected. * This algorithm is invalid for negative Julian days. * * @param int $year The year, for example: 2000, -1000, 0 * @param int $month The month, from 1 to 12 * @param float $day The day, from 1 to 31, or with decimals * @param float $days_to_add The number of days to add, example: 1, 2, -1, -2, -1.25, 1.5 * @return array|bool The new year or false on error * @returns int 0 The year * @returns int 1 The month * @returns float 2 The day */ function aa_add_days_to_date($year, $month, $day, $days_to_add) { $julian_day = aa_date_to_julian_day($year, $month, $day); if ($julian_day === false) { return false; } $julian_day += $days_to_add; if ($julian_day < 0) { aa_set_error('This algorithm is invalid for negative Julian days.'); return false; } $new_date = aa_julian_day_to_date($julian_day); return $new_date; }
/** * Calculates the mean sidereal time at Greenwich * * The calendar in which the date falls is automatically detected. * This algorithm is invalid for negative Julian days. * * @param int $year The year, for example: 2000, -1000, 0 * @param int $month The month, from 1 to 12 * @param int|float $day The day, from 1 to 31, or with decimals * @param int $hours The hours, from 0 to 23 * @param int $minutes The minutes, from 0 to 59 * @param float $seconds The seconds, from 0 to 59, or with decimals * @param string $format The format of the mean sidereal time: DMS, HMS, MOD360, NONE, RADIANS, default = HMS * @param bool $mod360 True to convert degrees to a value between 0 and 360 degrees before formating, * false otherwise, default = true * @return float|array|bool The mean sidereal time at Greenwich * @returns int 0 The hours or degrees * @returns int 1 The minutes * @returns float 2 The seconds */ function aa_greenwich_mean_sidereal_time($year, $month, $day, $hours = null, $minutes = null, $seconds = null, $format = null, $mod360 = true) { is_null($format) and $format = 'HMS'; $julian_day = aa_date_to_julian_day($year, $month, (int) $day); if ($julian_day === false) { return false; } $T = ($julian_day - 2451545) / 36525; $T2 = $T * $T; $T3 = $T2 * $T; $mean_sidereal_time = 100.46061837 + 36000.770053608 * $T + 0.000387933 * $T2 - $T3 / 38710000; $time = (($day - (int) $day) * 24 + $hours) * 3600 + $minutes * 60 + $seconds; $mean_sidereal_time += 1.00273790935 * $time / 240; // 3600 / 24 * 360 = 240 $mean_sidereal_time = aa_degrees_to_format($mean_sidereal_time, $format, $mod360); return $mean_sidereal_time; }
<?php /** * * Astronomical Algorithms UI Defaults * * @author Michel Corne <*****@*****.**> * @copyright 2012 Michel Corne * @license http://opensource.org/licenses/mit-license.php MIT */ require_once ROOT . '/api/aa-date-to-julian-day.php'; $year = date('Y'); $month = date('n'); $day = date('j'); return array('day' => $day, 'degrees' => 90, 'height' => 1706, 'hours' => 6, 'is_positive' => true, 'julian_day' => aa_date_to_julian_day($year, $month, $day), 'latitude' => 33.356111, 'minutes' => 0, 'month' => $month, 'seconds' => 0, 'year' => $year);
/** * Calculates the Julian day corresponding to January 0.0 of a given year * * This is the same number as for December 31.0 of the preceding year. * The calendar in which the date falls is automatically detected. * This algorithm is invalid for negative Julian days. * * @param int $year The year, for example: 2000, -1000, 0 * @param int $month The month, from 1 to 12 * @param float $day The day, from 1 to 31, or with decimals * @return float|bool The Julian day or false on error */ function aa_date_to_julian_day0($year) { $julian_day0 = aa_date_to_julian_day($year - 1, 12, 31); return $julian_day0; }