~homeworkprod/byceps

ref: 87b31ba68669551f699c7d12cf18401663b2d043 byceps/byceps/services/orga/transfer/models.py -rw-r--r-- 1.0 KiB
87b31ba6 — Jochen Kupperschmidt Fix type errors 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
byceps.services.orga.transfer.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from dataclasses import dataclass
from datetime import date
from typing import Optional

from ....util.datetime.calc import calculate_age, calculate_days_until
from ....util.datetime.monthday import MonthDay


@dataclass(frozen=True)
class Birthday:
    date_of_birth: date

    @property
    def age(self) -> Optional[int]:
        """Return the current age."""
        return calculate_age(self.date_of_birth, today())

    @property
    def days_until_next_birthday(self) -> Optional[int]:
        """Return the number of days until the next birthday."""
        return calculate_days_until(self.date_of_birth, today())

    @property
    def is_today(self) -> Optional[bool]:
        """Return `True` if the birthday is today."""
        return MonthDay.of(self.date_of_birth).matches(today())


def today() -> date:
    return date.today()