Skip to content

Instantly share code, notes, and snippets.

@jpinnix
Created April 13, 2010 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpinnix/364959 to your computer and use it in GitHub Desktop.
Save jpinnix/364959 to your computer and use it in GitHub Desktop.
formatted_time_accessor :occurs_at, :occurs_until
#initializer
class ActiveRecord::Base
def self.formatted_time_accessor(*names)
names.each do |name|
define_method("formatted_#{name}") do
#self[name].formatted_offset.strftime('%m/%d/%Y %I:%M %p')
self[name].strftime('%m/%d/%Y %I:%M %p')
end
define_method("formatted_#{name}=") do |value|
self[name] = DateTime.strptime(value, '%m/%d/%Y %I:%M %p').to_time
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment