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

Incorrect results for dates way in the future #49

Closed mlt closed 4 years ago

mlt commented 4 years ago

I've been searching for a way to calculate "humanized" but accurate time difference between time stamps way in the future. All approaches I tried thus far including this gem produce incorrect result.

a = Time.parse('2044-11-18 01:00:00 -0600')
b = Time.parse('2045-03-05 04:00:00 -0600')
TimeDifference.between(a, b).humanize

produces 3 Months, 2 Weeks, 1 Day, 19 Hours, 32 Minutes and 42 Seconds. There should not be minutes and seconds in the output I presume.

mlt commented 4 years ago

Apparently, it is a Year 2038 problem

AlexWayfer commented 4 years ago

Apparently, it is a Year 2038 problem

Wow, good investigation!

mlt commented 4 years ago

Nevermind and I apologize for the noise. It is not Y2038 related. All is good as usually there are ~365.25 days in a year and month length calculated from there. It is all explained in a linked SO post.