# == Schema Information
# Schema version: 3
#
# Table name: events
#
# id :integer(11) not null, primary key
# name :string(30)
# description :text
# flyer_id :integer(11)
# user_id :integer(11)
# start :datetime
# end :datetime
# created_at :datetime
# updated_at :datetime
#
class Event < ActiveRecord::Base
belongs_to :user
def length= time
if self.start
self.end = self.start + time
else
return false
end
end
def self.left_in date, user
month = {:start => date.beginning_of_month, :end => date.end_of_month}
count = user.events.count(:conditions => "`start` > #{month[:start]} AND `start` < #{month[:end]}")
user.allowed_events - count
end
def length
self.end - self.start
end
end