updated underage to function
This commit is contained in:
parent
dd5443a961
commit
d275acde9f
@ -27,14 +27,13 @@ class PersonModel(FiberBaseModel):
|
||||
date_of_birth: date | None = None
|
||||
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def underage(self) -> bool:
|
||||
def is_underage(self, ref_date: date | None = None) -> bool | None:
|
||||
if self.date_of_birth is None:
|
||||
return False
|
||||
today = date.today()
|
||||
age = ( today.year - self.date_of_birth.year
|
||||
- ( (today.month, today.day)
|
||||
if ref_date is None:
|
||||
ref_data = date.today()
|
||||
age = ( ref_date.year - self.date_of_birth.year
|
||||
- ( (ref_date.month, ref_date.day)
|
||||
< (self.date_of_birth.month, self.date_of_birth.day) )
|
||||
)
|
||||
return age < 18
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user