11155
(-- --)
June 21, 2012, 4:36pm
1
I have isolated what appears to be a bug in the Rails extensions to
DateTime, but I don't know where to report it.
I have a standalone file to demonstrate the bug, but the punch line is
that this code:
TestRecord.create!(:f_datetime => (expected = DateTime.jd(2000000)))
found = TestRecord.first.f_datetime
puts("expected == found => #{expected == found}")
puts("expected = #{expected.to_formatted_s(:rfc822)}")
puts("found = #{found.to_formatted_s(:rfc822)}")
generates this response:
expected == found => true
expected = Wed, 14 Sep 0763 00:00:00 +0000
found = Sat, 14 Sep 0763 00:00:00 +0000
So. The dates are equal, but was that day a Wednesday or a Saturday?
Can you post the contents of schema.rb section for the table.
Also it would be interesting to put in some inspect debug for expected
and found.
Colin
11155
(-- --)
June 21, 2012, 5:05pm
3
Can you post the contents of schema.rb section for the table.
Also it would be interesting to put in some inspect debug for expected
and found.
Colin:
Done. See Demonstration of bug in DateTime#to_formatted_s(:rfc822) · GitHub for code and results.
As for "inspect debug for expected and found", I assume you mean like
this:
puts("expected = #{expected.to_formatted_s(:rfc822)}
(#{expected.inspect})")
puts("found = #{found.to_formatted_s(:rfc822)}
(#{found.inspect})")
=>
expected = Wed, 14 Sep 0763 00:00:00 +0000 (Wed, 14 Sep 0763 00:00:00
+0000)
found = Sat, 14 Sep 0763 00:00:00 +0000 (Sat, 14 Sep 0763 00:00:00
UTC +00:00)
HTH.
- ff
11155
(-- --)
June 21, 2012, 6:13pm
4
I've created:
https://github.com/rails/rails/issues/6814
... which seems like the correct place to report this. I'm sure I'll
hear from the rails admin team soon enough if that's not the right
place.
- ff
Can you post the contents of schema.rb section for the table.
Also it would be interesting to put in some inspect debug for expected
and found.
Colin:
Done. See Demonstration of bug in DateTime#to_formatted_s(:rfc822) · GitHub for code and results.
As for "inspect debug for expected and found", I assume you mean like
this:
puts("expected = #{expected.to_formatted_s(:rfc822)}
(#{expected.inspect})")
puts("found = #{found.to_formatted_s(:rfc822)}
(#{found.inspect})")
What is the class of found?
Colin
Also I don't think you have told us which versions of ruby and rails
you are using.
Colin
11155
(-- --)
June 25, 2012, 8:12pm
7
Colin Law wrote in post #1065800:
What is the class of found?
I updated the above mentioned gist. 'expected' is a DateTme, 'found' is
ActiveSupport::TimeWithZone.
Also I don't think you have told us which versions of ruby and rails
you are using.
Apologies, this was buried at the end of the OP:
PS: I'm using postgresql with Ruby 1.93 and Rails 3.2.1
But this is all now moot: I posted this as a Rails issue:
two DateTime objects are == but print differently · Issue #6814 · rails/rails · GitHub
where @pixeltrix patiently educated me on the anomalies of ancient
calendar systems. The best line was "[calendar reforms] can lead to
oddities like William Shakespeare and Miguel de Cervantes dying on the
same date but 10 days apart." He also suggests using #gregorian to
adjust the datetime before converting to time, e.g:
>> DateTime.jd(2000000).gregorian
=> Wed, 18 Sep 0763 00:00:00 +0000
So: not a bug. Just a reality of calendar reforms.