toAge method

int toAge({
  1. bool isVirtualAge = true,
})

add another neighbor widget to this list for example: list .addNeighbor(widget) .addNeighbor(widget) .intoColumn();

Implementation

int toAge({bool isVirtualAge = true}) {
  if (BZObjectUtil.isEmpty(this)) {
    return 0;
  }
  DateTime birthDate = DateTime.parse(this);
  DateTime now = DateTime.now();

  int age = now.year - birthDate.year;

  if (isVirtualAge) {
    bool hasPassedBirthday = now.month > birthDate.month ||
        (now.month == birthDate.month && now.day >= birthDate.day);

    if (hasPassedBirthday) {
      age++;
    }
  }

  return age;
}