Module: Sequel::NumericExtensions
- Defined in:
- lib/sequel/core_ext.rb
Overview
Facilitates time calculations by providing methods to convert from larger time units to seconds, and to convert relative time intervals to absolute ones. This module duplicates some of the functionality provided by Rails’ ActiveSupport::CoreExtensions::Numeric::Time module.
Constant Summary collapse
- MINUTE =
60
- HOUR =
3600
- DAY =
86400
- WEEK =
DAY * 7
Class Method Summary collapse
-
.enable ⇒ Object
Extends the Numeric class with numeric extensions.
Instance Method Summary collapse
-
#ago(t = Time.now) ⇒ Object
(also: #before)
Returns the time at now - self.
-
#days ⇒ Object
(also: #day)
Converts self from days to seconds.
-
#from_now(t = Time.now) ⇒ Object
(also: #since)
Returns the time at now + self.
-
#hours ⇒ Object
(also: #hour)
Converts self from hours to seconds.
-
#minutes ⇒ Object
(also: #minute)
Converts self from minutes to seconds.
-
#weeks ⇒ Object
(also: #week)
Converts self from weeks to seconds.
Class Method Details
.enable ⇒ Object
Extends the Numeric class with numeric extensions.
55 56 57 |
# File 'lib/sequel/core_ext.rb', line 55 def self.enable Numeric.send(:include, self) end |
Instance Method Details
#ago(t = Time.now) ⇒ Object Also known as: before
Returns the time at now - self.
47 |
# File 'lib/sequel/core_ext.rb', line 47 def ago(t = Time.now); t - self; end |
#days ⇒ Object Also known as: day
Converts self from days to seconds
42 |
# File 'lib/sequel/core_ext.rb', line 42 def days; self * DAY; end |
#from_now(t = Time.now) ⇒ Object Also known as: since
Returns the time at now + self.
51 |
# File 'lib/sequel/core_ext.rb', line 51 def from_now(t = Time.now); t + self; end |
#hours ⇒ Object Also known as: hour
Converts self from hours to seconds
40 |
# File 'lib/sequel/core_ext.rb', line 40 def hours; self * HOUR; end |