class TimeElapser
TimeElapser
Returns time in windows, making easier to query caching to save results
Public Class Methods
sanitize(interval = 1)
click to toggle source
Saninitize current time and returns an starting point of time every interval (in seconds)
Example
If you want to cache results for 5 seconds, do this:
@products = Product.find(:all, :conditions => ['available_date <= ?', TimeElapser.sanitize(5)
])
If RAILS_ROOT is defined, it will use Time.zone.now, otherwise it will use Time.now
# File lib/time_elapser.rb, line 17 def self.sanitize interval = 1 now = (defined?(RAILS_ROOT)) ? Time.zone.now : Time.now if interval > 1 Time.at((now.to_i/interval)*interval) else now end end