Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Change to end_of_day causes problem with saving records

#3340

In ticket #3212 Almost 1 second extra in time subtraction (rails 2.3.4), it is pointed at that rails 2.3.4 changed the definition of end_of_day to be

change(:hour => 23, :min => 59, :sec => 59, :usec => 999999.999)

where previously it had been

change(:hour => 23, :min => 59, :sec => 59)

If an object that has a datetime field which is set to end_of_day is saved, the datetime is rounded down to just the seconds. When you reload the object, you get back something where the datetime field doesn't == what was saved.

>> e = Event.new(:transaction_date => Time.zone.now.end_of_day)
=> #<Event id: nil, transaction_date: "2009-10-06 23:59:59">
>> e.transaction_date.to_f
=> 1254873600.0
>> e.save!
=> true
>> e.id
=> 2867
>> new_e = Event.find(2867)
=> #<Event id: 2867, account_id: nil, amount: #<BigDecimal:1fe79b8,'0.1E1',4(8)>, description: "desc", flavor: "Withdraw", created_at: "2009-10-06 23:26:42", updated_at: "2009-10-06 23:26:42", post_balance: nil, transaction_date: "2009-10-06 23:59:59", details: nil>
>> new_e.transaction_date.to_f
=> 1254873599.0
>> e.transaction_date == new_e.transaction_date
=> false

In addition, it's difficult to figure out what is wrong because the to_s representations of both dates are the same

>> e.transaction_date
=> Tue, 06 Oct 2009 23:59:59 UTC +00:00
>> new_e.transaction_date
=> Tue, 06 Oct 2009 23:59:59 UTC +00:00

Reported by Steven · October 7th, 2009 @ 12:30 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Gregory Becker
    Gregory Becker

    +1 this change is not compatible with the way date are stored in databases

    November 3rd, 2009 @ 04:45 PM

  2. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 6th, 2010 @ 06:33 AM

  3. bingbing