aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-24 13:18:29 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-24 13:18:29 +0000
commit981d86cbb95303597488156cb12a0dcdc88f4cd5 (patch)
tree32c7f1d62b2511c561b0d2723808cc6942feb516 /activerecord/lib/active_record
parent2257980c504d4c20577afc1d35d123dfb9ce411c (diff)
downloadrails-981d86cbb95303597488156cb12a0dcdc88f4cd5.tar.gz
rails-981d86cbb95303597488156cb12a0dcdc88f4cd5.tar.bz2
rails-981d86cbb95303597488156cb12a0dcdc88f4cd5.zip
Added ActiveRecord::Base.timestamps_gmt that can be set to true to make the automated timestamping use GMT instead of local time #520 [Scott Baron]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@491 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/timestamp.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb
index b267284cf8..2c61f9e2d5 100644
--- a/activerecord/lib/active_record/timestamp.rb
+++ b/activerecord/lib/active_record/timestamp.rb
@@ -4,6 +4,7 @@ module ActiveRecord
# automatically included, so you don't need to do that manually.
#
# This behavior can be turned off by setting <tt>ActiveRecord::Base.record_timestamps = false</tt>.
+ # This behavior can use GMT by setting <tt>ActiveRecord::Base.timestamps_gmt = true</tt>
module Timestamp
def self.append_features(base) # :nodoc:
super
@@ -18,18 +19,20 @@ module ActiveRecord
end
def create_with_timestamps
- write_attribute("created_at", Time.now) if record_timestamps && respond_to?(:created_at) && created_at.nil?
- write_attribute("created_on", Time.now) if record_timestamps && respond_to?(:created_on) && created_on.nil?
+ t = timestamps_gmt ? Time.now.gmtime : Time.now
+ write_attribute("created_at", t) if record_timestamps && respond_to?(:created_at) && created_at.nil?
+ write_attribute("created_on", t) if record_timestamps && respond_to?(:created_on) && created_on.nil?
- write_attribute("updated_at", Time.now) if record_timestamps && respond_to?(:updated_at)
- write_attribute("updated_on", Time.now) if record_timestamps && respond_to?(:updated_on)
+ write_attribute("updated_at", t) if record_timestamps && respond_to?(:updated_at)
+ write_attribute("updated_on", t) if record_timestamps && respond_to?(:updated_on)
create_without_timestamps
end
def update_with_timestamps
- write_attribute("updated_at", Time.now) if record_timestamps && respond_to?(:updated_at)
- write_attribute("updated_on", Time.now) if record_timestamps && respond_to?(:updated_on)
+ t = timestamps_gmt ? Time.now.gmtime : Time.now
+ write_attribute("updated_at", t) if record_timestamps && respond_to?(:updated_at)
+ write_attribute("updated_on", t) if record_timestamps && respond_to?(:updated_on)
update_without_timestamps
end
@@ -41,5 +44,7 @@ module ActiveRecord
# if the table has columns of either of these names. This feature is turned on by default.
@@record_timestamps = true
cattr_accessor :record_timestamps
+ @@timestamps_gmt = false
+ cattr_accessor :timestamps_gmt
end
-end \ No newline at end of file
+end