moduleOneTimeZonemoduleActiveRecordMethods# def self.extended(base)
# puts "extending #{base.inspect}"
# base.module_eval do
# def self.inherited(subclass)
# puts "inherited #{subclass}"
# attributes=columns.select { |c| c.type ==:datetime }.map(&:name)
# tz_time_attributes attributes
# end
# end
# end
defone_time_zone(options={})
class_inheritable_array :tz_attributes,:instance_writer=>falseself.tz_attributes =columns.select {|c| c.type ==:datetime}.map(&:name)
class_eval do
tz_attributes.each do |attribute|
define_method attribute do
time = read_attribute(attribute)if(time.acts_like?(:time)|| time.acts_like?(:date))# && time.utc?
time=time.utc
write_attribute(attribute, time.in_current_time_zone)else
time
endendendprotecteddeffix_timezone
tz_attributes.each do |attribute|
send attribute.to_sym
endendend# we need to do this in both since if they save(false) we still
# want the proper time to be saved to the database
before_validation:fix_timezonebefore_save:fix_timezoneendendend