Class: TimeElapser
- Inherits:
-
Object
- Object
- TimeElapser
- Defined in:
- lib/time_elapser.rb
Overview
TimeElapser Returns time in windows, making easier to query caching to save results
Class Method Summary collapse
-
.sanitize(interval = 1) ⇒ Object
Saninitize current time and returns an starting point of time every interval (in seconds).
Class Method Details
.sanitize(interval = 1) ⇒ Object
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:
If RAILS_ROOT is defined, it will use Time.zone.now, otherwise it will use Time.now
17 18 19 20 21 22 23 24 |
# 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 |