cheesycarrion Posted November 24, 2008 Share Posted November 24, 2008 I made this script to convert solar time to sidereal time, but the problem is that sometimes the (when refreshing the page about once a second) the sidereal second count stops for about 15 seconds, then catches up, but the minutes don't roll over correctly and you stay at the same repeating minute for a while until it somehow fixes itself and gets back on. (at which point it's accurate right down to the second.) I have absolutely no idea why it does this or how to fix it. <?php $server_timezone_offset = 2; // If timezone of server is Pacific, set to 0. // amount of seconds in a tropical year: $tropical = 365.2425*60*60*24; // amount of seconds in a sidereal day: $sidereal = ((23*60)+56)*60+4.090530833; $months = array(0,31,28.25,31,30,31,30,31,31,30,31,30,31); $c_sec = date("s") - 114; // I was 9:32:54 off. $c_min = date("i") - 34; $c_hour = date("H") - $server_timezone_offset - 17; // 2 is for timezone offset from server's time $c_day = date("z"); $c_month = date("m"); $c_year = date("Y"); while ($c_sec<0) { $c_sec = $c_sec + 60; $c_min = $c_min - 1; } while ($c_min<0) { $c_min = $c_min + 60; $c_hour = $c_hour - 1; } while ($c_hour<0) { $c_hour = $c_hour + 24; $c_day = $c_day - 1; } while ($c_day<1) { $c_day = $c_day + $months[$c_month-1]; $c_month = $c_month - 1; } while ($c_month<1) { $c_month = $c_month + 12; $c_year = $c_year - 1; } if (strlen($c_hour)==1) $c_hour = 0 . $c_hour; if (strlen($c_min)==1) $c_min = 0 . $c_hour; if (strlen($c_sec)==1) $c_sec = 0 . $c_hour; ////////////////////////////////////////////// $c_hour_pacific = date("H") - $server_timezone_offset; if ($c_hour_pacific<0) $c_hour_pacific = $c_hour_pacific + 24; if (strlen($c_hour_pacific)==1) $c_hour_pacific = 0 . $c_hour_pacific; ////////////////////////////////////////////// $i = 0; while ($i < $c_month) { $topical_day = $tropical_day + $months[$i]; $i++; } $tropical_day = $tropical_day + $c_day; $tropical_sec = $tropical_day * 24 * 60 * 60; $tropical_sec = $tropical_sec + $c_sec + ($c_min*60) + ($c_hour*60*60); $c_sid_day_j = $tropical_sec / $sidereal; $c_sid_day = floor($c_sid_day_j); $c_sid_day_frac = $c_sid_day_j - $c_sid_day; $c_sid_hours_j = $c_sid_day_frac * 24; $c_sid_hours = floor($c_sid_hours_j); $c_sid_hours_frac = $c_sid_hours_j - $c_sid_hours; $c_sid_minutes_j = $c_sid_hours_frac * 60; $c_sid_minutes = floor($c_sid_minutes_j); $c_sid_minutes_frac = $c_sid_minutes_j - $c_sid_minutes; $c_sid_seconds = round($c_sid_minutes_frac * 60); ////////////////////////////////////////////// if ($c_sid_seconds<10) $c_sid_seconds = 0 . $c_sid_seconds; if ($c_sid_minutes<10) $c_sid_minutes = 0 . $c_sid_minutes; if ($c_sid_hours<10) $c_sid_hours = 0 . $c_sid_hours; ////////////////////////////////////////////// echo "Solar: " . $c_hour_pacific . ":" . date("i") . ":" . date("s") . "<br />\nSidereal: " . $c_sid_hours . ":" . $c_sid_minutes . ":" . $c_sid_seconds; $finished_solar = $c_hour_pacific . ":" . date("i") . ":" . date("s"); $finished_sidereal = $c_sid_hours . ":" . $c_sid_minutes . ":" . $c_sid_seconds; ?> Link to comment https://forums.phpfreaks.com/topic/133991-clock-goes-back-in-time/ Share on other sites More sharing options...
cheesycarrion Posted November 28, 2008 Author Share Posted November 28, 2008 bump.. If anybody needs anymore information or more specific information, just tell me. Link to comment https://forums.phpfreaks.com/topic/133991-clock-goes-back-in-time/#findComment-700810 Share on other sites More sharing options...
cheesycarrion Posted November 30, 2008 Author Share Posted November 30, 2008 bump Link to comment https://forums.phpfreaks.com/topic/133991-clock-goes-back-in-time/#findComment-702034 Share on other sites More sharing options...
cheesycarrion Posted December 8, 2008 Author Share Posted December 8, 2008 bump again. please if you need any more information or need me to make more specific notes or anything, tell me. Link to comment https://forums.phpfreaks.com/topic/133991-clock-goes-back-in-time/#findComment-709158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.