time_distance v0.0.1 TimeDistance
Show the difference between two specified times, or between a specified time and now
Example results:
- 2 seconds ago
- 6 months ago
- 3 days
- 2 years
Summary
Functions
Distance of times in words for a date in the past or the future. Supports elixir native times, or Timex.DateTime
Functions
Distance of times in words for a date in the past or the future. Supports elixir native times, or Timex.DateTime
Using Timex
iex> {:ok, now} = DateFormat.parse("2016-01-01", "{YYYY}-{0M}-{0D}")
...> {:ok, then} = DateFormat.parse("2015-01-01", "{YYYY}-{0M}-{0D}")
...> TimeDistance.distance_in_words(then, now)
"1 year ago"
Using native elixir dates
iex> now = {{2016, 1, 1}, {14, 18, 38}}
...> then = {{2015, 12, 1}, {14, 18, 38}}
...> TimeDistance.distance_in_words(then, now)
"4 weeks ago"