Module: Tardis::Moment::Traversal
Instance Method Summary collapse
-
#ago ⇒ Object
example: 5.days.ago anatomy: [Integer].ago => Time description: | Called on an Integer object and returns an Time object, which represents the point in time before the given amount of seconds.
-
#from(timestamp) ⇒ Object
example: time_left = next_birthday.from Date.yesterday anatomy: [Time|Date].from() => Integer description: | Called on a Time or Date object and given a Time or Date object.
-
#from_now ⇒ Object
example: time_left = next_birthday.from_now anatomy: [Time|Date].from_now => Integer description: | Called on a Time or Date object and returns an Integer, representing a number of seconds between the object called on (a time in the future) and now in time.
-
#later ⇒ Object
example: 5.days.later anatomy: [Integer].later => Time description: | Called on an Integer object and returns an Time object, which represents the point in time after the given amount of seconds.
-
#to(timestamp) ⇒ Object
example: @account.created_at.to Date.today anatomy: [Time|Date].to() => Integer description: | Called on a Time or Date object and given a Time or Date object.
-
#to_now ⇒ Object
example: @account.created_at.to_now anatomy: [Time|Date].to_now => Integer description: | Called on a Time or Date object and returns an Integer, representing a number of seconds between the object called on (a time in the past) and now in time.
Instance Method Details
#ago ⇒ Object
example: 5.days.ago anatomy: [Integer].ago => Time description: |
Called on an Integer object and returns an Time object, which
represents the point in time before the given amount of seconds.
77 78 79 80 |
# File 'lib/tardis/moment/traversal.rb', line 77 def ago # Subtract the Integer from Time.new Time.new - self end |
#from(timestamp) ⇒ Object
example: time_left = next_birthday.from Date.yesterday anatomy: [Time|Date].from() => Integer description: |
Called on a Time or Date object and given a Time or Date object.
Returns an Integer, representing a number of seconds between the
object called on (a time in the future) and the object given (a
time in the past).
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tardis/moment/traversal.rb', line 11 def from() # Transform the time/date object (self), which represents the # starting point, to an integer. beginning = self.to_i # Transform the time/date object (an argument), which represents # the point in the ending = .to_i # Subtract the end period from the start period which will # return the total amount of time in seconds from the # start the end. beginning - ending end |
#from_now ⇒ Object
example: time_left = next_birthday.from_now anatomy: [Time|Date].from_now => Integer description: |
Called on a Time or Date object and returns an Integer,
representing a number of seconds between the object
called on (a time in the future) and now in time.
54 55 56 57 58 |
# File 'lib/tardis/moment/traversal.rb', line 54 def from_now # Call the .from() method with self as the starting point and # Time.new as the end self.from(Time.new) end |
#later ⇒ Object
example: 5.days.later anatomy: [Integer].later => Time description: |
Called on an Integer object and returns an Time object, which
represents the point in time after the given amount of seconds.
87 88 89 90 |
# File 'lib/tardis/moment/traversal.rb', line 87 def later # Add the Integer to Time.new Time.new + self end |
#to(timestamp) ⇒ Object
example: @account.created_at.to Date.today anatomy: [Time|Date].to() => Integer description: |
Called on a Time or Date object and given a Time or Date object.
Returns an Integer, representing a number of seconds between the
object called on (a time in the past) and the object given (a
time in the future).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tardis/moment/traversal.rb', line 33 def to() # Transform the time/date object (self), which represents the # starting point, to an integer. beginning = .to_i # Transform the time/date object (an argument), which represents # the point in the ending = self.to_i # Subtract the end period from the start period which will # return the total amount of time in seconds from the # start the end. beginning - ending end |
#to_now ⇒ Object
example: @account.created_at.to_now anatomy: [Time|Date].to_now => Integer description: |
Called on a Time or Date object and returns an Integer,
representing a number of seconds between the object
called on (a time in the past) and now in time.
66 67 68 69 70 |
# File 'lib/tardis/moment/traversal.rb', line 66 def to_now # Call the .to() method with self as the starting point and # Time.new as the end self.to(Time.new) end |