Problems with Time

Andy Jones <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
Another one for you folks.  Can anyone tell me what is going on here?


360.upto(370) do |d|
  time = Time.now
  t = time - (d * 60 * 60 * 24)
  puts "%s: %s | %s" % [t, time - t, Time.now - t]
end


Output:

2018-04-29 14:53:06 +0100: 31104000.0 | 31104000.00043
2018-04-28 14:53:06 +0100: 31190400.0 | 31190400.000098
2018-04-27 14:53:06 +0100: 31276800.0 | 31276800.000087
2018-04-26 14:53:06 +0100: 31363200.0 | 31363200.000066
2018-04-25 14:53:06 +0100: 31449600.0 | 31449600.000183
2018-04-24 14:53:06 +0100: 31536000.0 | 31536000.000071
2018-04-23 14:53:06 +0100: 31622400.0 | 31622400.000084
2018-04-22 14:53:06 +0100: 31708800.0 | 31708800.000066
2018-04-21 14:53:06 +0100: 31795200.0 | 31795200.000064
2018-04-20 14:53:06 +0100: 31881600.0 | 31881600.000088
2018-04-19 14:53:06 +0100: 31968000.0 | 31968000.000065


I'd expect `time - t` to be slightly different from `Time.now - t`, of course, but why does it appear to have different precision?  `Time.now`, `time` and `time - t` are all of class Time, so there's nothing funny there?


Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Please note that we have updated our privacy policy in line with new data protection regulations. Please refer to our website to view the ways in which we handle your data.


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.