Module: TimeDSL
- Defined in:
- lib/core_ext/time_dsl.rb
Overview
Provides a a simple way of calling time units and to see the elapsed time between 2 moments
Examples
142.minutes => returns a value in seconds
7.days => returns a value in seconds
1.week => returns a value in seconds
2.weeks.ago => returns a date
1.year.since(time) => returns a date
5.months.since(2.weeks.from_now) => returns a date
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
47 48 49 |
# File 'lib/core_ext/time_dsl.rb', line 47 def ago(time = ::Time.now) time - self end |
#day ⇒ Object Also known as: days
26 27 28 |
# File 'lib/core_ext/time_dsl.rb', line 26 def day self * 86400 end |
#hour ⇒ Object Also known as: hours
21 22 23 |
# File 'lib/core_ext/time_dsl.rb', line 21 def hour self * 3600 end |
#minute ⇒ Object Also known as: minutes
16 17 18 |
# File 'lib/core_ext/time_dsl.rb', line 16 def minute self * 60 end |
#month ⇒ Object Also known as: months
36 37 38 |
# File 'lib/core_ext/time_dsl.rb', line 36 def month self * 2592000 end |
#second ⇒ Object Also known as: seconds
11 12 13 |
# File 'lib/core_ext/time_dsl.rb', line 11 def second self * 1 end |
#since(time = ::Time.now) ⇒ Object Also known as: from_now
Reads best with argument: 10.minutes.since(time)
53 54 55 |
# File 'lib/core_ext/time_dsl.rb', line 53 def since(time = ::Time.now) time + self end |
#week ⇒ Object Also known as: weeks
31 32 33 |
# File 'lib/core_ext/time_dsl.rb', line 31 def week self * 604800 end |
#year ⇒ Object Also known as: years
41 42 43 |
# File 'lib/core_ext/time_dsl.rb', line 41 def year self * 31471200 end |