Module: TimeDSL
- Defined in:
- lib/rubyexts/time_dsl.rb
Overview
Provides a a simple way of calling time units and to see the elapsed time between 2 moments
Instance Method Summary collapse
-
#ago(time = ::Time.now) ⇒ Object
(also: #until)
Reads best without arguments: 10.minutes.ago.
- #day ⇒ Object (also: #days)
- #hour ⇒ Object (also: #hours)
- #minute ⇒ Object (also: #minutes)
- #month ⇒ Object (also: #months)
- #second ⇒ Object (also: #seconds)
-
#since(time = ::Time.now) ⇒ Object
(also: #from_now)
Reads best with argument: 10.minutes.since(time).
- #week ⇒ Object (also: #weeks)
- #year ⇒ Object (also: #years)
Instance Method Details
#ago(time = ::Time.now) ⇒ Object Also known as: until
Reads best without arguments: 10.minutes.ago
50 51 52 |
# File 'lib/rubyexts/time_dsl.rb', line 50 def ago(time = ::Time.now) time - self end |
#day ⇒ Object Also known as: days
29 30 31 |
# File 'lib/rubyexts/time_dsl.rb', line 29 def day self * 86400 end |
#hour ⇒ Object Also known as: hours
24 25 26 |
# File 'lib/rubyexts/time_dsl.rb', line 24 def hour self * 3600 end |
#minute ⇒ Object Also known as: minutes
19 20 21 |
# File 'lib/rubyexts/time_dsl.rb', line 19 def minute self * 60 end |
#month ⇒ Object Also known as: months
39 40 41 |
# File 'lib/rubyexts/time_dsl.rb', line 39 def month self * 2592000 end |
#second ⇒ Object Also known as: seconds
14 15 16 |
# File 'lib/rubyexts/time_dsl.rb', line 14 def second self * 1 end |
#since(time = ::Time.now) ⇒ Object Also known as: from_now
Reads best with argument: 10.minutes.since(time)
56 57 58 |
# File 'lib/rubyexts/time_dsl.rb', line 56 def since(time = ::Time.now) time + self end |
#week ⇒ Object Also known as: weeks
34 35 36 |
# File 'lib/rubyexts/time_dsl.rb', line 34 def week self * 604800 end |
#year ⇒ Object Also known as: years
44 45 46 |
# File 'lib/rubyexts/time_dsl.rb', line 44 def year self * 31471200 end |