time_difference icon indicating copy to clipboard operation
time_difference copied to clipboard

Accuracy

Open igneus opened this issue 8 years ago • 0 comments

Recently I was debugging code which relied on TimeDifference when computing difference in days between two Dates. 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?).

igneus avatar Jun 13 '16 20:06 igneus