Project

General

Profile

Actions

Bug #10135

closed

Time.at is inaccurate

Added by thesmart (John Smart) over 10 years ago. Updated about 10 years ago.

Status:
Rejected
Target version:
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
[ruby-core:64369]

Description

I believe I have found an issue with Time.at. Many runtimes and DBs use milliseconds since epoch for recording time. Currently, the only way to generate a Time in ruby with milliseconds is:

Time.at(milliseconds / 1000.0)

However, this is inaccurate:

> Time.at(1381089302195 / 1000.0).to_f
=> 1381089302.1949997
> Time.at(1381089302195 / 1000.0).strftime('%3N')
=> "194"

This doesn't make much sense because you would expect:

> 1381089302195 / 1000.0
=> 1381089302.195
> (1381089302195 / 1000.0).to_f
=> 1381089302.195

It seems that somewhere in the MRI, someone is using floating-point math to represent a Time.

Is there any other way (workaround) to construct Time with millisecond accuracy?


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #10136: printf("%.60f\n", 0.1r) shows 0.100000000000000005551115123125782702118158340454101562500000Closed08/15/2014Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0