def as_leeftijd(cls, mks_geboortedatum, ind_onvolledige_datum=None, overlijdensdatum=None): """ birthday string as age Accepts birthday strings with unknown month. The age is unknown in the same month but otherwise simple known as if the birthday was on a arbitrary day in the month :param mks_geboortedatum: :param is_overleden: :return: """ if not mks_geboortedatum or overlijdensdatum: return None incomplete_date_indicator = IncompleteDateIndicator( ind_onvolledige_datum) if not (incomplete_date_indicator.is_jaar_known() and incomplete_date_indicator.is_maand_known()): # jaar and maand are mandatory to calculate age return None if cls._is_mks_datum(mks_geboortedatum): # Interpret all dates as dates in the current timezone now = _today() birthday = datetime.datetime.strptime( mks_geboortedatum, cls._MKS_DATUM_PARSE_FORMAT).date() if incomplete_date_indicator.is_dag_known( ) or now.month != birthday.month: # The dag is mandatory. Unless the current month is unequal to the birthday month # In the latter case the age can be calculated without knowing the exact birthday dag return cls._get_age(now=now, birthday=birthday)
def as_dag(cls, mks_datum, ind_onvolledige_datum=None): if cls._is_mks_datum(mks_datum) and IncompleteDateIndicator( ind_onvolledige_datum).is_dag_known(): return int(cls._dd(mks_datum))
def as_datum(cls, mks_datum, ind_onvolledige_datum=None): if cls._is_mks_datum(mks_datum) and IncompleteDateIndicator( ind_onvolledige_datum).is_datum_complete(): return f"{cls._yyyy(mks_datum)}-{cls._mm(mks_datum)}-{cls._dd(mks_datum)}"