MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mkrono.class
Ir para a documentação deste ficheiro.
1<?php
2/*
3+--+ Project Name: KronoClass
4+--+ Version: 0.7
5+--+ Project Author: Tommaso D'Argenio
6+--+ Author Email: rajasi@ziobudda.net, info@holosoft.it
7+--+ Build Date: January 10 2003 16.18 (CET)
8+--+ Update: September 9 2003 16.35 (CET)
9
10+--+ DISCLAIMER
11Copyright (c) 2002-03 Tommaso D'Argenio <rajasi@ziobudda.net>
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU Lesser General Public License
14as published by the Free Software Foundation; either version
152.1 of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied
19warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20PURPOSE. See the GNU Lesser General Public License for more details.
21
22You should have received a copy of the GNU Lesser General Public
23License along with this program; if not, write to the
24Free Software Foundation, Inc.,
2559 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26http://www.fsf.org
27
28+--+ NOTES FROM AUTHOR
29* Please, if you make any change in the code let me know by email!!!
30 if use this class in your project, please let me know, in this way i can publish it.
31
32 If you want to personalize the language settings, please take a look in all ini files.
33
34+--+ Requirements:
35 PHP 4.0+
36*/
37
48class MKrono
49{
54
59
64
69
74
79
83 var $error;
84
88 var $abbr;
89
93 var $lan;
94
98 var $version='0.7';
99
109
118
123
127 var $path;
128
137 function __construct($lan='it', $dateFormat='it', $timeFormat='it',$separator='/')
138 {
139 global $MIOLO;
140
141 $this->path = $MIOLO->GetConf('home.etc') . '/mkrono.conf';
142 $xml = new SimpleXML($this->path);
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;
147 $this->error='';
148
149 $this->_checkIniFile();
150
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'];
159
160/*
161 $this->dayNameExt=parse_ini_file($this->path.'_long_day.ini', TRUE);
162
163 $this->dayNameCon=parse_ini_file($this->path.'_short_day.ini', TRUE);
164
165 $this->monthNameExt=parse_ini_file($this->path.'_long_month.ini', TRUE);
166
167 $this->monthNameCon=parse_ini_file($this->path.'_short_month.ini', TRUE);
168*/
169 }
170
175 function _checkIniFile()
176 {
177/*
178 if(!file_exists($this->path.'_long_day.ini'))
179 $this->error.='Long Days ini languages does\'nt exists!<br>';
180 if(!file_exists($this->path.'_short_day.ini'))
181 $this->error.='Short Days ini languages does\'nt exists!<br>';
182 if(!file_exists($this->path.'_long_month.ini'))
183 $this->error.='Long Months ini languages does\'nt exists!<br>';
184 if(!file_exists($this->path.'_short_month.ini'))
185 $this->error.='Short Months ini languages does\'nt exists!<br>';
186*/
187 $this->exitOnError();
188 }
189
194 function exitOnError()
195 {
196 if($this->error!='')
197 {
198 echo ' [Fatal Error] <b>'.$this->error.'</b> ';
199 exit;
200 }
201 }
202
207 function _update()
208 {
209 $s=stat(__FILE__);
210 return $this->kDate('%l %d %F %Y',$s[9]);
211 }
212
217 function _format()
218 {
219 switch($this->dateFormat)
220 {
221 case 'ansi':
222 if(!$this->abbr)
223 return 'Y'.$this->separator.'m'.$this->separator.'d';
224 else
225 return 'Y'.$this->separator.'n'.$this->separator.'j';
226 break;
227 case 'it':
228 case 'br':
229 if(!$this->abbr)
230 return 'd'.$this->separator.'m'.$this->separator.'Y';
231 else
232 return 'j'.$this->separator.'n'.$this->separator.'Y';
233 break;
234 case 'en':
235 case 'std':
236 if(!$this->abbr)
237 return 'm'.$this->separator.'d'.$this->separator.'Y';
238 else
239 return 'n'.$this->separator.'j'.$this->separator.'Y';
240 break;
241 default: $this->error='Date Format not recognized, must be "ansi", "it", "std", "br" or "en" !! '; $this->exitOnError();
242 }
243 }
244
250 function _language()
251 {
252 switch($this->lan)
253 {
254 case 'it': return 'Italian'; break;
255 case 'en': return 'English'; break;
256 case 'de': return 'Deutch'; break;
257 case 'fr': return 'French'; break;
258 case 'es': return 'Spanish'; break;
259 case 'id': return 'Indonesian'; break;
260 case 'no': return 'Norway'; break;
261 case 'jp': return 'Japanese'; break;
262 case 'fi': return 'Finnish'; break;
263 case 'nl': return 'Dutch'; break;
264 case 'br': return 'Brazilian Portuguese'; break;
265 default: return 'Language not recognized!!';
266 }
267 }
268
273 function _debug()
274 {
275 $debug ='
276 Format of Date: <i>'.$this->_format().'</i><br>
277 Date Separator: <i>'.$this->separator.'</i><br>
278 Language: <i>'.$this->_language().'</i>
279 ';
280 return $debug;
281 }
286 function _disclaimer()
287 {
288 echo '<span style="font-family:helvetica,verdana,serif;font-size:14px;color:#ff9900;">';
289 echo '<b>KronoClass</b> v. '.$this->version.' <br>';
290 echo '<i>Copyright (c) 2002-2003 by Tommaso D\'Argenio &lt;<a href="mailto:rajasi@ziobudda.net" title="Send me an email">rajasi@ziobudda.net</a>&gt;<br>';
291 echo 'Last modified on: '.$this->_update().'</i><br><hr size="1px" width="50%" color="black" align="left"></span><br>';
292 }
293
298 function _isDaylight($time)
299 {
300 list($dom, $dow, $month, $hour, $min) = explode(":", date("d:w:m:H:i", $time));
301
302 if ($month > 4 && $month < 10)
303 {
304 $retval = 1; # May thru September
305 }
306 elseif ($month == 4 && $dom > 7)
307 {
308 $retval = 1; # After first week in April
309 }
310 elseif ($month == 4 && $dom <= 7 && $dow == 0 && $hour >= 2)
311 {
312 $retval = 1; # After 2am on first Sunday ($dow=0) in April
313 }
314 elseif ($month == 4 && $dom <= 7 && $dow != 0 && ($dom-$dow > 0))
315 {
316 $retval = 1; # After Sunday of first week in April
317 }
318 elseif ($month == 10 && $dom < 25)
319 {
320 $retval = 1; # Before last week of October
321 }
322 elseif ($month == 10 && $dom >= 25 && $dow == 0 && $hour < 2)
323 {
324 $retval = 1; # Before 2am on last Sunday in October
325 }
326 elseif ($month == 10 && $dom >= 25 && $dow != 0 && ($dom-24-$dow < 1) )
327 {
328 $retval = 1; # Before Sunday of last week in October
329 }
330 else
331 {
332 $retval = 0;
333 }
334
335 return($retval);
336 }
337
338
345 function dayToN($day)
346 {
347 if($day=='' || strlen($day)<3)
348 {
349 $this->error='Day name not valid!';
350 $this->exitOnError();
351 }
352
353 $day=ucwords($day);
354 if(strlen($day)==3)
355 $ar=$this->dayNameCon[$this->lan];
356 else
357 $ar=$this->dayNameExt[$this->lan];
358
359 if(in_array($day,$ar))
360 {
361 $k=array_keys($ar,$day);
362 return($k[0]);
363 }
364 }
365
372 function NToDay($day)
373 {
374 if($day>6 || $day<0)
375 {
376 $this->error='Day range not valid. Must be 0 to 6!';
377 $this->exitOnError();
378 }
379
380 if($this->abbr===true)
381 return($this->dayNameCon[$this->lan][$day]);
382 elseif($this->abbr!=true)
383 return($this->dayNameExt[$this->lan][$day]);
384 }
385
392 function monthToN($month)
393 {
394 if($month=='' || strlen($month)<3)
395 {
396 $this->error='Month name not valid!';
397 $this->exitOnError();
398 }
399
400 $month=ucwords($month);
401 if(strlen($month)==3)
402 $ar=$this->monthNameCon[$this->lan];
403 else
404 $ar=$this->monthNameExt[$this->lan];
405
406 if(in_array($month,$ar))
407 {
408 $k=array_search($month,$ar);
409 return($k+1);
410 }
411 else
412 return -1;
413 }
414
421 function NToMonth($month)
422 {
423 if($month>12 || $month<1)
424 {
425 $this->error='Month range not valid. Must be 1 to 12!';
426 $this->exitOnError();
427 }
428
429 if($this->abbr===true)
430 return($this->monthNameCon[$this->lan][$month-1]);
431 elseif($this->abbr!=true)
432 return($this->monthNameExt[$this->lan][$month-1]);
433 }
434
435
444 function isDay($data,$day)
445 {
446 $data=str_replace('-','/',$data);
447 $data=str_replace('.','/',$data);
448 $exp=explode('/',$data);
449
450 $data_unix=$this->kMkTime($exp);
451 $giorno_unix=date('w',$data_unix);
452
453 if(!is_numeric($day))
454 {
455 $day=$this->dayToN($day);
456 }
457
458 if($giorno_unix==$day)
459 return 1;
460 else
461 return $this->NToDay($giorno_unix);
462 }
463
471 function dateToTimestamp($date)
472 {
473 if(strstr($date,' '))
474 {
475 $t = explode(' ',$date);
476 $date = $t[0];
477 $time = explode(':',$t[1]);
478 }
479 else
480 $time = '';
481 $date=str_replace('-','/',$date);
482 $date=str_replace('.','/',$date);
483 $exp=explode('/',$date);
484 if($time!='')
485 {
486 $exp[3]=(isset($time[0])) ? $time[0] : 0;
487 $exp[4]=(isset($time[1])) ? $time[1] : 0;
488 $exp[5]=(isset($time[2])) ? $time[2] : 0;
489 }
490 return $this->kMkTime($exp);
491 }
492
500 function daysDiff($data_ini,$data_fin)
501 {
502 $data_ini=str_replace('-','/',$data_ini);
503 $data_ini=str_replace('.','/',$data_ini);
504 $data_fin=str_replace('-','/',$data_fin);
505 $data_fin=str_replace('.','/',$data_fin);
506
507 $exp_ini=explode('/',$data_ini);
508 $exp_fin=explode('/',$data_fin);
509
510 $ini=date('z',$this->kMkTime($exp_ini));
511 $fin=date('z',$this->kMkTime($exp_fin));
512
513 $days = floor(($this->kMkTime($exp_fin)-$this->kMkTime($exp_ini))/(60*60*24));
514 return $days;
515 }
516
531 function timesDiff($time_from,$time_to,$result_in="m")
532 {
533 if( (strstr($time_from,'.') || strstr($time_from,':')) && (strstr($time_to,'.') || strstr($time_to,':')) )
534 {
535 $time_from=str_replace(':','.',$time_from);
536 $time_to=str_replace(':','.',$time_to);
537
538 $t1=explode('.',$time_from);
539 $t2=explode('.',$time_to);
540
541 $h1=$t1[0];
542 $m1=$t1[1];
543
544 $h2=$t2[0];
545 $m2=$t2[1];
546
547 if($h1<=24 && $h2<=24 && $h1>=0 && $h2>=0 && $m1<=59 && $m2<=59 && $m1>=0 && $m2>=0)
548 {
549 $diff=($h2*3600+$m2*60)-($h1*3600+$m1*60);
550 if($result_in=="s")
551 return $diff;
552 elseif($result_in=="m")
553 {
554 return $diff/60;
555 }
556 elseif($result_in=="h")
557 {
558 $r=$diff/3600;
559 $t=explode('.',$r);
560 $h=$t[0];
561 if($h>24)
562 $h-=24;
563 $m=round("0.$t[1]"*60);
564 return $h.'h'.$m.'m';
565 }
566 }
567 else
568 {
569 $this->error='Time range not valid. Must be 0 to 24 for hours and 0 to 59 for minutes!';
570 $this->exitOnError();
571 }
572 }
573 else
574 {
575 $this->error='Time format not valid. Must be in format HH:mm or HH.mm';
576 $this->exitOnError();
577 }
578 }
579
593 function timesAdd($time,$add,$what)
594 {
595 if( (strstr($time,'.') || strstr($time,':')))
596 {
597 $time=str_replace(':','.',$time);
598 $t1=explode('.',$time);
599 $h1=$t1[0];
600 $m1=$t1[1];
601 if($h1<=24 && $h1>=0 && $m1<=59 && $m1>=0)
602 {
603 if($what=="m")
604 {
605 $res=($h1*60)+$m1+$add;
606 $r=$res/60;
607 $t=explode('.',$r);
608 $h=$t[0];
609 if($h>24)
610 $h-=24;
611 $m=round("0.$t[1]"*60);
612 return $h.':'.$m;
613 }
614 elseif($what=="h")
615 {
616 $res=($h1*60)+$m1+($add*60);
617 $r=$res/60;
618 $t=explode('.',$r);
619 $h=$t[0];
620 if($h>24)
621 $h-=24;
622 $m=round("0.$t[1]"*60);
623 return $h.':'.$m;
624 }
625 elseif($what=="t")
626 {
627 if( (strstr($add,'.') || strstr($add,':')))
628 {
629 $add=str_replace(':','.',$add);
630 $t1=explode('.',$add);
631 $h2=$t1[0];
632 $m2=$t1[1];
633 if($h2<=24 && $h2>=0 && $m2<=59 && $m2>=0)
634 {
635 $res=($h1*60)+($h2*60)+$m1+$m2;
636 $r=$res/60;
637 $t=explode('.',$r);
638 $h=$t[0];
639 if($h>24)
640 $h-=24;
641 $m=round("0.$t[1]"*60);
642 return $h.':'.$m;
643 }
644 }
645 else
646 {
647 $this->error='Time format not valid. Must be in format HH:mm or HH.mm';
648 $this->exitOnError();
649 }
650 }
651 }
652 else
653 {
654 $this->error='Time range not valid. Must be 0 to 24 for hours and 0 to 59 for minutes!';
655 $this->exitOnError();
656 }
657 }
658 else
659 {
660 $this->error='Time format not valid. Must be in format HH:mm or HH.mm';
661 $this->exitOnError();
662 }
663 }
664
670 function howTo($data)
671 {
672 $data=str_replace('-','/',$data);
673 $data=str_replace('.','/',$data);
674 $exp=explode('/',$data);
675 $data_unix=$this->kMkTime($exp);
676 $diff = $data_unix-time();
677 if($data_unix>time())
678 return (date("z",$diff));
679 else
680 {
681 $this->error='Cannot perform calculation on past time!';
682 $this->exitOnError();
683 }
684 }
685
694 function howDays($data_ini,$data_fin,$day)
695 {
696 $data_ini=str_replace('-','/',$data_ini);
697 $data_ini=str_replace('.','/',$data_ini);
698
699 $eta_data=$this->daysDiff($data_ini,$data_fin);
700
701 $giorno=(int)$this->atomDate($data_ini,'d');
702 $mese=(int)$this->atomDate($data_ini,'m');
703 $anno=(int)$this->atomDate($data_ini,'Y');
704
705 $count=0;
706
707 for($i=0;$i<$eta_data;$i++)
708 {
709 $data=date($this->_format(),mktime(0,0,0,$mese,$giorno+$i,$anno));
710 if($this->isDay($data,$day)===1)
711 $count++;
712 }
713 return $count;
714 }
715
721 function kMkTime($exp)
722 {
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)
727 {
728 case 'ansi': return $this->makeTime($h,$m,$s,$exp[1],$exp[2],$exp[0]); break; // using YYYY-MM-DD
729 case 'it': return $this->makeTime($h,$m,$s,$exp[1],$exp[0],$exp[2]); break;// using DD-MM-YYYY
730 case 'br': return $this->makeTime($h,$m,$s,$exp[1],$exp[0],$exp[2]); break;// using DD-MM-YYYY
731 case 'std': return $this->makeTime($h,$m,$s,$exp[0],$exp[1],$exp[2]); break; // using MM-DD-YYYY
732 case 'en': return $this->makeTime($h,$m,$s,$exp[0],$exp[1],$exp[2]); break; // using MM-DD-YYYY
733 default: $this->error='Date Format not recognized, must be "ansi", "it", "std", "br" or "en" !! '; $this->exitOnError();
734 }
735 }
736
752 function atomDate($date,$atom)
753 {
754 if(strlen($date)<=10)
755 {
756 $date.=' 00:00:00';
757 }
758
759 $t=explode(' ',$date);
760 $exp1=explode('/',$t[0]);
761 $exp2=explode(':',$t[1]);
762 $exp=array_merge($exp1,$exp2);
763 // Extract only time
764 switch($atom)
765 {
766 case 'h': return $exp[3]; break;
767 case 'i': return $exp[4]; break;
768 case 's': return $exp[5]; break;
769 }
770 // Extract day,month and year
771 switch($this->dateFormat)
772 {
773 case 'ansi':
774 {
775 switch($atom)
776 {
777 case 'd': return $exp[2]; break;
778 case 'm': return $exp[1]; break;
779 case 'y': return substr($exp[0],2,2); break;
780 case 'Y': return $exp[0]; break;
781 default: $this->error='Atom not recognized, must be "d", "m", "y" or "Y" !!'; $this->exitOnError();
782 }
783 break;
784 }
785 case 'it':
786 case 'br':
787 {
788 switch($atom)
789 {
790 case 'd': return $exp[0]; break;
791 case 'm': return $exp[1]; break;
792 case 'y': return substr($exp[2],2,2); break;
793 case 'Y': return $exp[2]; break;
794 default: $this->error='Atom not recognized, must be "d", "m", "y" or "Y" !!'; $this->exitOnError();
795 }
796 break;
797 }
798 case 'en':
799 case 'std':
800 {
801 switch($atom)
802 {
803 case 'd': return $exp[1]; break;
804 case 'm': return $exp[0]; break;
805 case 'y': return substr($exp[2],2,2); break;
806 case 'Y': return $exp[2]; break;
807 default: $this->error='Atom not recognized, must be "d", "m", "y" or "Y" !!'; $this->exitOnError();
808 }
809 break;
810 }
811 default: $this->error='Date Format not recognized, must be "ansi", "it", "std","br" or "en" !! '; $this->exitOnError();
812 }
813 }
814
815
833 function kDate($format="%l %d %F %Y",$timestamp=0)
834 {
835 if($timestamp==0)
836 $timestamp=time();
837
838
839 if(!preg_match('/\%l|\%F|\%D|\%M/',$format))
840 {
841 return date(str_replace('%','',$format),$timestamp);
842 }
843 else
844 {
845 $out=$format;
846 if(strstr($format,'%l'))
847 {
848 $this->abbr=false;
849 $out=str_replace('%l',$this->NToDay(date('w',$timestamp)),$out);
850 }
851 if(strstr($format,'%F'))
852 {
853 $this->abbr=false;
854 $out=str_replace('%F',$this->NToMonth(date('m',$timestamp)),$out);
855 }
856 if(strstr($format,'%D'))
857 {
858 $this->abbr=true;
859 $out=str_replace('%D',$this->NToDay(date('w',$timestamp)),$out);
860 }
861 if(strstr($format,'%M'))
862 {
863 $this->abbr=true;
864 $out=str_replace('%M',$this->NToMonth(date('m',$timestamp)),$out);
865 }
866 if(strstr($format,'%Y'))
867 $out=str_replace('%Y',date('Y',$timestamp),$out);
868 if(strstr($format,'%y'))
869 $out=str_replace('%y',date('y',$timestamp),$out);
870 if(strstr($format,'%d'))
871 $out=str_replace('%d',date('d',$timestamp),$out);
872 if(strstr($format,'%m'))
873 $out=str_replace('%m',date('m',$timestamp),$out);
874 if(strstr($format,'%n'))
875 $out=str_replace('%n',date('n',$timestamp),$out);
876 if(strstr($format,'%j'))
877 $out=str_replace('%j',date('j',$timestamp),$out);
878
879 return $out;
880 }
881 }
882
883 /* Perform operation like sum or subtraction on date
884 * @access public
885 * @return date The date transformed by calc
886 * @param string $operator Operator may be
887 * + '+' -> for sum
888 * + 'sum' -> for sum
889 * + 'add' -> for sum
890 * + '-' -> for subtraction
891 * + 'sub'-> for subtraction
892 * + 'sot'-> for subtraction
893 * @param date $date The date to calc on
894 * @param string $operand is a number plus '%D' for days, '%M' for months, '%Y' for years
895 * + Example:
896 * - Add 1 month to a date:
897 * - $obj->operation('+','10/01/2003','1%M');
898 *
899 * - Subtract 20 days from a date:
900 * - $obj->operation('-','10/01/2003','20%D');
901 */
902 function operation($operator,$date,$operand)
903 {
904 // Thanks to Tim Hodson tim@trundlie.fsnet.co.uk - Begin Change
905 if(is_array($date))
906 { //to take a date as an array rather than hardcoded string
907 $date2=$this->kMkTime($date);
908 $ts=$date2;
909 }
910 elseif(is_string($date))
911 { // to handle an original string
912 $ts=$this->dateToTimestamp($date);
913 }
914 elseif(is_integer($date))
915 { // to handle a timestamp
916 $ts = $date;
917 }
918 // end change of Tim
919
920 if(!strstr($operand,'%'))
921 {
922 $this->error='Bad operand type!!';
923 $this->exitOnError();
924 }
925
926 $t=explode('%',$operand);
927 $how=$t[0];
928
929 switch($t[1])
930 {
931 case 'D':
932 {
933 if($operator=='+' || $operator=='sum' || $operator=='add')
934 {
935 return date($this->_format(),mktime(0,0,0,date('m',$ts),date('d',$ts)+$how,date('Y',$ts)));
936 }
937 elseif($operator=='-' || $operator=='sub' || $operator=='sot')
938 {
939 return date($this->_format(),mktime(0,0,0,date('m',$ts),date('d',$ts)-$how,date('Y',$ts)));
940 }
941 else
942 {
943 $this->error='Operator not recognized!!';
944 $this->exitOnError();
945 }
946 break;
947 }
948 case 'M':
949 {
950 if($operator=='+' || $operator=='sum' || $operator=='add')
951 {
952 return date($this->_format(),mktime(0,0,0,date('m',$ts)+$how,date('d',$ts),date('Y',$ts)));
953 }
954 elseif($operator=='-' || $operator=='sub' || $operator=='sot')
955 {
956 return date($this->_format(),mktime(0,0,0,date('m',$ts)-$how,date('d',$ts),date('Y',$ts)));
957 }
958 else
959 {
960 $this->error='Operator not recognized!!';
961 $this->exitOnError();
962 }
963 break;
964 }
965 case 'Y':
966 {
967 if($operator=='+' || $operator=='sum' || $operator=='add')
968 {
969 return date($this->_format(),mktime(0,0,0,date('m',$ts),date('d',$ts),date('Y',$ts)+$how));
970 }
971 elseif($operator=='-' || $operator=='sub' || $operator=='sot')
972 {
973 return date($this->_format(),mktime(0,0,0,date('m',$ts),date('d',$ts),date('Y',$ts)-$how));
974 }
975 else
976 {
977 $this->error='Operator not recognized!!';
978 $this->exitOnError();
979 }
980 break;
981 }
982 default:
983 {
984 $this->error='Bad operand type!!';
985 $this->exitOnError();
986 }
987 }
988 }
989
996 function netTimestamp($server='time-a.nist.gov', $port=37)
997 {
998 if ($fp = fsockopen($server, $port, $errno, $errstr, 25))
999 {
1000 fputs($fp, "\n");
1001 $timevalue = fread($fp, 49);
1002 fclose($fp);
1003 }
1004 else
1005 {
1006 $this->error=$server.' Time Server unavailable or u\'re not connected on the net!!';
1007 $this->exitOnError();
1008 }
1009
1010 $ts = (abs(hexdec('7fffffff') - hexdec(bin2hex($timevalue)) - hexdec('7fffffff')) - 2208988800);
1011 return $ts;
1012 }
1013
1018 function swatchTime()
1019 {
1020 $offset = 60;
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);
1028 if ($beats >= 1000)
1029 {
1030 $beats = $beats % 1000;
1031 }
1032 return ("@".$beats);
1033 }
1034
1043 function mysql_time_easy($timestamp,$mode='mysqlfrom')
1044 {
1045 $formated='';
1046
1047 if($mode=='mysqlfrom')
1048 {
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);
1056 $format=$this->_format();
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);
1060 }
1061 else
1062 {
1063 $data=str_replace('-','/',$timestamp);
1064 $data=str_replace('.','/',$data);
1065 $m=$this->atomDate($data,'m');
1066 $d=$this->atomDate($data,'d');
1067 $Y=$this->atomDate($data,'Y');
1068 $h=$this->atomDate($data,'h');
1069 $i=$this->atomDate($data,'i');
1070 $s=$this->atomDate($data,'s');
1071 $formated=$Y.$m.$d.$h.$i.$s;
1072 }
1073 return $formated;
1074 }
1075
1085 function getNthDay($number,$weekday,$month,$year=0)
1086 {
1087 if($number>5)
1088 {
1089 $this->error='There isn\'t more than 5 '.$weekday.' in a month, usually!!';
1090 $this->exitOnError();
1091 }
1092
1093 $date_counter=1;
1094 $week_counter=0;
1095
1096 if($year==0)
1097 $year=date('Y');
1098
1099 if(strlen($weekday)>3)
1100 $format_dow='%l';
1101 else
1102 $format_dow='%D';
1103
1104 if(!is_numeric($month))
1105 {
1106 $month=$this->monthToN($month);
1107 }
1108
1109 do
1110 {
1111 $itsit=mktime(0,0,0,$month,$date_counter,$year);
1112 $dow=$this->kDate($format_dow,$itsit);
1113 if($dow==$weekday)
1114 {
1115 $week_counter++;
1116 }
1117
1118 if( ($week_counter==$number) && ($weekday==$dow) )
1119 {
1120 $week_counter=$number;
1121 if($date_counter > 1) // Thanks to Maurizio Marini <maumar@datalogica.com>
1122 $date_counter--;
1123 }
1124 else
1125 {
1126 $date_counter++;
1127 }
1128 }
1129 while($week_counter<$number);
1130
1131 $itsit=mktime(0,0,0,$month,$date_counter+1,$year);
1132 $format=$this->_format();
1133 $f=explode($this->separator,$format);
1134 $format='%'.$f[0].$this->separator.'%'.$f[1].$this->separator.'%'.$f[2];
1135
1136 if($this->kDate('n',$itsit)!=$month)
1137 {
1138 $this->error='Bad request, try again!!';
1139 $this->exitOnError();
1140 }
1141 else
1142 {
1143 return $this->kDate($format,$itsit);
1144 }
1145 }
1146
1153 function romanDate($date)
1154 {
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');
1159
1160 if($date=='')
1161 {
1162 $date=date('d/m/Y',time());
1163 $old_state=$this->dateFormat;
1164 $this->dateFormat='it';
1165 $year=$this->atomDate($date,'Y');
1166 $month=$this->atomDate($date,'m');
1167 $day=$this->atomDate($date,'d');
1168 $this->dateFormat=$old_state;
1169 }
1170 else
1171 {
1172 $year=$this->atomDate($date,'Y');
1173 $month=$this->atomDate($date,'m');
1174 $day=$this->atomDate($date,'d');
1175 }
1176
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);
1181
1182 $m_tens=substr($month,-2,1)*10;
1183 $m_unit=substr($month,-1,1);
1184
1185 $d_tens=substr($day,-2,1)*10;
1186 $d_unit=substr($day,-1,1);
1187
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];
1191 }
1192
1198 function yearMoonPhases($Y)
1199 {
1200 //Converted from Basic by Roger W. Sinnot, Sky & Telescope, March 1985.
1201 //Converted from javascript by Are Pedersen 2002
1202 //Javascript found at http://www.stellafane.com/moon_phase/moon_phase.htm
1203
1204 $R1 = 3.14159265 / 180;
1205 $U = false;
1206 $s = ""; // Formatted Output String
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);
1214 //X In the Line Below, F is not yet initialized, and J is not used before it set in the FOR loop.
1215 //X J += intval(F); F -= INT(F);
1216 //X Ken Slater, 2002-Feb-19 on advice of Pete Moore of Houston, TX
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 )
1230 {
1231 $J = $J0 + 14*$K9; $F = $F0 + 0.765294*$K9;
1232 $K = $K9/2;
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);
1244 $F += 0.5 / 1440; //Adds 1/2 minute for proper rounding to minutes per Sky & Tel article
1245 $J += intval($F); $F -= intval($F);
1246 //Convert from JD to Calendar Date
1247 $julian=$J+round($F);
1248 $s = jdtogregorian ($julian);
1249 //half K
1250 if (($K9-floor($K9))>0)
1251 {
1252 if (!$U)
1253 {
1254 //New half
1255 $phases[$s]="New Half";
1256 }
1257 else
1258 {
1259 //Full half
1260 $phases[$s]="Full Half";
1261 }
1262 }
1263 else
1264 {
1265 //full K
1266 if ( !$U )
1267 {
1268 $phases[$s]="New Moon";
1269 }
1270 else
1271 {
1272 $phases[$s]="Full Moon";
1273 }
1274 $U = !$U;
1275 }
1276 } // Next
1277 return $phases;
1278 } //End MoonPhase
1279
1280 /*
1281 Public: Return the Moon phase for given date, if no date is present refer to present day
1282 */
1283 function todayMoonPhase($date='')
1284 {
1285 if(!isset($date) || $date=='')
1286 {
1287 $time=time();
1288 }
1289 else
1290 $time=$this->dateToTimestamp($date);
1291
1292 $moon_phases=$this->yearMoonPhases(date("Y",$time));
1293 $day=$this->kDate("%n/%j/%Y",$time);
1294 $k=array_keys($moon_phases);
1295 $ab=$this->abbr;
1296 $this->abbr=true;
1297 while(!$key=array_search($day,$k))
1298 {
1299 $day=$this->operation('-',$day,'1%D');
1300 }
1301 $this->abbr=$ab;
1302 return $moon_phases[$day];
1303 }
1304
1320 function getSunTime($latitude=0,$longitude=0,$timezone=1,$location='IT|Roma',$daylight=1,$date='')
1321 {
1322 $result='';
1323 if(!isset($date) || $date=='')
1324 {
1325 $time=time();
1326 }
1327 else
1328 $time=$this->dateToTimestamp($date);
1329
1330 if($location!='' && ($latitude==0 || $longitude==0))
1331 {
1332 require_once '_it_geo_coord.dat.php';
1333 $location=strtoupper($location);
1334 if(in_array($location,array_keys($_geo_coord)))
1335 {
1336 $exp=explode('|',$_geo_coord[$location]);
1337 $latitude=$exp[0];
1338 $longitude=$exp[1];
1339 }
1340 }
1341
1342 $yday = date('z',$time);
1343 $mon = date('n',$time);
1344 $mday = date('j',$time);
1345 $year = date('Y',$time);
1346
1347
1348 $DST=$this->_isDaylight($time);
1349 if($DST)
1350 {
1351 $timezone = ($timezone + 1);
1352 }
1353
1354 if($timezone == "13")
1355 {
1356 $timezone = "-11";
1357 }
1358
1359 $A = 1.5708;
1360 $B = 3.14159;
1361 $C = 4.71239;
1362 $D = 6.28319;
1363 $E = 0.0174533 * $latitude;
1364 $F = 0.0174533 * $longitude;
1365 $G = 0.261799 * $timezone;
1366
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
1371 $R = -.0145439;
1372
1373 for ($i = 0; $i < 2; $i++)
1374 {
1375
1376 if (!$i)
1377 {
1378 $J = $A;
1379 $type = "rise";
1380 } # calculate sunrise
1381 else
1382 {
1383 $J = $C;
1384 $type = "set";
1385 } # calculate sunset
1386
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
1392 if ($D == 0)
1393 {
1394 $this->error="Trying to normalize with zero offset...";
1395 $this->exitOnError();
1396 }
1397
1398 while($M < 0)
1399 {
1400 $M = ($M + $D);
1401 }
1402
1403 while($M >= $D)
1404 {
1405 $M = ($M - $D);
1406 }
1407
1408 if (($M / $A) - intval($M / $A) == 0)
1409 {
1410 $M += 4.84814E-06;
1411 }
1412
1413 $P = sin($M) / cos($M); # Solar Right Ascension
1414 $P = atan2(.91746 * $P, 1);
1415
1416 # Quadrant Adjustment
1417 if ($M > $C)
1418 {
1419 $P += $D;
1420 }
1421 else
1422 {
1423 if ($M > $A)
1424 {
1425 $P += $B;
1426 }
1427 }
1428
1429 $Q = .39782 * sin($M); # Solar Declination
1430 $Q = $Q / sqrt(-$Q * $Q + 1); # This is how the original author wrote it!
1431 $Q = atan2($Q, 1);
1432
1433 $S = $R - (sin($Q) * sin($E));
1434 $S = $S / (cos($Q) * cos($E));
1435
1436 if (abs($S) > 1)
1437 {
1438 $result.='none';
1439 } # Null phenomenon
1440
1441 $S = $S / sqrt(-$S * $S + 1);
1442 $S = $A - atan2($S, 1);
1443
1444 if ($type == 'rise')
1445 {
1446 $S = $D - $S ;
1447 }
1448
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
1453 if ($D == 0)
1454 {
1455 $this->error="Trying to normalize with zero offset...";
1456 $this->exitOnError();
1457 }
1458
1459 while($V < 0)
1460 {
1461 $V = ($V + $D);
1462 }
1463
1464 while($V >= $D)
1465 {
1466 $V = ($V - $D);
1467 }
1468
1469 $V = $V * 3.81972;
1470
1471 $hour = intval($V);
1472 $min = intval((($V - $hour) * 60) + 0.5);
1473
1474 $result.="sun$type is at: ";
1475
1476 if($this->timeFormat=='12' || $this->timeFormat==12 || $this->timeFormat='en')
1477 $result.=date( "g:i A", mktime($hour,$min,0,$mon,$mday,$year) );
1478 else
1479 $result.=date( "H:i", mktime($hour,$min,0,$mon,$mday,$year) );
1480
1481 $result.='&nbsp;-&nbsp;';
1482 }
1483 return $result;
1484 }
1485
1486 function pg_time_easy($timestamp)
1487 {
1488 $Date_Time = explode(" ", $timestamp);
1489 $date_pieces = explode("-", $Date_Time[0]);
1490 $time_convert = explode("-", $Date_Time[1]);
1491 $time_pieces = explode(":", $time_convert[0]);
1492
1493 $timestamp = mktime($time_pieces[0], $time_pieces[1], $time_pieces[2], $date_pieces[1], $date_pieces[2], $date_pieces[0]);
1494 return $this->kDate('',$timestamp);
1495 }
1496
1509 function timeToText($seconds, $format="h")
1510 {
1511 $hours=0;
1512 $minutes=0;
1513 $days=0;
1514
1515 if($seconds<=60)
1516 {
1517 $hours=0;
1518 $minutes=0;
1519 }
1520 elseif($seconds>=60 && $seconds<3600)
1521 {
1522 $hours=0;
1523 $minutes=$seconds/60;
1524 $t=explode('.',$minutes);
1525 $minutes=$t[0];
1526 $seconds=round("0.$t[1]"*60);
1527 }
1528 elseif($seconds>=3600 && $seconds<86400)
1529 {
1530 $r=$seconds/3600;
1531 $t=explode('.',$r);
1532 $hours=$t[0];
1533 if($hours>24)
1534 $hours-=24;
1535
1536 $minutes="0.$t[1]"*60;
1537 $t=explode('.',$minutes);
1538 $minutes=$t[0];
1539 $seconds=round("0.$t[1]"*60);
1540 }
1541 elseif($seconds>=86400)
1542 {
1543 $r=$seconds/86400;
1544 $t=explode('.',$r);
1545 $days=$t[0];
1546 $hours="0.$t[1]"*24;
1547 if(!strstr($hours,"."))
1548 {
1549 $minutes=0;
1550 $seconds=0;
1551 }
1552 else
1553 {
1554 $t=explode(".",$hours);
1555 $hours=$t[0];
1556 $mi="0.$t[1]"*60;
1557 if(!strstr($mi,"."))
1558 {
1559 $minutes=$mi;
1560 $seconds=0;
1561 }
1562 else
1563 {
1564 $t=explode(".",$mi);
1565 $minutes=$t[0];
1566 $seconds=round("0.$t[1]"*60);
1567 }
1568 }
1569 }
1570
1571 if($hours>1)
1572 $hours.=($format=='h' || $format=='d') ? 'h ' : 'hours ';
1573 else
1574 $hours.=($format=='h' || $format=='d') ? 'h ' : 'hour ';
1575
1576 if($minutes>1)
1577 $minutes.=($format=='h' || $format=='d') ? 'm ' : 'minutes ';
1578 else
1579 $minutes.=($format=='h' || $format=='d') ? 'm ' : 'minute ';
1580
1581 if($seconds>1)
1582 $seconds.=($format=='h' || $format=='d') ? 's ' : 'seconds ';
1583 else
1584 $seconds.=($format=='h' || $format=='d') ? 's ' : 'second ';
1585
1586 if($days>1)
1587 $days.=($format=='h' || $format=='d') ? 'd ' : 'days ';
1588 else
1589 $days.=($format=='h' || $format=='d') ? 'd ' : 'day ';
1590
1591 $timestr=$hours.$minutes.$seconds;
1592 $datestr=$days;
1593
1594 if($format=="d" || $format=="D")
1595 return $datestr.$timestr;
1596 else
1597 return $timestr;
1598 }
1599
1609 function secsToTime($secs)
1610 {
1611 if($secs == 0)
1612 {
1613 return "-empty-";
1614 }
1615 else
1616 {
1617 $hours = round(floor(($secs/3600)),0); // just the whole hours
1618 $minutes = $secs % 3600; //remainder
1619 $minutes = $minutes/60;
1620
1621 if($minutes == 0)
1622 { // tidy up output
1623 $minutes = '00';
1624 }
1625
1626 return $hours.":".$minutes;
1627 }
1628 }
1629
1638 function isValid($date)
1639 {
1640 if(strstr($date, ':'))
1641 {
1642 if(strstr($date," "))
1643 {
1644 $t = explode(' ',$date);
1645 $time = $t[1];
1646 $date = explode($this->separator,$t[0]);
1647 }
1648 else
1649 {
1650 $time = $date;
1651 $date = "";
1652 }
1653 }
1654 else
1655 $date = explode($this->separator,$date);
1656
1657 $time = (isset($time)) ? explode(':',$time) : "";
1658
1659 if(isset($time) && $time!="")
1660 {
1661 $hour = $time[0];
1662 $mins = (isset($time[1])) ? $time[1] : 0;
1663 $seconds = (isset($time[2])) ? $time[2] : 0;
1664 }
1665 else
1666 {
1667 $time = 1;
1668 $hour = 0;
1669 $mins = 0;
1670 $seconds = 0;
1671 }
1672
1673 if($date!="")
1674 {
1675 switch($this->dateFormat)
1676 {
1677 case 'ansi': $year=$date[1]; $month=$date[2]; $day=$date[0]; break; // using YYYY-MM-DD
1678 case 'it': $day=$date[1]; $month=$date[0]; $year=$date[2]; break;// using dd-mm-yyyy
1679 case 'br': $day=$date[1]; $month=$date[0]; $year=$date[2]; break;// using dd-mm-yyyy
1680 case 'std': $month=$date[0]; $day=$date[1]; $year=$date[2]; break; // using MM-DD-YYYY
1681 case 'en': $month=$date[0]; $day=$date[1]; $year=$date[2]; break; // using MM-DD-YYYY
1682 default: $this->error='Date Format not recognized, must be "ansi", "it", "std" or "en" !! '; $this->exitOnError();
1683 }
1684 }
1685
1686 switch($this->timeFormat)
1687 {
1688 case 'it':
1689 case 24:
1690 case '24':
1691 if($hour>=0 && $hour<=24 && $mins>=0 && $mins<=59 && $seconds>=0 && $seconds<=59)
1692 $time=1;
1693 else
1694 $time=0;
1695 break;
1696 case 'en':
1697 case '12':
1698 case 12:
1699 if($hour>=0 && $hour<=12 && $mins>=0 && $mins<=59 && $seconds>=0 && $seconds<=59)
1700 $time=1;
1701 else
1702 $time=0;
1703 break;
1704 default: $this->error='Time Format not recognized, must be "it" or "24", "en" or "12" !! '; $this->exitOnError();
1705 }
1706 if($date!="")
1707 $date = checkdate($month,$day,$year);
1708 else
1709 $date=true;
1710
1711 if($date && $time)
1712 return true;
1713 elseif(!$date)
1714 return -1;
1715 elseif(!$time)
1716 return -2;
1717 elseif(!$date && !$time)
1718 return false;
1719 }
1720
1721
1739 function getInfo($date,$what,$format="short")
1740 {
1741 $result = false;
1742 if($this->isValid($date))
1743 {
1744 if($format=="short" || $format=="s")
1745 $this->abbr=true;
1746 elseif($format=="long" || $format=="l")
1747 $this->abbr=false;
1748 switch(strtolower($what))
1749 {
1750 case 'monthname':
1751 $m=$this->atomDate($date,'m');
1752 $result = $this->NToMonth($m);
1753 break;
1754 case 'dayname':
1755 $time=$this->dateToTimestamp($date);
1756 $weekday = date("w",$time);
1757 $result = $this->NToDay($weekday);
1758 break;
1759 case 'dayofweek':
1760 $time=$this->dateToTimestamp($date);
1761 $weekday = date("w",$time);
1762 $result = $weekday+1;
1763 break;
1764 case 'dayofyear':
1765 $time=$this->dateToTimestamp($date);
1766 $result = date("z",$time)+1;
1767 break;
1768 case 'week':
1769 $time=$this->dateToTimestamp($date);
1770 $week = date("W",$time);
1771 $result = $week;
1772 break;
1773
1774 case 'trimester':
1775 $m=$this->atomDate($date,'m');
1776 if($m>1 && $m<=3)
1777 $result = 1;
1778 elseif($m>3 && $m<=6)
1779 $result = 2;
1780 elseif($m>6 && $m<=9)
1781 $result = 3;
1782 elseif($m>9 && $m<=12)
1783 $result = 4;
1784 break;
1785
1786 default: $this->error='You must specify what kind of info need!';
1787 }
1788 }
1789 else
1790 $this->error='Date Format not recognized, must be "ansi", "it", "std", "br" or "en" !! ';
1791
1792 $this->exitOnError();
1793 return $result;
1794 }
1795
1796 function InvertDate($date=null)
1797 {
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!';
1803 return $date;
1804 }
1805
1806 function CompareDate($dateA, $operator, $dateB)
1807 {
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) {
1813 case '==':
1814 if ($date1 == $date2) return true; else return false;
1815 break;
1816 case '=':
1817 if ($date1 == $date2) return true; else return false;
1818 break;
1819 case '>':
1820 if ($date1 > $date2) return true; else return false;
1821 break;
1822 case '<':
1823 if ($date1 < $date2) return true; else return false;
1824 break;
1825 case '>=':
1826 if ($date1 >= $date2) return true; else return false;
1827 break;
1828 case '<=':
1829 if ($date1 <= $date2) return true; else return false;
1830 break;
1831 case '!=':
1832 if ( !($date1 == $date2) ) return true; else return false;
1833 break;
1834 case '<>':
1835 if ( !($date1 == $date2) ) return true; else return false;
1836 break;
1837 }
1838 }
1839
1840 function GetDay($date)
1841 {
1842 list($day,$month,$year) = explode("/",$date);
1843 return $day;
1844 }
1845
1846 function GetMonth($date)
1847 {
1848 list($day,$month,$year) = explode("/",$date);
1849 return $month;
1850 }
1851
1852 function GetYear($date)
1853 {
1854 list($day,$month,$year) = explode("/",$date);
1855 return $year;
1856 }
1857
1858 function Between($date1, $date, $date2)
1859 {
1860 $num1 = str_replace( "/", "", $this->InvertDate($date1) );
1861 $num = str_replace( "/", "", $this->InvertDate($date) );
1862 $num2 = str_replace( "/", "", $this->InvertDate($date2) );
1863 if ( ($num1 <= $num) && ($num <=$num2) )
1864 return TRUE;
1865 else
1866 return FALSE;
1867 }
1868
1869 function makeTime()
1870 {
1871 $objArgs = func_get_args();
1872 $nCount = count($objArgs);
1873 if ($nCount < 7)
1874 {
1875 $objDate = getdate();
1876 if ($nCount < 1)
1877 $objArgs[] = $objDate["hours"];
1878 if ($nCount < 2)
1879 $objArgs[] = $objDate["minutes"];
1880 if ($nCount < 3)
1881 $objArgs[] = $objDate["seconds"];
1882 if ($nCount < 4)
1883 $objArgs[] = $objDate["mon"];
1884 if ($nCount < 5)
1885 $objArgs[] = $objDate["mday"];
1886 if ($nCount < 6)
1887 $objArgs[] = $objDate["year"];
1888 if ($nCount < 7)
1889 $objArgs[] = -1;
1890 }
1891 $nYear = $objArgs[5];
1892 $nOffset = 0;
1893 if ($nYear < 1970)
1894 {
1895 if ($nYear < 1902)
1896 return 0;
1897 else if ($nYear < 1952)
1898 {
1899 $nOffset = -2650838400;
1900 $objArgs[5] += 84;
1901 // Apparently dates before 1942 were never DST
1902 if ($nYear < 1942)
1903 $objArgs[6] = 0;
1904 }
1905 else
1906 {
1907 $nOffset = -883612800;
1908 $objArgs[5] += 28;
1909 }
1910 }
1911 unset($objArgs[6]);
1912 //die(var_export($objArgs, true));
1913
1914 return call_user_func_array("mktime", $objArgs) + $nOffset;
1915 }
1916}
1917?>
kDate($format="%l %d %F %Y", $timestamp=0)
Definição mkrono.class:833
$version
Definição mkrono.class:98
NToMonth($month)
Definição mkrono.class:421
netTimestamp($server='time-a.nist.gov', $port=37)
Definição mkrono.class:996
secsToTime($secs)
Definição mkrono.class:1609
$dayNameExt
Definição mkrono.class:53
makeTime()
Definição mkrono.class:1869
_language()
Definição mkrono.class:250
timesAdd($time, $add, $what)
Definição mkrono.class:593
yearMoonPhases($Y)
Definição mkrono.class:1198
Between($date1, $date, $date2)
Definição mkrono.class:1858
swatchTime()
Definição mkrono.class:1018
isValid($date)
Definição mkrono.class:1638
_disclaimer()
Definição mkrono.class:286
_checkIniFile()
Definição mkrono.class:175
exitOnError()
Definição mkrono.class:194
todayMoonPhase($date='')
Definição mkrono.class:1283
_format()
Definição mkrono.class:217
$monthNameExt
Definição mkrono.class:63
$monthNameCon
Definição mkrono.class:68
timeToText($seconds, $format="h")
Definição mkrono.class:1509
howDays($data_ini, $data_fin, $day)
Definição mkrono.class:694
GetMonth($date)
Definição mkrono.class:1846
getNthDay($number, $weekday, $month, $year=0)
Definição mkrono.class:1085
howTo($data)
Definição mkrono.class:670
_isDaylight($time)
Definição mkrono.class:298
__construct($lan='it', $dateFormat='it', $timeFormat='it', $separator='/')
Definição mkrono.class:137
operation($operator, $date, $operand)
Definição mkrono.class:902
$timeFormat
Definição mkrono.class:117
NToDay($day)
Definição mkrono.class:372
atomDate($date, $atom)
Definição mkrono.class:752
kMkTime($exp)
Definição mkrono.class:721
dayToN($day)
Definição mkrono.class:345
GetYear($date)
Definição mkrono.class:1852
mysql_time_easy($timestamp, $mode='mysqlfrom')
Definição mkrono.class:1043
$dataFrom
Definição mkrono.class:73
_debug()
Definição mkrono.class:273
romanDate($date)
Definição mkrono.class:1153
GetDay($date)
Definição mkrono.class:1840
InvertDate($date=null)
Definição mkrono.class:1796
$separator
Definição mkrono.class:122
$dayNameCon
Definição mkrono.class:58
getInfo($date, $what, $format="short")
Definição mkrono.class:1739
getSunTime($latitude=0, $longitude=0, $timezone=1, $location='IT|Roma', $daylight=1, $date='')
Definição mkrono.class:1320
daysDiff($data_ini, $data_fin)
Definição mkrono.class:500
pg_time_easy($timestamp)
Definição mkrono.class:1486
isDay($data, $day)
Definição mkrono.class:444
timesDiff($time_from, $time_to, $result_in="m")
Definição mkrono.class:531
$dateFormat
Definição mkrono.class:108
monthToN($month)
Definição mkrono.class:392
_update()
Definição mkrono.class:207
dateToTimestamp($date)
Definição mkrono.class:471
CompareDate($dateA, $operator, $dateB)
Definição mkrono.class:1806