Created
June 21, 2012 17:02
-
-
Save rdpoor/2967023 to your computer and use it in GitHub Desktop.
Demonstration of bug in DateTime#to_formatted_s(:rfc822)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
[1m[36m (237.7ms)[0m [1mCREATE TABLE "test_records" ("id" serial primary key, "f_datetime" timestamp) [0m | |
-> 0.3416s | |
[1m[35m (0.3ms)[0m BEGIN | |
[1m[36mSQL (39.4ms)[0m [1mINSERT INTO "test_records" ("f_datetime") VALUES ($1) RETURNING "id"[0m [["f_datetime", Wed, 14 Sep 0763 00:00:00 UTC +00:00]] | |
[1m[35m (0.8ms)[0m COMMIT | |
[1m[36mDateTimeBug::TestRecord Load (0.5ms)[0m [1mSELECT "test_records".* FROM "test_records" LIMIT 1[0m | |
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) | |
[1m[35m (21.6ms)[0m DROP TABLE "test_records" | |
-> 0.0219s | |
=> nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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