Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8513 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Adding duration with seconds to DateTime gives incorrect result

Reported by: gbuesing Assigned to: core
Priority: normal Milestone: 1.x
Component: ActiveSupport Version: edge
Severity: normal Keywords: duration datetime
Cc:

Description

Adding duration with seconds to DateTime gives incorrect result because it adds seconds with the + operator -- I've converted it to use the #since method, which works for both Times and DateTimes.

Currently:

>> ( DateTime.civil(2000,1,1) + 59.seconds ).to_s(:db)
=> "2000-02-29 00:00:00"

Patched version:

>> ( DateTime.civil(2000,1,1) + 59.seconds ).to_s(:db)
=> "2000-01-01 00:00:59"

I've also fleshed out numeric_ext_test.rb with DateTime examples, and I snuck in a change to DateTime#since so that it rounds the seconds argument when it's a decimal, instead of raising an error.

Attachments

duration_with_seconds_uses_since_instead_of_plus.diff (4.7 kB) - added by gbuesing on 05/30/07 02:06:30.

Change History

05/30/07 02:06:30 changed by gbuesing

  • attachment duration_with_seconds_uses_since_instead_of_plus.diff added.

05/30/07 06:21:12 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [6901]) Time durations use since instead of + for accuracy. Closes #8513.