jknowles/eeptools — pull request #13 by jasonpbecker (2013-12-03 20:27:27+00:00)
Title: Added precision option

I added a new attribute, `precise`, that is set to a logical value with a default of true. The previous version of this function did not allow for non-integer outputs. The method for calculating age in months and years both produced truncated values much like a `floor` function would.

This new method takes into account leap years and will calculate integer values for years and months. For years, a calendar year is always considered one year regardless of leap years (so 01-01-2012 to 01-01-2013 is 1 year, not 1.002739726 years). The fractional year is calculated as the number of days divided by the number of days in that year.

A similar method is used for months where the fractional months are based on days into that particular month. Therefore, a date on the 15th of the month can be the fractional equivalent of .535714286, .517241379, .5, or .483870968 depending on the month.

One possible refactor of this code could be creating a separate `is_leap_year` function in the package and utilizing that rather than lines 12-14 in this current function. It is not clear to me if this would be independently useful.