# TNET Services, Inc.
#
# Copyright: (c) 1992-2007 Copyright TNET Services, Inc.
############################################################################
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
############################################################################
# This document uses Tab 4 Settings
############################################################################
// Version 1.01 - 22-Jan-2012 - fixes for mixed date format translations
require_once("Settings.php");
require_once("common.php");
############################################################################
$TITLE= $SITE['organ'] . " - " . langtransstr("Astronomy");
$showGizmo = true; // set to false to exclude the gizmo
include("top.php");
############################################################################
?>
'') { // do astronomy only if station is configured
if(isset($SITE['WXsoftware']) and $SITE['WXsoftware'] == 'WD') {
// Sample from WD: $moonage = "Moon age: 10 days,10 hours,41 minutes,80%"; // current age of the moon (days since new moon)
// Sample from WD: $moonphase = "80%"; // Moon phase %
$moonagedays = preg_replace('|^Moon age:\s+(\d+)\s.*$|is',"\$1",$moonage);
if(!isset($moonphase) or $moonphase == '') { // MAC version of WD is missing this value
preg_match_all('|(\d+)|is',$moonage,$matches);
$moonphase = $matches[1][3];
if(isset($matches[1][4])) {
$moonphase .= '.' . $matches[1][4]; // pick up decimal;
$moonphase = round($moonphase,0);
}
$moonphase .= '%';
}
$moonphasename = moonphase($moonage);
} else { // perform non-WD moon stuff
$mooninfo = cGetMoonInfo(); /* Note: getMoonInfo() is located in common.php */
print "\n";
if(!isset($moonphase)) {$moonphase = $mooninfo->ill.'%'; }
if(!isset($newmoon)) {$newmoon = $mooninfo->NMWD; }
if(!isset($nextnewmoon)) {$nextnewmoon = $mooninfo->Q4WD; }
if(!isset($firstquarter)) {$firstquarter = $mooninfo->Q1WD; }
if(!isset($lastquarter)) {$lastquarter = $mooninfo->Q3WD; }
if(!isset($fullmoon)) {$fullmoon = $mooninfo->FMWD; }
if(!isset($moonphasename)) {$moonphasename = $mooninfo->phase;}
if(!isset($moonagedays)) {$moonagedays = $mooninfo->pic; }
if(!isset($moonage)) {$moonage = 'Moon age: '.$mooninfo->age.','.$mooninfo->ill.'%'; }
$seasoninfo = cGetSeasonInfo(); /* Note: getSeasonInfo() is located in common.php */
if(!isset($marchequinox) and isset($seasoninfo->spring)) {$marchequinox = $seasoninfo->spring; }
if(!isset($junesolstice) and isset($seasoninfo->summer)) {$junesolstice = $seasoninfo->summer; }
if(!isset($sepequinox) and isset($seasoninfo->fall)) {$sepequinox = $seasoninfo->fall; }
if(!isset($decsolstice) and isset($seasoninfo->winter)) {$decsolstice = $seasoninfo->winter; }
if(file_exists("get-USNO-sunmoon.php")) {
include_once("get-USNO-sunmoon.php");
$USNOdata = getUSNOsunmoon();
}
if(isset($USNOdata['sunrise'])) {$sunrise = $USNOdata['sunrise']; }
if(isset($USNOdata['sunrisedate'])) {$sunrisedate = $USNOdata['sunrisedate']; }
if(isset($USNOdata['sunset'])) {$sunset = $USNOdata['sunset']; }
if(isset($USNOdata['sunsetdate'])) {$sunsetdate = $USNOdata['sunsetdate']; }
if(isset($USNOdata['moonrise'])) {$moonrise = $USNOdata['moonrise']; }
if(isset($USNOdata['moonrisedate'])) {$moonrisedate= $USNOdata['moonrisedate']; }
if(isset($USNOdata['moonset'])) {$moonset = $USNOdata['moonset']; }
if(isset($USNOdata['moonsetdate'])) {$moonsetdate = $USNOdata['moonsetdate']; }
if(isset($USNOdata['moonphase'])) {$moonphasename = $USNOdata['moonphase']; }
if(isset($USNOdata['illumination'])) {$moonphase = $USNOdata['illumination']; }
if(isset($USNOdata['hoursofpossibledaylight'])) {$hoursofpossibledaylight = $USNOdata['hoursofpossibledaylight'];}
}
?>
Note: Astronomy information not available since weather station not yet specified.
\n"; } ?>
\n";
$mdays = $matches[1][0];
$mhours = $matches[1][1];
$mmins = $matches[1][2];
$mpct = $matches[1][3];
$mdaysd = $mdays + ($mhours / 24) + ($mmins / 1440);
// Definitions from http://www.answers.com/topic/lunar-phase
// * Dark Moon - Not visible
// * New Moon - Not visible, or traditionally, the first visible crescent of the Moon
// * Waxing Crescent Moon - Right 1-49% visible
// * First Quarter Moon - Right 50% visible
// * Waxing gibbous Moon - Right 51-99% visible
// * Full Moon - Fully visible
// * Waning gibbous Moon - Left 51-99% visible
// * Third Quarter Moon - Left 50% visible
// * Waning Crescent Moon - Left 1-49% visible
// * New Moon - Not visible
if ($mdaysd <= 29.53/2) { // increasing illumination
$ph = "Waxing";
$qtr = "First";
} else { // decreasing illumination
$ph = "Waning";
$qtr = "Last";
}
if ($mpct < 1 ) { return("New Moon"); }
if ($mpct <= 49) { return("$ph Crescent"); }
if ($mpct < 51) { return("$qtr Quarter"); }
if ($mpct < 99) { return("$ph Gibbous"); }
return("Full Moon");
}
# perform two-way translation on UTC String from WD for astronomical dates
# first, change from WD UTC date format (possibly in non-English) to English
# second, change from English to targeted language (possibly leave in English)
function get_utcdate ( $indate ) {
global $SITE, $sourceMonths;
$EnglishMonths = array(
'January','February','March','April','May','June',
'July','August','September','October','November','December');
$utcstr = substr($indate,10) . " " . substr($indate,0,9); // move formats
if (isset($SITE['monthNames'])) {
// convert TO English for strtotime()
echo "\n";
foreach ($EnglishMonths as $i => $monthEN) {
$utcstr = preg_replace('| '.$SITE['monthNames'][$i].' |i'," $monthEN ",$utcstr);
}
echo "\n";
}
$lclstr = $utcstr;
if (isset($SITE['langMonths'])) {
// convert From English for return (will only work if long-format month names in $timeFormat)
echo "\n";
foreach ($EnglishMonths as $i => $monthEN) {
$lclstr = preg_replace('| '.$monthEN.' |i',' '.$SITE['langMonths'][$i].' ',$lclstr);
}
echo "\n";
}
return ($lclstr);
}
function get_localdate ( $indate) {
global $SITE;
$EnglishMonths = array(
'January','February','March','April','May','June',
'July','August','September','October','November','December');
// Change '02:33 UTC 4 September 2007' to
// specified date by
$timeFormat = 'D, d-M-Y h:ia T'; // Fri, 31-Mar-2006 14:03 TZone
// $timeFormat = 'h:ia T D, d-M-Y '; // Fri, 31-Mar-2006 14:03 TZone
if(isset($SITE['timeFormat'])) { $timeFormat = $SITE['timeFormat']; }
$utcstr = substr($indate,10) . " " . substr($indate,0,9); // move formats
echo "\n";
// input dates are assumed to be in English only
if (isset($SITE['monthNames'])) {
// convert TO English for strtotime()
echo "\n";
foreach ($EnglishMonths as $i => $monthEN) {
$utcstr = preg_replace('| '.$SITE['monthNames'][$i].' |i'," $monthEN ",$utcstr);
}
echo "\n";
}
$utc = strtotime($utcstr);
$lclstr = date($timeFormat,$utc);
if (isset($SITE['langMonths'])) {
// convert From English for return (will only work if long-format month names in $timeFormat)
echo "\n";
foreach ($EnglishMonths as $i => $monthEN) {
$lclstr = preg_replace('| '.$monthEN.' |i',' '.$SITE['langMonths'][$i].' ',$lclstr);
}
echo "\n";
}
return ($lclstr);
}
//=========================================================================
// change the hh:mm AM/PM to h:mmam/pm format or format spec by $timeOnlyFormat
function adjustWDtime ( $WDtime ) {
global $timeOnlyFormat,$DebugMode;
if ($WDtime == "00:00: AM") { return ''; }
$t = explode(':',$WDtime);
if (preg_match('/pm/i',$WDtime)) { $t[0] = $t[0] + 12; }
if ($t[0] > 23) {$t[0] = 12; }
if (preg_match('/^12.*am/i',$WDtime)) { $t[0] = 0; }
$t2 = join(':',$t); // put time back to gether;
$t2 = preg_replace('/[^\d\:]/is','',$t2); // strip out the am/pm if any
$r = date($timeOnlyFormat , strtotime($t2));
if ($DebugMode) {
$r = "" . $r;
$r = '