TimeAgo v1.1.0 TimeAgo View Source

Module for getting the amount of days/hours/minutes/seconds since past a specific date.

This module is inspired of functionality in many social networks

Link to this section Summary

Functions

Returns tuple first value is the unit as an atom second value is the amount of days/hours/minutes/seconds

Link to this section Functions

Link to this function

from_date(first, last \\ DateTime.utc_now())

View Source
from_date(DateTime.t(), DateTime.t()) :: {number(), atom()}

Returns tuple first value is the unit as an atom second value is the amount of days/hours/minutes/seconds

second argument has the current time of UTC timezone as default value

Examples

  # returns original date if amount of days are more than 7
  iex> TimeAgo.from_date ~N[2019-12-10 23:00:00], ~N[2019-12-21 22:30:00]
  {:date, ~N[2019-12-10 23:00:00]}

  # returns days if amount of days are more than 0
  iex> TimeAgo.from_date ~N[2019-12-18 12:00:00], ~N[2019-12-21 22:30:00]
  {:days, 3}

  # returns hours if amount of hours are more than 0
  iex> TimeAgo.from_date ~N[2019-12-21 20:00:00], ~N[2019-12-21 22:30:00]
  {:hours, 2}

  # returns minutes if amount of minutes are more than 0
  iex> TimeAgo.from_date ~N[2019-12-21 18:00:00], ~N[2019-12-21 18:30:00]
  {:minutes, 30}

  # returns seconds if amount of seconds are more than 0
  iex> TimeAgo.from_date ~N[2019-12-21 13:00:00], ~N[2019-12-21 13:00:55]
  {:seconds, 55}