Skip to content

Instantly share code, notes, and snippets.

@sgrif
Created June 14, 2014 13:42
Show Gist options
  • Save sgrif/0af0158e1875387956a7 to your computer and use it in GitHub Desktop.
Save sgrif/0af0158e1875387956a7 to your computer and use it in GitHub Desktop.
Test Time Zone
require_relative '../load_paths'
require 'active_record'
require 'active_support/all'
Time.zone = ActiveSupport::TimeZone['Central Time (US & Canada)']
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection(adapter: :sqlite3, database: ':memory:')
class MyModel < ActiveRecord::Base
connection.create_table :my_models, force: true do |t|
t.datetime :a_datetime
end
end
my_model = MyModel.new(a_datetime: '2014-06-14 07:39:00')
p my_model.a_datetime # => Sat, 14 Jun 2014 07:39:00 CDT -05:00
my_model.save!
my_model.reload
p my_model.a_datetime # => Sat, 14 Jun 2014 07:39:00 CDT -05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment