diff options
| author | Greg Roach <fisharebest@gmail.com> | 2015-09-27 09:12:22 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2015-09-27 09:12:22 +0100 |
| commit | 44f3c1494a4da70175ffd2d40aa661783f529868 (patch) | |
| tree | 10cb5d30ed279aa3eb56423db0b7ab1227da7d40 /app/Census | |
| parent | a53db70de9092a80529e77db445001f1acf43696 (diff) | |
| download | webtrees-44f3c1494a4da70175ffd2d40aa661783f529868.tar.gz webtrees-44f3c1494a4da70175ffd2d40aa661783f529868.tar.bz2 webtrees-44f3c1494a4da70175ffd2d40aa661783f529868.zip | |
Unit tests
Diffstat (limited to 'app/Census')
| -rw-r--r-- | app/Census/CensusColumnChildrenBornAlive.php | 6 | ||||
| -rw-r--r-- | app/Census/CensusColumnChildrenDied.php | 8 | ||||
| -rw-r--r-- | app/Census/CensusColumnChildrenLiving.php | 7 | ||||
| -rw-r--r-- | app/Census/CensusColumnMarriedWithinYear.php (renamed from app/Census/CensusColumnMarriedWithinOneYear.php) | 10 | ||||
| -rw-r--r-- | app/Census/CensusColumnMonthIfBornWithinYear.php | 7 | ||||
| -rw-r--r-- | app/Census/CensusColumnMonthIfMarriedWithinYear.php | 9 | ||||
| -rw-r--r-- | app/Census/CensusOfUnitedStates1850.php | 2 | ||||
| -rw-r--r-- | app/Census/CensusOfUnitedStates1860.php | 2 |
8 files changed, 44 insertions, 7 deletions
diff --git a/app/Census/CensusColumnChildrenBornAlive.php b/app/Census/CensusColumnChildrenBornAlive.php index b728d9b4cd..3a5963de16 100644 --- a/app/Census/CensusColumnChildrenBornAlive.php +++ b/app/Census/CensusColumnChildrenBornAlive.php @@ -37,7 +37,11 @@ class CensusColumnChildrenBornAlive extends AbstractCensusColumn implements Cens $count = 0; foreach ($individual->getSpouseFamilies() as $family) { foreach ($family->getChildren() as $child) { - if (Date::compare($child->getBirthDate(), $this->date()) < 0 && $child->getBirthDate() != $child->getDeathDate()) { + if ( + $child->getBirthDate()->isOK() && + Date::compare($child->getBirthDate(), $this->date()) < 0 && + $child->getBirthDate() != $child->getDeathDate() + ) { $count++; } } diff --git a/app/Census/CensusColumnChildrenDied.php b/app/Census/CensusColumnChildrenDied.php index 249f42d4b0..fc7be84dc0 100644 --- a/app/Census/CensusColumnChildrenDied.php +++ b/app/Census/CensusColumnChildrenDied.php @@ -37,7 +37,13 @@ class CensusColumnChildrenDied extends AbstractCensusColumn implements CensusCol $count = 0; foreach ($individual->getSpouseFamilies() as $family) { foreach ($family->getChildren() as $child) { - if (Date::compare($child->getBirthDate(), $this->date()) < 0 && $child->getBirthDate() != $child->getDeathDate() && Date::compare($child->getDeathDate(), $this->date()) < 0) { + if ( + $child->getBirthDate()->isOK() && + Date::compare($child->getBirthDate(), $this->date()) < 0 && + $child->getBirthDate() != $child->getDeathDate() && + $child->getDeathDate()->isOK() && + Date::compare($child->getDeathDate(), $this->date()) < 0 + ) { $count++; } } diff --git a/app/Census/CensusColumnChildrenLiving.php b/app/Census/CensusColumnChildrenLiving.php index c23116ca7e..3f798f5fe9 100644 --- a/app/Census/CensusColumnChildrenLiving.php +++ b/app/Census/CensusColumnChildrenLiving.php @@ -37,7 +37,12 @@ class CensusColumnChildrenLiving extends AbstractCensusColumn implements CensusC $count = 0; foreach ($individual->getSpouseFamilies() as $family) { foreach ($family->getChildren() as $child) { - if (Date::compare($child->getBirthDate(), $this->date()) < 0 && $child->getBirthDate() != $child->getDeathDate() && Date::compare($child->getDeathDate(), $this->date()) >= 0) { + if ( + $child->getBirthDate()->isOK() && + Date::compare($child->getBirthDate(), $this->date()) < 0 && + $child->getBirthDate() != $child->getDeathDate() && + (!$child->getDeathDate()->isOK() || Date::compare($child->getDeathDate(), $this->date()) > 0) + ) { $count++; } } diff --git a/app/Census/CensusColumnMarriedWithinOneYear.php b/app/Census/CensusColumnMarriedWithinYear.php index 373cf1cd46..6611f11d48 100644 --- a/app/Census/CensusColumnMarriedWithinOneYear.php +++ b/app/Census/CensusColumnMarriedWithinYear.php @@ -20,7 +20,7 @@ use Fisharebest\Webtrees\Individual; /** * Did the individual marry within the last year. */ -class CensusColumnMarriedWithinOneYear extends AbstractCensusColumn implements CensusColumnInterface { +class CensusColumnMarriedWithinYear extends AbstractCensusColumn implements CensusColumnInterface { /** * Generate the likely value of this census column, based on available information. * @@ -29,6 +29,14 @@ class CensusColumnMarriedWithinOneYear extends AbstractCensusColumn implements C * @return string */ public function generate(Individual $individual) { + foreach ($individual->getSpouseFamilies() as $family) { + foreach ($family->getFacts('MARR') as $fact) { + if ($fact->getDate()->julianDay() + 365 >= $this->date()->julianDay()) { + return 'Y'; + } + } + } + return ''; } } diff --git a/app/Census/CensusColumnMonthIfBornWithinYear.php b/app/Census/CensusColumnMonthIfBornWithinYear.php index e37db99922..59cd5c762c 100644 --- a/app/Census/CensusColumnMonthIfBornWithinYear.php +++ b/app/Census/CensusColumnMonthIfBornWithinYear.php @@ -29,6 +29,11 @@ class CensusColumnMonthIfBornWithinYear extends AbstractCensusColumn implements * @return string */ public function generate(Individual $individual) { - return ''; + if ($individual->getBirthDate()->julianDay() + 365 >= $this->date()->julianDay()) { + // Use the GEDCOM month, as we need this in English - for the US census + return ucfirst(strtolower($individual->getBirthDate()->minimumDate()->format('%O'))); + } else { + return ''; + } } } diff --git a/app/Census/CensusColumnMonthIfMarriedWithinYear.php b/app/Census/CensusColumnMonthIfMarriedWithinYear.php index 0750ba16d9..259594af23 100644 --- a/app/Census/CensusColumnMonthIfMarriedWithinYear.php +++ b/app/Census/CensusColumnMonthIfMarriedWithinYear.php @@ -29,6 +29,15 @@ class CensusColumnMonthIfMarriedWithinYear extends AbstractCensusColumn implemen * @return string */ public function generate(Individual $individual) { + foreach ($individual->getSpouseFamilies() as $family) { + foreach ($family->getFacts('MARR') as $fact) { + if ($fact->getDate()->julianDay() + 365 >= $this->date()->julianDay()) { + // Use the GEDCOM month, as we need this in English - for the US census + return ucfirst(strtolower($fact->getDate()->minimumDate()->format('%O'))); + } + } + } + return ''; } } diff --git a/app/Census/CensusOfUnitedStates1850.php b/app/Census/CensusOfUnitedStates1850.php index 672fa868ba..17e5f129f9 100644 --- a/app/Census/CensusOfUnitedStates1850.php +++ b/app/Census/CensusOfUnitedStates1850.php @@ -44,7 +44,7 @@ class CensusOfUnitedStates1850 extends CensusOfUnitedStates implements CensusInt new CensusColumnOccupation($this, '', ''), new CensusColumnNull($this, '', ''), // Value of real estate owned new CensusColumnBirthPlace($this, '', ''), - new CensusColumnMarriedWithinOneYear($this, '', ''), + new CensusColumnMarriedWithinYear($this, '', ''), new CensusColumnNull($this, '', ''), // Attended school within year new CensusColumnNull($this, '', ''), // Illiterate new CensusColumnNull($this, '', ''), // Infirm diff --git a/app/Census/CensusOfUnitedStates1860.php b/app/Census/CensusOfUnitedStates1860.php index c010add80b..74849f31a4 100644 --- a/app/Census/CensusOfUnitedStates1860.php +++ b/app/Census/CensusOfUnitedStates1860.php @@ -45,7 +45,7 @@ class CensusOfUnitedStates1860 extends CensusOfUnitedStates implements CensusInt new CensusColumnNull($this, '', ''), // Value of real estate owned new CensusColumnNull($this, '', ''), // Value of personal estate owned new CensusColumnBirthPlace($this, '', ''), - new CensusColumnMarriedWithinOneYear($this, '', ''), + new CensusColumnMarriedWithinYear($this, '', ''), new CensusColumnNull($this, '', ''), // Attended school within year new CensusColumnNull($this, '', ''), // Illiterate new CensusColumnNull($this, '', ''), // Infirm |
