Users: Birthday refactoring

Also fixes #118
This commit is contained in:
veselcraft 2021-12-14 18:53:44 +03:00
parent 4a7a37e200
commit 6ef1e533da
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
3 changed files with 6 additions and 6 deletions

View file

@ -317,14 +317,14 @@ class User extends RowModel
return $this->getRecord()->notification_offset;
}
function getBirthday(): ?int
function getBirthday(): ?DateTime
{
return $this->getRecord()->birthday;
return new DateTime($this->getRecord()->birthday);
}
function getAge(): ?int
{
return (int)floor((time() - $this->getBirthday()) / mktime(0, 0, 0, 1, 1, 1971));
return (int)floor((time() - $this->getBirthday()->timestamp()) / mktime(0, 0, 0, 1, 1, 1971));
}
function get2faSecret(): ?string

View file

@ -135,7 +135,7 @@
<span class="nobold">{_"birth_date"}: </span>
</td>
<td>
<input max={date('Y-m-d')} name="birthday" value={gmdate("Y-m-d", $user->getBirthday())} type="date"/>
<input max={date('Y-m-d')} name="birthday" value={$user->getBirthday()->format('%Y-%m-%d')} type="date"/>
</td>
</tr>
<tr>

View file

@ -402,10 +402,10 @@
<td class="label"><span class="nobold">{_"politViews"}:</span></td>
<td class="data">{var $pviews = $user->getPoliticalViews()}{_"politViews_$pviews"}</td>
</tr>
{if $user->getBirthday() > 0}
{if $user->getBirthday()->timestamp() > 0}
<tr>
<td class="label"><span class="nobold">{_"birth_date"}:</span></td>
<td class="data">{date('d F Y',$user->getBirthday())},
<td class="data">{$user->getBirthday()->format('%e %B %Y')},
{tr("years", $user->getAge())}</td>
</tr>
{/if}