allow age calculation on NULL birthdate and allow age to be null

+ improve translation of age
This commit is contained in:
Julien Fastré 2021-07-20 23:50:31 +02:00
parent 08e396195c
commit 76e7f5b1ee
4 changed files with 16 additions and 6 deletions

View File

@ -0,0 +1,6 @@
years_old: >-
{age, plural,
one {# an}
many {# ans}
other {# ans}
}

View File

@ -734,9 +734,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->birthdate;
}
public function getAge(): int
public function getAge(): ?int
{
return date_diff($this->birthdate, date_create('now'))->format("%y");
if ($this->birthdate instanceof \DateTimeInterface) {
return date_diff($this->birthdate, date_create('now'))->format("%y");
}
return null;
}
/**

View File

@ -76,10 +76,10 @@
{{ 'Unknown date of birth'|trans }}
{% else %}
{{ person.birthdate|format_date('short') }}
<span class="age">
{{ 'years_old'|trans({ 'age': person.age }) }}
</span>
{% endif %}
<span class="age">
{{ person.age ~ ((person.age > 1) ? ' ans' : ' an') }}
</span>
</div>
{%- if chill_person.fields.nationality == 'visible' -%}

View File

@ -102,7 +102,7 @@ class PersonControllerUpdateTest extends WebTestCase
public function testHiddenFielsArePresent()
{
$crawler = $this->client->request('GET', $this->editUrl);
var_dump($crawler->text());
$configurables = array('placeOfBirth', 'phonenumber', 'email',
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus');
$form = $crawler->selectButton('Enregistrer')->form(); //;