xref: /webtrees/app/Elements/AgeAtEvent.php (revision 0b1e93f09de17105396206d67b26349551d9c95c)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Elements;
21
22use function strtolower;
23use function strtoupper;
24
25/**
26 * AGE_AT_EVENT := {Size=1:12}
27 * [ < | > | <NULL>]
28 * [ YYy MMm DDDd | YYy | MMm | DDDd |
29 * YYy MMm | YYy DDDd | MMm DDDd |
30 * CHILD | INFANT | STILLBORN ]
31 * ]
32 * Where:
33 * >         = greater than indicated age
34 * <         = less than indicated age
35 * y         = a label indicating years
36 * m         = a label indicating months
37 * d         = a label indicating days
38 * YY        = number of full years
39 * MM        = number of months
40 * DDD       = number of days
41 * CHILD     = age < 8 years
42 * INFANT    = age <1year
43 * STILLBORN = died just prior, at, or near birth, 0 years
44 */
45class AgeAtEvent extends AbstractElement
46{
47    protected const MAXIMUM_LENGTH = 12;
48
49    public function canonical(string $value): string
50    {
51        $value = parent::canonical($value);
52        $upper = strtoupper($value);
53
54        if ($upper === 'CHILD' || $upper === 'INFANT' || $upper === 'STILLBORN') {
55            return $upper;
56        }
57
58        return strtolower($value);
59    }
60}
61