141 $this->path =
$MIOLO->GetConf(
'home.etc') .
'/mkrono.conf';
143 $this->lan = (string)$xml->xml->language;
144 $this->dateFormat = (string)$xml->xml->dateFormat;
145 $this->separator = (string)$xml->xml->separator;
146 $this->timeFormat = (string)$xml->xml->timeFormat;
151 $array = $xml->ToArray($conf, $xml->xml->longDay);
152 foreach($array as $k=>$v) $this->dayNameExt[$k] = $v[
'day'];
153 $array = $xml->ToArray($conf, $xml->xml->shortDay);
154 foreach($array as $k=>$v) $this->dayNameCon[$k] = $v[
'day'];
155 $array = $xml->ToArray($conf, $xml->xml->longMonth);
156 foreach($array as $k=>$v) $this->monthNameExt[$k] = $v[
'month'];
157 $array = $xml->ToArray($conf, $xml->xml->shortMonth);
158 foreach($array as $k=>$v) $this->monthNameCon[$k] = $v[
'month'];
300 list($dom, $dow, $month, $hour, $min) = explode(
":", date(
"d:w:m:H:i", $time));
302 if ($month > 4 && $month < 10)
304 $retval = 1; # May thru September
306 elseif ($month == 4 && $dom > 7)
308 $retval = 1; # After first week in April
310 elseif ($month == 4 && $dom <= 7 && $dow == 0 && $hour >= 2)
312 $retval = 1; # After 2am on first Sunday ($dow=0) in April
314 elseif ($month == 4 && $dom <= 7 && $dow != 0 && ($dom-$dow > 0))
316 $retval = 1; # After Sunday of first week in April
318 elseif ($month == 10 && $dom < 25)
320 $retval = 1; # Before last week of October
322 elseif ($month == 10 && $dom >= 25 && $dow == 0 && $hour < 2)
324 $retval = 1; # Before 2am on last Sunday in October
326 elseif ($month == 10 && $dom >= 25 && $dow != 0 && ($dom-24-$dow < 1) )
328 $retval = 1; # Before Sunday of last week in October
696 $data_ini=str_replace(
'-',
'/',$data_ini);
697 $data_ini=str_replace(
'.',
'/',$data_ini);
699 $eta_data=$this->
daysDiff($data_ini,$data_fin);
701 $giorno=(int)$this->
atomDate($data_ini,
'd');
702 $mese=(int)$this->
atomDate($data_ini,
'm');
703 $anno=(int)$this->
atomDate($data_ini,
'Y');
707 for($i=0;$i<$eta_data;$i++)
709 $data=date($this->
_format(),mktime(0,0,0,$mese,$giorno+$i,$anno));
710 if($this->
isDay($data,$day)===1)
723 (isset($exp[3])) ? $h=$exp[3] : $h=0;
724 (isset($exp[4])) ? $m=$exp[4] : $m=0;
725 (isset($exp[5])) ? $s=$exp[5] : $s=0;
726 switch($this->dateFormat)
728 case 'ansi':
return $this->
makeTime($h,$m,$s,$exp[1],$exp[2],$exp[0]);
break;
729 case 'it':
return $this->
makeTime($h,$m,$s,$exp[1],$exp[0],$exp[2]);
break;
730 case 'br':
return $this->
makeTime($h,$m,$s,$exp[1],$exp[0],$exp[2]);
break;
731 case 'std':
return $this->
makeTime($h,$m,$s,$exp[0],$exp[1],$exp[2]);
break;
732 case 'en':
return $this->
makeTime($h,$m,$s,$exp[0],$exp[1],$exp[2]);
break;
733 default: $this->error=
'Date Format not recognized, must be "ansi", "it", "std", "br" or "en" !! '; $this->
exitOnError();
998 if ($fp = fsockopen($server, $port, $errno, $errstr, 25))
1001 $timevalue = fread($fp, 49);
1006 $this->error=$server.
' Time Server unavailable or u\'re not connected on the net!!';
1010 $ts = (abs(hexdec(
'7fffffff') - hexdec(bin2hex($timevalue)) - hexdec(
'7fffffff')) - 2208988800);
1021 $beat_division = 24 * 60 / 1000;
1022 $current_date = getdate(time());
1023 $hour = $current_date[
"hours"];
1024 $minute = $current_date[
"minutes"];
1025 $seconds = $current_date[
"seconds"];
1026 $total_minutes = $minute + $offset + $hour * 60;
1027 $beats = round ($total_minutes / $beat_division);
1030 $beats = $beats % 1000;
1032 return (
"@".$beats);
1047 if($mode==
'mysqlfrom')
1049 $hour = substr($timestamp,8,2);
1050 $minute = substr($timestamp,10,2);
1051 $second = substr($timestamp,12,2);
1052 $month = substr($timestamp,4,2);
1053 $day = substr($timestamp,6,2);
1054 $year = substr($timestamp,0,4);
1055 $mktime = mktime($hour, $minute, $second, $month, $day, $year);
1057 $f=explode($this->separator,$format);
1058 $format=
'%'.$f[0].$this->separator.
'%'.$f[1].$this->separator.
'%'.$f[2].
' %g:%i %a';
1059 $formated = $this->
kDate($format,$mktime);
1063 $data=str_replace(
'-',
'/',$timestamp);
1064 $data=str_replace(
'.',
'/',$data);
1071 $formated=$Y.$m.$d.$h.$i.$s;
1089 $this->error=
'There isn\'t more than 5 '.$weekday.
' in a month, usually!!';
1099 if(strlen($weekday)>3)
1104 if(!is_numeric($month))
1111 $itsit=mktime(0,0,0,$month,$date_counter,$year);
1112 $dow=$this->
kDate($format_dow,$itsit);
1118 if( ($week_counter==$number) && ($weekday==$dow) )
1120 $week_counter=$number;
1121 if($date_counter > 1)
1129 while($week_counter<$number);
1131 $itsit=mktime(0,0,0,$month,$date_counter+1,$year);
1133 $f=explode($this->separator,$format);
1134 $format=
'%'.$f[0].$this->separator.
'%'.$f[1].$this->separator.
'%'.$f[2];
1136 if($this->
kDate(
'n',$itsit)!=$month)
1138 $this->error=
'Bad request, try again!!';
1143 return $this->
kDate($format,$itsit);
1155 $unit=array(0=>
"",1=>
'I',2=>
'II',3=>
'III',4=>
'IV',5=>
'V',6=>
'VI',7=>
'VII',8=>
'VIII',9=>
'IX');
1156 $tens=array(0=>
"",10=>
'X',20=>
'XX',30=>
'XXX',40=>
'XL',50=>
'L',60=>
'LX',70=>
'LXX',80=>
'LXXX',90=>
'XC');
1157 $hund=array(0=>
"",100=>
'C',200=>
'CC',300=>
'CCC',400=>
'CD',500=>
'D',600=>
'DC',700=>
'DCC',800=>
'DCCC',900=>
'CM');
1158 $thou=array(0=>
"",1000=>
'M',2000=>
'MM',3000=>
'MMM',4000=>
'MMMM',5000=>
'MMMMM');
1162 $date=date(
'd/m/Y',time());
1164 $this->dateFormat=
'it';
1168 $this->dateFormat=$old_state;
1177 $y_thou = substr($year, -4, 1) * 1000;
1178 $y_hund = substr($year, -3, 1) * 100;
1179 $y_tens = substr($year, -2, 1) * 10;
1180 $y_unit = substr($year, -1, 1);
1182 $m_tens=substr($month,-2,1)*10;
1183 $m_unit=substr($month,-1,1);
1185 $d_tens=substr($day,-2,1)*10;
1186 $d_unit=substr($day,-1,1);
1188 return $tens[$d_tens].$unit[$d_unit].
1189 $tens[$m_tens].$unit[$m_unit].
1190 $thou[$y_thou].$hund[$y_hund].$tens[$y_tens].$unit[$y_unit];
1204 $R1 = 3.14159265 / 180;
1207 $K0 = intval(($Y-1900)*12.3685);
1208 $T = ($Y-1899.5) / 100;
1209 $T2 = $T*$T; $T3 = $T*$T*$T;
1210 $J0 = 2415020 + 29*$K0;
1211 $F0 = 0.0001178*$T2 - 0.000000155*$T3;
1212 $F0 += (0.75933 + 0.53058868*$K0);
1213 $F0 -= (0.000837*$T + 0.000335*$T2);
1217 $M0 = $K0*0.08084821133;
1218 $M0 = 360*($M0 - intval($M0)) + 359.2242;
1219 $M0 -= 0.0000333*$T2;
1220 $M0 -= 0.00000347*$T3;
1221 $M1 = $K0*0.07171366128;
1222 $M1 = 360*($M1 - intval($M1)) + 306.0253;
1223 $M1 += 0.0107306*$T2;
1224 $M1 += 0.00001236*$T3;
1225 $B1 = $K0*0.08519585128;
1226 $B1 = 360*($B1 - intval($B1)) + 21.2964;
1227 $B1 -= 0.0016528*$T2;
1228 $B1 -= 0.00000239*$T3;
1229 for ( $K9=0; $K9 <= 28; $K9=$K9+0.5 )
1231 $J = $J0 + 14*$K9; $F = $F0 + 0.765294*$K9;
1233 $M5 = ($M0 + $K*29.10535608)*$R1;
1234 $M6 = ($M1 + $K*385.81691806)*$R1;
1235 $B6 = ($B1 + $K*390.67050646)*$R1;
1236 $F -= 0.4068*sin($M6);
1237 $F += (0.1734 - 0.000393*$T)*sin($M5);
1238 $F += 0.0161*sin(2*$M6);
1239 $F += 0.0104*sin(2*$B6);
1240 $F -= 0.0074*sin($M5 - $M6);
1241 $F -= 0.0051*sin($M5 + $M6);
1242 $F += 0.0021*sin(2*$M5);
1243 $F += 0.0010*sin(2*$B6-$M6);
1245 $J += intval($F); $F -= intval($F);
1247 $julian=$J+round($F);
1248 $s = jdtogregorian ($julian);
1250 if (($K9-floor($K9))>0)
1255 $phases[$s]=
"New Half";
1260 $phases[$s]=
"Full Half";
1268 $phases[$s]=
"New Moon";
1272 $phases[$s]=
"Full Moon";
1320 function getSunTime($latitude=0,$longitude=0,$timezone=1,$location=
'IT|Roma',$daylight=1,$date=
'')
1323 if(!isset($date) || $date==
'')
1330 if($location!=
'' && ($latitude==0 || $longitude==0))
1332 require_once
'_it_geo_coord.dat.php';
1333 $location=strtoupper($location);
1334 if(in_array($location,array_keys($_geo_coord)))
1336 $exp=explode(
'|',$_geo_coord[$location]);
1342 $yday = date(
'z',$time);
1343 $mon = date(
'n',$time);
1344 $mday = date(
'j',$time);
1345 $year = date(
'Y',$time);
1351 $timezone = ($timezone + 1);
1354 if($timezone ==
"13")
1363 $E = 0.0174533 * $latitude;
1364 $F = 0.0174533 * $longitude;
1365 $G = 0.261799 * $timezone;
1367 # For astronomical twilight, use R = -.309017
1368 # For nautical twilight, use R = -.207912
1369 # For civil twilight, use R = -.104528
1370 # For sunrise or sunset, use R = -.0145439
1373 for ($i = 0; $i < 2; $i++)
1380 } # calculate sunrise
1385 } # calculate sunset
1387 $K = $yday + (($J - $F) / $D);
1388 $L = ($K * .017202) - .0574039; # Solar Mean Anomoly
1389 $M = $L + .0334405 * sin($L); # Solar True Longitude
1390 $M += 4.93289 + (3.49066E-04) * sin(2 * $L);
1391 # Quadrant Determination
1394 $this->error=
"Trying to normalize with zero offset...";
1408 if (($M / $A) - intval($M / $A) == 0)
1413 $P = sin($M) / cos($M); # Solar Right Ascension
1414 $P = atan2(.91746 * $P, 1);
1416 # Quadrant Adjustment
1429 $Q = .39782 * sin($M); # Solar Declination
1430 $Q = $Q / sqrt(-$Q * $Q + 1); # This is how the original author wrote it!
1433 $S = $R - (sin($Q) * sin($E));
1434 $S = $S / (cos($Q) * cos($E));
1441 $S = $S / sqrt(-$S * $S + 1);
1442 $S = $A - atan2($S, 1);
1444 if ($type ==
'rise')
1449 $T = $S + $P - 0.0172028 * $K - 1.73364; # Local apparent time
1450 $U = $T - $F; # Universal timer
1451 $V = $U + $G; # Wall clock time
1452 # Quadrant Determination
1455 $this->error=
"Trying to normalize with zero offset...";
1472 $min = intval((($V - $hour) * 60) + 0.5);
1474 $result.=
"sun$type is at: ";
1476 if($this->timeFormat==
'12' || $this->timeFormat==12 || $this->timeFormat=
'en')
1477 $result.=date(
"g:i A", mktime($hour,$min,0,$mon,$mday,$year) );
1479 $result.=date(
"H:i", mktime($hour,$min,0,$mon,$mday,$year) );
1481 $result.=
' - ';
1640 if(strstr($date,
':'))
1642 if(strstr($date,
" "))
1644 $t = explode(
' ',$date);
1646 $date = explode($this->separator,$t[0]);
1655 $date = explode($this->separator,$date);
1657 $time = (isset($time)) ? explode(
':',$time) :
"";
1659 if(isset($time) && $time!=
"")
1662 $mins = (isset($time[1])) ? $time[1] : 0;
1663 $seconds = (isset($time[2])) ? $time[2] : 0;
1675 switch($this->dateFormat)
1677 case 'ansi': $year=$date[1]; $month=$date[2]; $day=$date[0];
break;
1678 case 'it': $day=$date[1]; $month=$date[0]; $year=$date[2];
break;
1679 case 'br': $day=$date[1]; $month=$date[0]; $year=$date[2];
break;
1680 case 'std': $month=$date[0]; $day=$date[1]; $year=$date[2];
break;
1681 case 'en': $month=$date[0]; $day=$date[1]; $year=$date[2];
break;
1682 default: $this->error=
'Date Format not recognized, must be "ansi", "it", "std" or "en" !! '; $this->
exitOnError();
1686 switch($this->timeFormat)
1691 if($hour>=0 && $hour<=24 && $mins>=0 && $mins<=59 && $seconds>=0 && $seconds<=59)
1699 if($hour>=0 && $hour<=12 && $mins>=0 && $mins<=59 && $seconds>=0 && $seconds<=59)
1704 default: $this->error=
'Time Format not recognized, must be "it" or "24", "en" or "12" !! '; $this->
exitOnError();
1707 $date = checkdate($month,$day,$year);
1717 elseif(!$date && !$time)
1798 $date=str_replace(
'-',$this->separator,$date);
1799 $date=str_replace(
'.',$this->separator,$date);
1800 list($obj1, $obj2, $obj3) = preg_split(
'/'.$this->separator.
'/', $date, 3);
1801 $date = $obj3 . $this->separator . $obj2 . $this->separator . $obj1;
1802 if ( ( $date == ($this->separator . $this->separator) ) ) $date =
'Invalid Date!';
1808 list($dayA,$monthA,$yearA) = explode(
"/",$dateA);
1809 list($dayB,$monthB,$yearB) = explode(
"/",$dateB);
1810 $date1 = $yearA.$monthA.$dayA;
1811 $date2 = $yearB.$monthB.$dayB;
1812 switch ($operator) {
1814 if ($date1 == $date2)
return true;
else return false;
1817 if ($date1 == $date2)
return true;
else return false;
1820 if ($date1 > $date2)
return true;
else return false;
1823 if ($date1 < $date2)
return true;
else return false;
1826 if ($date1 >= $date2)
return true;
else return false;
1829 if ($date1 <= $date2)
return true;
else return false;
1832 if ( !($date1 == $date2) )
return true;
else return false;
1835 if ( !($date1 == $date2) )
return true;
else return false;