Issue Type: Bug Bug
Assignee: Thomas E Enebo
Created: 25/Oct/12 4:08 PM
Description:

Ruby 1.9(.3?) supports passing a rational value for the µsec portion of a time, as follows:

Time.utc(2012, 10, 25, 15, 16, "1/100".to_r)

However, internally we resolve the rational to a double and then normalize that to a long nsec value. This leads to cases where we fail to preserve the exact time value passed in if it can't be represented exactly in a double.


A simple script (originally found while investigating JRUBY-6964) illustrates fractional µsec values that fail to roundtrip properly:

require 'date'

def format time
  time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
end

loop do
  dt   = DateTime.now
  time = dt.to_time
  if format(dt) != format(time)
    puts "FAILED:"
    puts dt.sec_fraction
    puts time.subsec
  end
end

The numbers are all rationals that have repeating decimal representations. A few examples from the above script's output:

FAILED:
371/500
741/1000
FAILED:
149/200
93/125
FAILED:
187/250
747/1000
FAILED:
377/500
753/1000
FAILED:
19/25
759/1000
FAILED:
763/1000
381/500
Project: JRuby
Priority: Major Major
Reporter: Charles Oliver Nutter
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to