lib/greenwich/rails.rb in greenwich-0.0.3 vs lib/greenwich/rails.rb in greenwich-0.0.4
- old
+ new
@@ -24,25 +24,22 @@
time = time.to_time
ActiveSupport::TimeWithZone.new(nil, time_zone, time)
},
:converter => Proc.new { |value|
- value[1] = ActiveSupport::TimeZone.new(value[1]) unless value[1].is_a? ActiveSupport::TimeZone
+ value[1] = Greenwich::Utilities.get_time_zone_from(value[1])
value[0] = value[0].to_time
ActiveSupport::TimeWithZone.new(nil, value[1], value[0])
}
define_method "#{time_field}=" do |time|
instance_eval do
- time_zone = read_attribute(time_zone)
+ write_attribute(time_field, time.to_s)
- if time_zone.nil?
- write_attribute(time_field, time.to_s)
- else
- self.send("#{name}=".to_sym, [time, time_zone])
- end
+ time_zone = read_attribute(time_zone)
+ self.send("#{name}=".to_sym, [time, time_zone]) if time && time_zone
end
end
time_zone "#{name}_time_zone".to_sym, :for => name.to_sym if options[:time_zone] == time_zone_field
end
@@ -54,18 +51,17 @@
define_method "#{name}" do
time_zone_name = read_attribute(name)
ActiveSupport::TimeZone.new(time_zone_name) unless time_zone_name.nil?
end
- define_method "#{name}=" do |time_zone|
+ define_method "#{name}=" do |time_zone_string|
instance_eval do
- time_zone = ActiveSupport::TimeZone.new(time_zone) unless time_zone.is_a? ActiveSupport::TimeZone || time_zone.nil?
- time_zone = time_zone.name if time_zone.respond_to? :name
+ time_zone = Greenwich::Utilities.get_time_zone_from(time_zone_string).try(:name)
write_attribute(name, time_zone)
options[:for].each do |composed_field, time_field|
time = read_attribute(time_field)
- self.send("#{composed_field}=".to_sym, [time, time_zone]) unless time.nil?
+ self.send("#{composed_field}=".to_sym, [time, time_zone]) if time && time_zone
end
end
end
end
end