This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Date/Time distance helpers: time ago, less than 5 minutes, about 1 month...
version 1.1.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.1.0
Committed At 2017-06-26 08:59:06 UTC
justinmimbs/elm-date-extra 2.0.2 <= v < 3.0.0 2.1.1
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

README

elm-date-distance

Distance between dates in words. Example output:

  • 5 minutes ago
  • about 1 hour
  • in 3 months

Compatible with the core Date type.

Installation

elm-package install alpacaaa/elm-date-distance

Usage

import Date.Distance as Distance

-- Date.Extra is not required
-- you can create Date objects however you prefer
import Date.Extra as Date

date1 = Date.fromParts 2017 May 5 10 20 0 0
date2 = Date.fromParts 2017 May 7 10 20 0 0

Distance.inWords date1 date2 == "2 days"

You can also use a custom configuration (Config docs).

date1 = Date.fromParts 2017 May 7 10 20 0 0
date2 = Date.fromParts 2017 May 7 10 20 15 0

inWords = { Distance.defaultConfig | includeSeconds = True}
    |> Distance.inWordsWithConfig

inWords date1 date2 == "less than 20 seconds"

More examples are available in the /tests folder.

For an in depth table of the results that this package can produce, check Results.md.

This package is heavily influenced by date-fns distanceInWords.