For my needs just getting things right to a day level is all I needed.

But, I could see something more accurate as being useful for other situations.

But to be honest I’m not really that aware of the details of how leap seconds 
come into play. But, I expect someone with a better understanding of that sort 
of stuff could probably come up with a better set of devisers based on seconds 
rather than days. With just a little digging I think you would have to properly 
determine one of the following devisors:

standard year = 31536000 seconds
standard leap year = 31622400 seconds
For all the leap seconds you need some sort of map table of some sort (I’m 
guessing datetime has this some place internally but I don’t see any api to ask 
it for is_leap_sec_year and I”m not sure that by it self would be meaning full 
given what was done in 1972):
http://www.ietf.org/timezones/data/leap-seconds.list 
<http://www.ietf.org/timezones/data/leap-seconds.list>
But generally:
standard year plus leap second = 31536001
standard leap year plus leap second = 31622401
Special care has to be taken for the above depending on when the leap second 
exactly occurred and what your dates are.
1972 (if I understand the above link right) is a very special case and could 
potentially need other possible divisors 31536010, 31536011, 31622410 or 
31622411 it depends on exactly how your dates fell out to know which is exactly 
accurate for a particular set of dates.

Then if you could workout delta_seconds between the two dates minus the years 
(that accounted for leap_years, leap_seconds and timezones) you might be able 
to get something accurate to that level (but not sure it is possible from what 
I can tell we can only get to delta_ms which is minutes and seconds and if my 
reading is right we have no reliable way to convert duration minutes to seconds 
and delta_ms doesn’t mention anything about timezone so that would take some 
experimentation to determine if it deals with that).

I think technically it is doable just not clear to me how to get at the things 
needed with current DateTime API’s.

Matthew

> On Jul 4, 2015, at 8:38 PM, Eric Brine <ikeg...@adaelis.com> wrote:
> 
> On Fri, Jul 3, 2015 at 12:27 PM, <matt...@jenika.com 
> <mailto:matt...@jenika.com>> wrote:
> I have a need to compute a year with fraction between two dates.
> 
> Meaning date 1 = 2005-05-04 date 2 = 2015-05-06 then the year I’m after is 
> 10.0054794520548.
> 
> My thinking on the above is neither 2005 or 2015 is a leap year so I should 
> use a devisor of 365 days and the number of days extra between the above two 
> dates is 2 so 2/365 is 0.0054794520548.
> 
> Based on the above thinking I need to determine two things to do the above 
> generically.
> 
> 1) what devisor to use 365 or 366 (depends on if either the start or end year 
> is a leap year)
> 
> 2) exactly how many days exist between the start date and end date minus all 
> the extra years.
> 
> What about the number of hours in the day? That varies for some days in many 
> time zones.
> 

Reply via email to