Daylight hours script does not display longer than yesterday info

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:

<p class="sideBarTitle">Daylight Hours</p>


<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(':', $hoursofpossibledaylight, 2);
			 echo (int)$time_arr[0] . " hrs " . (int)$time_arr[1] . " min";
			 echo '
of daylight today
';
	 ?>
			 </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" />
			 

			 <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 '
Which is 
';
			 $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 ('
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

Hopefully someone knows.

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

edit - added attachment


pie_inc.txt (1.41 KB)

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:

<?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($midnight, SUNFUNCS_RET_TIMESTAMP, $stationlat, $stationlong, $z, $offset);
$tsset = date_sunset($midnight, SUNFUNCS_RET_TIMESTAMP, $stationlat, $stationlong, $z, $offset);
$tlod = $tsset - $tsrise;

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

//output some stuff
print 'Today is: '.$ddn."
";
print 'Sunrise Today: '.date("H:i:s",$tsrise)."
";
print 'Sunset Today: '.date("H:i:s",$tsset)."
";
print 'Length of Day Today: '.gmdate("H:i:s", $tlod)."<hr br/>";
print 'Sunrise Yesterday: '.date("H:i:s",$ysrise)."
";
print 'Sunset Yesterday: '.date("H:i:s",$ysset)."
";
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/>";
?>

Thanks Niko…I will give the script a try when I get home…thanks for taking a look at it for me.

Ronnie

Thanks -Niko
You were correct, my pie only shows changes > 1 min.
Now is showing change, since we are + 1.02 min.