Kopie des alten Systems |
Dies ist eine alte Kopie des GenWiki und spiegelt den Stand vom 8. Mai 2022 wider. This is an old copy of the GenWiki and reflects the status as of May 8, 2022. Please visit us at wiki.genealogy.net |
GOV/Webservice/PHP/GovTimespan.php
aus GenWiki, dem genealogischen Lexikon zum Mitmachen.
< GOV | Webservice | PHP
<?php define('PRECISION_DAY', 2); define('PRECISION_MONTH', 1); define('PRECISION_YEAR', 0); define('NO_BEGIN', (PHP_MAX_INT*-1)+1); define('NO_END', PHP_MAX_INT); class GovTimespan { var $begin; var $end; function GovTimespan( $begin, $end, $julianDays = FALSE ) { if( $julianDays ) { $this->begin = $begin; $this->end = $end; } else { // input is in years $this->setBeginDate( $begin, 0, 0); $this->setEndDate( $begin, 0, 0); } } function hasBeginMonth() { return ($this->begin % 10) > 0; } function hasEndMonth() { return ($this->end % 10) > 0; } function getBeginYear() { $cal = cal_from_jd($this->begin,CAL_GREGORIAN); return $cal['year']; } function getEndYear() { $cal = cal_from_jd($this->end,CAL_GREGORIAN); return $cal['year']; } function setBeginDate( $year, $month, $day ) { if( $month == 0 ) { $myMonth = 1;} else {$myMonth = $month;} if( $day == 0 ) {$myDay = 1;} else {$myDay = $day;} $julianDay = cal_to_jd(CAL_GREGORIAN,$myMonth,$myDay,$year); $this->begin = ($julianDay * 10) + $this->calculatePrecisionIndicator($month, $day); } function setEndDate( $year, $month, $day ) { if( $month == 0 ) { $myMonth = 1;} else {$myMonth = $month;} if( $day == 0 ) {$myDay = 1;} else {$myDay = $day;} $julianDay = cal_to_jd(CAL_GREGORIAN,$myMonth,$myDay,$year); $this->end = ($julianDay * 10) + $this->calculatePrecisionIndicator($month, $day); } function calculatePrecisionIndicator( $month, $day ) { if( $month == 0 ) return PRECISION_YEAR; if( $day == 0 ) return PRECISION_YEAR; return PRECISION_DAY; } /** Check if the timespans overlap. */ function overlaps( $timespan ) { if ($timespan == null) { $result = true; } else { if ((!$this->hasBeginMonth() && !$timespan->hasEndMonth()) || (!$this->hasEndMonth() && !$timespan->hasBeginMonth())) { /* Timespans overlap only at a value that contains a year (no month or day). * Be lenient in this case. */ $result = ($this->getBeginYear() < $timespan->getEndYear()) && ($this->getEndYear() > $timespan->getBeginYear()); } else { $result = ($this->begin < $timespan->end) && ($this->end > $timespan->begin); } } return $result; } } ?>
Kategorie: GOV-Intern