nafiesl / silsilah

A genealogy/family tree application, built with Laravel.
MIT License
588 stars 284 forks source link

[PROPOSAL] Add user age based on given date of birth and date of death #26

Closed nafiesl closed 5 years ago

nafiesl commented 5 years ago

It will be nice if we have age information of a user/person. For example, if we visit a person profile, we see age of the person after their name.

We can calculate person age by this method:

  1. User dob (date of birth) are filled (must be filled first).
  2. We calculate current year - person year of birth (from their dob).
  3. If dod (date of death) are filled, we calculate year difference.
  4. If dod is null and yod (year of death) are filled, we calculate year difference.

We can use eloquent accessor to set age attribute of a person, like this $user->age.

nafiesl commented 5 years ago

I think we also need to add yob (year of birth) column on users table, since we not always get exact person date of birth. I often see a genealogy book/paper, a person with year range like: 1920 - 1995.

biplobice commented 5 years ago

Opinions:

nafiesl commented 5 years ago

In the first time I use only date of death, I often found that people don't know exact date of date of their family. They only remember the year. So i fill the date of death with given year followed by -01-01, e.g. 2001-01-01.

But it's not a valid data, right? So i decide to add yod column as the solution and we have a valid data (year of death instead of invalid given date).

Same idea goes to yob (year of birth), which hasn't added, yet.

Why we are calculating the year instead of date of birth? Well, I believe we (usually) only need the years old value.

What do you think @biplobice?

biplobice commented 5 years ago

Case 1: In this case, I think your solution is fine.

Case2: Yeah, we need only the years old value, but from the actual age. Suppose, my dob is 2000-07-01. On 2019-01-01, my age is 18 years 6 months 0 days. What we can say 18 year(age) years old. On 2019-12-01, my age is 19 years 5 months 0 days. What we can say 19 year(age) years old.

But if we, calculate from year to year 2019-2000 = 19, which is incorrect.

In case, where the dob or dod isn't available, we've to calculate from the year.

nafiesl commented 5 years ago

OK, I've got your point :ok_hand: Thank you for your suggestion :+1:

nafiesl commented 5 years ago

@biplobice, I am creating PR #27 for this feature. If you don't mind and have some spare time, kindly please review this feature on person_age branch.

Thank you in advance.:pray:

biplobice commented 5 years ago

@nafiesl Sorry, I’m late due to a busiest weekend. I didn't have opportunity to run, but as your commit seems good to me. Just left one comment.