Re: Problems with Time

John W Higgins <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAPhAwGz1L87vgQpdwyQpWpsqTLr6oDBZxwEBa65A4tsF0boDZg@mail.gmail.com>
What would you expect here?

On Wed, Apr 24, 2019 at 7:00 AM Andy Jones <[email protected]>
wrote:

> 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
>

You take a time - subtract an exact amount of seconds - and subtract - you
get a Float with no nanoseconds because they have the same nanoseconds
field.

You then take 2 times with different nanosecond fields - and you subtract
then - the nanoseconds fields are different.

This is not a precision issue - it's an input issue (if one wishes to even
call it an issue).

John

P.S. You are being way too fancy here for your own good. t = time - 1 is
where you start here - throwing a bunch of this or that in the middle of it
just makes the problem very much more obfuscated. You subtract one second
and then ask for the number of seconds between the times you get 1.0 - you
subtract 1.00000312731 seconds and ask for the different you get
1.00000312731 seconds


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.