2 # Active Record automatically timestamps create and update operations if the table has fields
3 # named created_at/created_on or updated_at/updated_on.
5 # Timestamping can be turned off by setting
6 # <tt>ActiveRecord::Base.record_timestamps = false</tt>
8 # Timestamps are in the local timezone by default but can use UTC by setting
9 # <tt>ActiveRecord::Base.default_timezone = :utc</tt>
11 def self.included(base) #:nodoc:
12 base.alias_method_chain :create, :timestamps
13 base.alias_method_chain :update, :timestamps
15 base.cattr_accessor :record_timestamps, :instance_writer => false
16 base.record_timestamps = true
20 def create_with_timestamps #:nodoc:
22 t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
23 write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil?
24 write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil?
26 write_attribute('updated_at', t) if respond_to?(:updated_at)
27 write_attribute('updated_on', t) if respond_to?(:updated_on)
29 create_without_timestamps
32 def update_with_timestamps #:nodoc:
34 t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
35 write_attribute('updated_at', t) if respond_to?(:updated_at)
36 write_attribute('updated_on', t) if respond_to?(:updated_on)
38 update_without_timestamps