time_difference
time_difference copied to clipboard
Accuracy
Recently I was debugging code which relied on TimeDifference when computing difference in days between two Date
s. It turned out that code like
TimeDifference.between(
Date.new(2015, 3, 15),
Date.new(2015, 4, 14)
).in_days.to_i
returns on different platforms different results. Having read how TimeDifference makes the calculations (dividing difference in seconds by an approximate length of a year / month / day / ... in seconds) I'm not surprised any more by the results, but for the sake of others tempted to make the same mistake I suggest being more explicit in the README concerning accuracy: TimeDifference is great for quick calculations where no accuracy is required (how long is it since I wrote my blog post?), but unsuitable for accurate computations (for how many days of using the service will I be billed?).