I am starting to get into a situation where I am going to have to get totals for the past 12 months and have started playing with code. Here is where I am at:
def self.tm_beg Time.now.beginning_of_month end
def tm_end Time.now.end_of_month end
def tm_beg_less_1 tm_beg.last_month.beginning_of_month end
def tm_end_less_1 tm_end.last_month.end_of_month end
and so on to tm_beg_less_11/tm_end_less_11
My intention is to use it something like this in the personnel.rb model... @clinical_supervisions_tm = ClinicalReview.find(:all, :conditions => ["personnel_id = ? AND supv_date BETWEEN tm_beg .. tm_end", self.id]) NOTE: don't worry about syntax because I will use ez-where to handle the search
This seems to work fine in console so my questions are:
- Am I missing a plugin that does this for me? (the date math for 12 months)
- If I put these calcs in lib/t_calcs.rb or application.rb or application_helper.rb, it seems not to matter because I am going to have to call it via Class anyway, is there a preferred way?
- Does someone have the whole enchilada calendar utilities/engine that will make me stop hating date/time calcs (not that I don't love the utility that rails gives me for free)?
Thanks
Craig