Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-02-2008, 01:25 AM
okhissabigfish okhissabigfish is offline
 
Join Date: May 2008
Posts: 69
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Challenge: Sunrise/Sunset on your forum?

I have a fishing lake website. Fishing rules state that fishing shall start at sunrise and end at sunset daily. I found this code and would love to place a form that places the data somewhere on forumhome.

This kind of creation is a bit over my head...but, I haven't seen anyone work with date/time/events too much here. Anyone up for the challenge? Hopefully when done the member will be able to read the output on screen at page reload, etc. I've not tested this script.

Quote:
SunRise/SunSet Code:

<?php

class Astro_Sunrise {

// coordinates to calculate sunrise/sunset for
var $lat = 47.0452; // -90..+90; > 0 is north of the equator
var $lon = 7.2715; // -180..+180; > 0 is east of Greenwich

// date
var $year; // 4 digits, please
var $month;
var $mday; // day of the month
var $tz; // timezone offset in hours, > 0 is east of GMT, < 0 is west
var $yday; // day of the year

var $twilight = array(
'effective' => -.0145439, // sunrise/sunset
'civil' => -.104528, // civil twilight
'nautical' => -.207912, // nautical twilight
'astronomical' => -.309017 // astronomical twilight
);

var $R; // radius used for twilight calculation

var $last_utc; // UNIX timestamp of last calculation

function Astro_Sunrise() {
$this->setTwilight('effective');
}

function setCoords($lat, $lon) {
if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180)
return null;
$this->lat = $lat;
$this->lon = $lon;
}

function getCoords() {
return sprintf('%1.4f %s %1.4f %s',
abs($this->lat), $this->lat < 0 ? 'S' : 'N',
abs($this->lon), $this->lon < 0 ? 'W' : 'E'
);
}

function setDate($year, $month, $mday) {
if ($year < 100)
$year += 1900;
if ($year < 1600 || !checkdate($month, $mday, $year))
return null;

$this->year = $year;
$this->month = $month;
$this->mday = $mday;

$daysinmonth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
$this->yday = $daysinmonth[$month - 1] + $mday - 1;
if ($month > 2 && ($year % 4) == 0 && (($year % 100) != 0 || ($year % 400) == 0))
$this->yday++;
}

function getDate() {
return sprintf('%04d-%02d-%02d', $this->year, $this->month, $this->mday);
}

function setTimestamp($time) {
list($this->year, $this->month, $this->mday, $this->yday) =
explode(':', date('Y:n:j:z', $time));
}

function setTimezone($tz=0) {
if ($tz < -13 || $tz > 13)
return null;
$this->tz = $tz;
}

function getTimezone() {
$tz = abs($this->tz);
if ($tz == 0)
return 'UTC';
$hours = intval($tz);
$mins = intval(($tz - $hours) * 60 + 0.5);
return sprintf('%s%02d%02d', $this->tz < 0 ? '-' : '+', $hours, $mins);
}

function setTwilight($type) {
if (!array_key_exists($type, $this->twilight))
return null;
$this->R = $this->twilight[$type];
}


function getSunrise() {
return $this->calcSunrise(true);
}

function getSunset() {
return $this->calcSunrise(false);
}

function getLastSwatchBeat() {
$tm = ($this->last_utc + 3600) % 86400; // MEZ
return sprintf("@%03d", 1000 * $tm / 86400);
}

function calcSunrise($isRise) {

// multiples of pi
$A = 0.5 * M_PI; // Quarter circle
$B = M_PI; // Half circle
$C = 1.5 * M_PI; // 3/4 circle
$D = 2 * M_PI; // Full circle

// convert coordinates and time zone to radians
$E = $this->lat * $B / 180;
$F = $this->lon * $B / 180;
$G = $this->tz * $D / 24;

$J = $isRise ? $A : $C;

$K = $this->yday + ($J - $F) / $D;
$L = $K * .017202 - .0574039; // Solar Mean Anomoly
$M = $L + .0334405 * sin($L); // Solar True Longitude
$M += 4.93289 + 3.49066E-4 * sin(2 * $L);

// Quadrant Determination
$M = norm($M, $D);

if (($M / $A) - intval($M / $A) == 0)
$M += 4.84814E-6;
$P = sin($M) / cos($M); // Solar Right Ascension
$P = atan2(.91746 * $P, 1);

// Quadrant Adjustment
if ($M > $C)
$P += $D;
elseif ($M > $A)
$P += $B;

$Q = .39782 * sin($M); // Solar Declination
$Q /= sqrt(-$Q * $Q + 1);
$Q = atan2($Q, 1);

$S = $this->R - sin($Q) * sin($E);
$S /= cos($Q) * cos($E);

if (abs($S) > 1)
return "(Mitternachtssonne/Dauernacht)";

$S /= sqrt(-$S * $S + 1);
$S = $A - atan2($S, 1);

if ($isRise)
$S = $D - $S;

$T = $S + $P - 0.0172028 * $K - 1.73364; // Local apparent time
$U = $T - $F; // Universal time
$V = $U + $G; // Wall clock time

// Quadrant Determination
$U = norm($U, $D);
$V = norm($V, $D);

// Scale from radians to hours
$U *= 24 / $D;
$V *= 24 / $D;

// Universal time
$hour = intval($U);
$U = ($U - $hour) * 60;
$min = intval($U);
$U = ($U - $min) * 60;
$sec = intval($U);
$this->last_utc = gmmktime($hour, $min, $sec, $this->month, $this->mday, $this->year);

// Local time
$hour = intval($V);
$min = intval(($V - $hour) * 60);

return sprintf('%02d:%02d', $hour, $min);

} // function calcSunrise

} // class Astro_SunTime

function norm($a, $b) { // normalize $a to be in [0, $b)
while ($a < 0)
$a += $b;
while ($a >= $b)
$a -= $b;
return $a;
} // function norm

?>
Reply With Quote
  #2  
Old 07-02-2008, 03:05 AM
Bellardia Bellardia is offline
 
Join Date: Jul 2007
Location: Hamilton, Ontario
Posts: 378
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This script, as it is, has no output.
It does however include several functions related to sunrise & sunset.
What is your desired output from this script?
Reply With Quote
  #3  
Old 07-02-2008, 03:11 AM
okhissabigfish okhissabigfish is offline
 
Join Date: May 2008
Posts: 69
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Based on either city, state or longitude/latitude (what ever the script requires) it would state the sunrise and sunset times for each day of the year. Hopefully placed near the NavBar or right under it.

I have the longitude and latitude of the lake's location. City= Bude, Mississippi.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:29 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03586 seconds
  • Memory Usage 2,205KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete