cloudy cloudy

Author Topic: Daylight hours script does not display longer than yesterday info  (Read 466 times)

0 Members and 1 Guest are viewing this topic.

Offline rford

  • Posts: 321
  • Raleigh, North Carolina
  • OS/Browser:
  • Win NT 10.0
  • Firefox 64.0
    • Turner Downs Weather
I'm in the process of updating my site and having a little trouble with the Daylight Hours script.  The script that I'm using is:
Code: [Select]
<p class="sideBarTitle">Daylight Hours</p>
<br />
<div class="sideBarText" style="font-weight:lighter; font-size: 9px; text-align: center; margin-bottom: -4px;">
<?php
 //Make piechart
 $testtime substr($hoursofpossibledaylight,0,2);
 $testminute substr($hoursofpossibledaylight,3,2);
 $testminute=$testminute/60;
 $testresult=$testtime+$testminute;
 $testljus=round(($testresult/24)*100,1);
 $testmorker=100-$testljus;
 ?>

<span class="thisPage" style="position: relative; font-weight:lighter; font-size:11px;">
<?php
 $time_arr explode(':'$hoursofpossibledaylight2);
 echo (int)$time_arr[0] . " hrs " . (int)$time_arr[1] . " min";
 echo '<br />of daylight today<br />';
 ?>

</span>
<img style="margin-top: 4px;" src="http://chart.apis.google.com/chart?chs=100x70&amp;chma=0,0,0,0&amp;chd=t:<?php echo $testljus;?>,<?php echo $testmorker;?>&amp;cht=p3&amp;chp=1.6&amp;chf=bg,s,cccccc&amp;chco=ffd700,000000" alt="graph" />
<br />
<span style="position:relative; float:left; margin-top: -42px; margin-left:17px; font-weight:lighter; color:#000000;">        <!-- was -5 -->
<?php echo $testljus "%"?>
</span>
<span style=" position:relative; float:right; margin-top: -42px; margin-right:17px; font-weight:lighter; color:#ffffff;">      <!-- was 5 -->
<?php echo $testmorker "%"?>
</span>
<span class="thisPage" style=" position:relative; font-weight:lighter; font-size:11px; top: -8px">
<?php
 echo '<br />Which is <br />';
 $time_arr explode(':'$changeinday);
 if (substr($time_arr[0],0,1) != "-") {         // -0 when getting shorter
 echo (int)$time_arr[1] . " min longer";
 } else {
 echo (int)$time_arr[1] . " min shorter";
 }
 echo ('<br />than yesterday');
 ?>

</span>
 

Could someone tell me if there is an updated code or, if possible, look at my existing code to see what my problem may be....I'm just a cut, paste and pray guy...so any help would be appreciated.

My site is http://www.turnerdownsweather.com/

Thanks again
Ronnie

Offline ed2kayak

  • CoCoRaHS PA-CD-6, Weather Underground KPAMECHA7, CWOP DW5425
  • Posts: 458
  • Mechanicsburg PA
  • OS/Browser:
  • Win NT 10.0
  • Chrome 71.0.3578.98
    • Cumberland Valley Weather
Re: Daylight hours script does not display longer than yesterday info
« Reply #1 on: January 04, 2019, 03:33:26 PM »
Hopefully someone knows.

I have same issue, see my side menu on forecast page.

http://cvweather.org/wxforecast.php

edit - added attachment
« Last Edit: January 04, 2019, 03:56:46 PM by ed2kayak »
Ed
CoCoRaHS PA-CD-6,  Weather Underground KPAMECHA7, CWOP DW5425

Offline niko

  • syzygy
  • Global Moderator
  • Posts: 28,174
  • Crystal Ball broken! Please post the URL.
  • Northern California, U.S.A.
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Chrome 71.0.3578.98
Re: Daylight hours script does not display longer than yesterday info
« Reply #2 on: January 04, 2019, 06:17:59 PM »
Blame it on astrophysics guys  :lol:  At this time of year the length of day is changing very slowly, for Raleigh NC my own script shows an increase of 45 seconds. I haven't studied the posted script but at first glance it only has a one minute resolution so you are seeing the increase as 0 minutes.

If you want a more precise calculation try this:

Code: [Select]
<?php
$stationlat 
=  35.78;
$stationlong =  -78.64;
$z 90.83333;
$tzz 'America/New_York';
date_default_timezone_set($tzz);

//get the current offset from UTC
$WXTimeZone = new DateTimeZone($tzz);
$WXdateTime = new DateTime("now"$WXTimeZone);
$offset = ($WXTimeZone->getOffset($WXdateTime))/3600;

//get the timestamp for the start of today
$ddd date('Ymd');
$ddn date('l jS \of F Y'); //pretty date
$midnight strtotime($ddd);

//get the timestamp for the start of yesterday
$lastmnight strtotime($ddd)-86400;

//get timestamps for sunrise, sunset, and calculate length of day today
$tsrise date_sunrise($midnightSUNFUNCS_RET_TIMESTAMP$stationlat$stationlong$z$offset);
$tsset date_sunset($midnightSUNFUNCS_RET_TIMESTAMP$stationlat$stationlong$z$offset);
$tlod $tsset $tsrise;

//get timestamps for sunrise, sunset, and calculate length of day yesterday
$ysrise date_sunrise($lastmnightSUNFUNCS_RET_TIMESTAMP$stationlat$stationlong$z$offset);
$ysset date_sunset($lastmnightSUNFUNCS_RET_TIMESTAMP$stationlat$stationlong$z$offset);
$ylod $ysset $ysrise;

//output some stuff
print 'Today is: '.$ddn."<br/>";
print 
'Sunrise Today: '.date("H:i:s",$tsrise)."<br/>";
print 
'Sunset Today: '.date("H:i:s",$tsset)."<br/>";
print 
'Length of Day Today: '.gmdate("H:i:s"$tlod)."<hr br/>";
print 
'Sunrise Yesterday: '.date("H:i:s",$ysrise)."<br/>";
print 
'Sunset Yesterday: '.date("H:i:s",$ysset)."<br/>";
print 
'Length of Day Yesterday: '.gmdate("H:i:s"$ylod)."<hr br/>";
$tdiff abs($ylod-$tlod);
//print $tdiff;
$dchange=intval(gmdate('i'$tdiff))." minute(s) ".intval(gmdate('s',$tdiff))." second(s)";
if ( 
$tlod $ylod ) {
$diffdesc 'Increased By ';
} else {
$diffdesc 'Decreased By ';
}

print 
'Day Length '.$diffdesc.$dchange."<hr br/>";
?>

Offline rford

  • Posts: 321
  • Raleigh, North Carolina
  • OS/Browser:
  • Win NT 10.0
  • Firefox 64.0
    • Turner Downs Weather
Re: Daylight hours script does not display longer than yesterday info
« Reply #3 on: January 04, 2019, 06:55:50 PM »
Thanks Niko...I will give the script a try when I get home...thanks for taking a look at it for me. 

Ronnie

Offline ed2kayak

  • CoCoRaHS PA-CD-6, Weather Underground KPAMECHA7, CWOP DW5425
  • Posts: 458
  • Mechanicsburg PA
  • OS/Browser:
  • Win NT 10.0
  • Chrome 71.0.3578.98
    • Cumberland Valley Weather
Re: Daylight hours script does not display longer than yesterday info
« Reply #4 on: January 07, 2019, 03:36:12 PM »
Thanks -Niko
You were correct, my pie only shows changes > 1 min.
Now is showing change, since we are + 1.02 min.
Ed
CoCoRaHS PA-CD-6,  Weather Underground KPAMECHA7, CWOP DW5425