module Tardis::Moment::Traversal

Public Instance Methods

ago() click to toggle source

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.
# File lib/tardis/moment/traversal.rb, line 77
def ago
  # Subtract the Integer from Time.new
  Time.new - self
end
from(timestamp) click to toggle source

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).
# File lib/tardis/moment/traversal.rb, line 11
def from(timestamp)
  # 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 = timestamp.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() click to toggle source

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.
# 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() click to toggle source

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.
# File lib/tardis/moment/traversal.rb, line 87
def later
  # Add the Integer to Time.new
  Time.new + self
end
to(timestamp) click to toggle source

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).
# File lib/tardis/moment/traversal.rb, line 33
def to(timestamp)
  # Transform the time/date object (self), which represents the
  # starting point, to an integer.
  beginning = timestamp.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() click to toggle source

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