tmlee / time_difference

The missing Ruby method to print out time difference (duration) in year, month, week, day, hour, minute, and second.
https://rubygems.org/gems/time_difference
MIT License
305 stars 92 forks source link

Time Diff in days - need both from and to be counted while computing difference #11

Closed vregdev closed 9 years ago

vregdev commented 9 years ago

When i use: TimeDifference.between(@from_date, @to_date).in_days

where @from_date = '01/01/2014' and @to_date = '12/31/2014', it computes the diff as 364 days.

Is there a way I can have the diff take into account the end-date as well, so that the result comes up as "365" instead of "364" ?

tmlee commented 9 years ago

@vregdev 364 days is the accurate calculation done by the computer. http://www.wolframalpha.com/input/?i=how+many+days+from+01%2F01%2F2014+to+12%2F31%2F2014

365 days is the human estimation. I am afraid the only way to do so is through a workaround. You can calculate that

TimeDifference.between(start_time, end_time).in_years # returns 1 year

and map that 1 year = 365 days