chronic_duration icon indicating copy to clipboard operation
chronic_duration copied to clipboard

Failing to round at the year mark?

Open andy-twosticks opened this issue 6 years ago • 0 comments

require "chronic_duration"

360.upto(370) do |d|
    time = Time.now
    t = time - (d * 60 * 60 * 24) + rand * 50
    puts "%s: %s | %s" % [ t,
                           time - t,
                           ChronicDuration.output(time - t, units: 1)]
end

Output:

2018-04-29 15:54:35 +0100: 31103965.53874908 | 11 mos
2018-04-28 15:54:19 +0100: 31190381.52392838 | 12 mos
2018-04-27 15:54:07 +0100: 31276793.729049 | 12 mos
2018-04-26 15:54:29 +0100: 31363172.040289067 | 12 mos
2018-04-25 15:54:30 +0100: 31449570.683521885 | 12 mos
2018-04-24 15:54:19 +0100: 31535982.140896846 | 12 mos
2018-04-23 15:54:49 +0100: 31622352.089178756 | 1.0020518698880383 yrs
2018-04-22 15:54:45 +0100: 31708755.525656532 | 1.00478982957058 yrs
2018-04-21 15:54:06 +0100: 31795195.078492984 | 1.0075289337114668 yrs
2018-04-20 15:54:04 +0100: 31881596.925340295 | 1.0102668430216586 yrs
2018-04-19 15:54:18 +0100: 31967982.62229197 | 1.0130042405725395 yrs

The workaround appears to be to truncate time - t to an integer, and pass that instead.

andy-twosticks avatar Apr 24 '19 13:04 andy-twosticks