All Projects → alpacaaa → Elm Date Distance

alpacaaa / Elm Date Distance

Licence: mit
Date/Time distance helpers: time ago, less than 5 minutes, about 1 month...

Programming Languages

elm
856 projects

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

Available Locales

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].