Skip to content

Rounding error when quoting times with usec > 999499 (off by ~1 sec) #631

@buehmann

Description

@buehmann

We discovered this in v4.2.18.

When quoted, times with microseconds in the range 999500..999999 are rounded down to the next full second (effectively the microseconds are removed) instead of rounded up.

irb(main):154:0> ApplicationRecord.connection.class
=> ActiveRecord::ConnectionAdapters::SQLServerAdapter
irb(main):155:0> ApplicationRecord.connection.class.const_get('VERSION')
=> "4.2.18"
irb(main):156:0> ApplicationRecord.connection.quote('2017-11-25 10:05:38.999499'.to_time)
=> "'11-25-2017 09:05:38.999'"
irb(main):157:0> ApplicationRecord.connection.quote('2017-11-25 10:05:38.999500'.to_time)
=> "'11-25-2017 09:05:38'"
irb(main):158:0> ApplicationRecord.connection.quote('2017-11-25 10:05:38.999999'.to_time)
=> "'11-25-2017 09:05:38'"

I expect '11-25-2017 09:05:39' in the last two examples (or at least '11-25-2017 09:05:38.999'; that's what v5.0.7 seems to do).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions