note 77521 added to ref.calendar
| From: | simon at chronolabs dot org dot au | Date: | Sun, 02 Sep 2007 01:18:19 +0000 |
| Subject: | note 77521 added to ref.calendar | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130083@lists.php.net to get a copy of this message | ||
Dear PHPers,
I appologise for posting this again, there was just an error in the code so I have posted it again,
<?php
function RounCalendar($unix_time,
$poffset = '2008-05-11 10:05 AM',
$pweight = '-20.22222222223',
$defiency='deficient',
$hoursrounding = array(
'hours'=>24,
'minutes'=>60,
'seconds'=>60))
// Code Segment 1
$tme = $unix_time;
if ($gmt>0){
$gmt=-$gmt;
} else {
$gmt=$gmt+$gmt+$gmt;
}
$ptime = strtotime($poffset)+(60*60*gmt);
$weight = $pweight+(1*gmt);
$roun_xa = ($tme)/(24*60*60);
$roun_ya = $ptime/(24*60*60);
$roun = (($roun_xa -$roun_ya) - $weight)+(microtime/999999);
// Code Segment 2
$nonedeficient = array(
"seq1" => array(31,30,31,30,30,30,31,30,31,30,31,30),
"seq2" => array(31,30,31,30,31,30,31,30,31,30,31,30),
"seq3" => array(31,30,31,30,30,30,31,30,31,30,31,30),
"seq4" => array(31,30,31,30,30,30,31,30,31,30,31,30));
$deficient = array(
"seq1" => array(31,30,31,30,30,30,31,30,31,30,31,30),
"seq2" => array(31,30,31,30,31,30,31,30,31,30,31,30),
"seq3" => array(31,30,31,30,31,30,31,30,30,30,31,30),
"seq4" => array(30,30,31,30,31,30,31,30,31,30,31,30));
$monthusage = isset($defiency) ? ${$defiency} : $deficient;
// Code Segment 3
foreach($monthusage as $key => $item){
$i++;
foreach($item as $numdays){
$ttl_num=$ttl_num+$numdays;
$ttl_num_months++;
}
}
$revolutionsperyear = $ttl_num / $i;
$numyears = round((floor($roun) / $revolutionsperyear),0);
$avg_num_month = floor($ttl_num_months/$i);
$jtl = abs(abs($roun) - ceil($revolutionsperyear*($numyears+1)));
while($month==0){
$day=0;
foreach($monthusage as $key => $item){
$t++;
$u=0;
foreach($item as $numdays){
if ($ii<abs($roun)){
$isbelow=true;
}
$ii=$ii+$numdays;
if ($ii>abs($roun)){
$isabove=true;
}
if ($isbelow==true&&$isabove==true){
$daynum = floor(($ii-$numday)-abs($roun));
$daynum++;
$month = $u;
$month++;
if ($roun<0){
$month=ceil($avg_num_month-$month);
$daynum=ceil($numdays-$daynum);
}
$isbelow=false;
$isabove=false;
$nodaycount=true;
}
if ($nodaycount==false)
$day++;
$u++;
}
}
}
$timer = substr($roun, strpos($roun,'.')+1,
strlen($roun)-strpos($roun,'.')-1);
$roun_out= $numyears.'/'.$month.'/'.$daynum.' '.
$day.'.'.substr($timer,0,2).':'.substr($timer,2,2).':'
.substr($timer,4,2).'.'.substr($timer,6,strlen($timer)-6);
$return array('year'=>$numyears,
'month'=>$month,
'day'=>$day,
'hours'=>(intval(substr($timer,0,2))/100
*$hoursrounding['hours']),
'minute'=>(intval(substr($timer,2,2))/100
*$hoursrounding['minutes']),
'seconds'=>(intval(substr($timer,4,2))/100
*$hoursrounding['seconds']),
'microtime'=>substr($timer,6,strlen($timer)-6),
'strout'=>$roun_out)
}
?>
----
Server IP: 203.220.0.234
Probable Submitter: 125.253.8.126
----
Manual Page -- http://www.php.net/manual/en/ref.calendar.php
Edit -- https://master.php.net/note/edit/77521
Del: integrated -- https://master.php.net/note/delete/77521/integrated
Del: useless -- https://master.php.net/note/delete/77521/useless
Del: bad code -- https://master.php.net/note/delete/77521/bad+code
Del: spam -- https://master.php.net/note/delete/77521/spam
Del: non-english -- https://master.php.net/note/delete/77521/non-english
Del: in docs -- https://master.php.net/note/delete/77521/in+docs
Del: other reasons-- https://master.php.net/note/delete/77521
Reject -- https://master.php.net/note/reject/77521
Search -- https://master.php.net/manage/user-notes.php