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

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

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

#dayObject Also known as: days



29
30
31
# File 'lib/rubyexts/time_dsl.rb', line 29

def day
  self * 86400
end

#hourObject Also known as: hours



24
25
26
# File 'lib/rubyexts/time_dsl.rb', line 24

def hour
  self * 3600
end

#minuteObject Also known as: minutes



19
20
21
# File 'lib/rubyexts/time_dsl.rb', line 19

def minute
  self * 60
end

#monthObject Also known as: months



39
40
41
# File 'lib/rubyexts/time_dsl.rb', line 39

def month
  self * 2592000
end

#secondObject 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

#weekObject Also known as: weeks



34
35
36
# File 'lib/rubyexts/time_dsl.rb', line 34

def week
  self * 604800
end

#yearObject Also known as: years



44
45
46
# File 'lib/rubyexts/time_dsl.rb', line 44

def year
  self * 31471200
end