Sha256: a07351a7b59bf1b8f483897b696db7389736946013cdd92fee74923a83434301
Contents?: true
Size: 492 Bytes
Versions: 7
Compression:
Stored size: 492 Bytes
Contents
class Time # Simplify time range checking # time = 10.minutes.from_now # time.within? 5.minutes # "of right now" is implied # => false # time.within? 20.minutes # => true # time.within? 1.minute, :of => 12.minutes.from_now # => false # time.within? 5.minutes, :of => 12.minutes.from_now # => true def within?(period, options = {}) comparison_point = options[:of] || Time.now time_difference = (comparison_point - self).abs time_difference < period end end
Version data entries
7 entries across 7 versions & 1 rubygems