Skip to content

Instantly share code, notes, and snippets.

@rdpoor
Created June 21, 2012 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdpoor/2967023 to your computer and use it in GitHub Desktop.
Save rdpoor/2967023 to your computer and use it in GitHub Desktop.
Demonstration of bug in DateTime#to_formatted_s(:rfc822)
load '../sketches/datetime_bug.rb'
-- create_table(:test_records, {:force=>true})
NOTICE: CREATE TABLE will create implicit sequence "test_records_id_seq" for serial column "test_records.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_records_pkey" for table "test_records"
 (237.7ms) CREATE TABLE "test_records" ("id" serial primary key, "f_datetime" timestamp) 
-> 0.3416s
 (0.3ms) BEGIN
SQL (39.4ms) INSERT INTO "test_records" ("f_datetime") VALUES ($1) RETURNING "id" [["f_datetime", Wed, 14 Sep 0763 00:00:00 UTC +00:00]]
 (0.8ms) COMMIT
DateTimeBug::TestRecord Load (0.5ms) SELECT "test_records".* FROM "test_records" LIMIT 1
expected == found => true
expected = Wed, 14 Sep 0763 00:00:00 +0000 (DateTime, Wed, 14 Sep 0763 00:00:00 +0000)
found = Sat, 14 Sep 0763 00:00:00 +0000 (ActiveSupport::TimeWithZone, Sat, 14 Sep 0763 00:00:00 UTC +00:00)
-- drop_table(:test_records)
 (21.6ms) DROP TABLE "test_records"
-> 0.0219s
=> nil
module DateTimeBug
extend self
def up
ActiveRecord::Schema.define do
create_table(:test_records, :force => true) do |t|
t.datetime :f_datetime
end
end
end
def down
ActiveRecord::Schema.define do
drop_table :test_records
end
end
class TestRecord < ActiveRecord::Base ; end
def do_test
up
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)} (#{expected.class}, #{expected.inspect})")
puts("found = #{found.to_formatted_s(:rfc822)} (#{found.class}, #{found.inspect})")
down
end
do_test
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment