Date helpers for Ember.js using date-fns
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
addon
app
config
lib
tests Add proper helper function documentation May 6, 2018
vendor Initial Commit from Ember CLI v2.10.0 Jan 10, 2017
.editorconfig
.ember-cli
.eslintignore
.eslintrc.js
.gitignore
.jshintrc
.npmignore
.travis.yml Update `ember-cli` and dependencies May 6, 2018
.watchmanconfig
LICENSE.md
README.md Fix typo (data-fns → date-fns) Sep 13, 2017
circle.yml
ember-cli-build.js
index.js
package.json
testem.js Update `ember-cli` and dependencies May 6, 2018
yarn.lock

README.md

Ember date-fns

npm version CircleCI

Lightweight date helpers for your ember-cli application thanks to date-fns. If all you need is to format a date, Ember date-fns will help you.

If you are looking for more features, see ember-moment instead.

Installation

In your ember-cli project, run either

ember install ember-date-fns

or

yarn add ember-date-fns

or

npm install --save ember-date-fns

Available helpers

All helpers map to the date-fns function of the same name.

Usage

date-format

Uses format to format a date object, string or timestamp.

{{date-format date "D. MMM YYYY"}}

date-from-now

Uses distanceInWordsToNow to return "time ago". By default no suffix is added.

{{date-from-now date addSuffix=true}}

Exposing additional date-fns

date-fns provides many functions for manipulating dates. In order to reduce bundle size only date-fns/distance_in_words_to_now and date-fns/format are included by default. However you can include more functions by listing them in your ember-cli-build.js.

Example:

// ember-cli-build.js

const app = new EmberAddon(defaults, {
  'ember-date-fns': {
    includedDateFns: [
      'end_of_day',
    ],
  }
});

This will allow you to import the endOfDay function anywhere in your ember application:

// app/components/sum-component.js

import Ember from 'ember';
import endOfDay from 'date-fns/end_of_day';

// Your component code here...

Contributing

The idea with this project is to expose the most useful date-fns helpers as Ember helpers. Currently only format is supported. Helpers will follow the format date-helper-name. If there is a date-fn you would like to see as a helper feel free to open a Pull Request :)

  • git clone git@github.com:oskarrough/ember-date-fns.git
  • cd ember-date-fns
  • yarn
  • yarn test
  • yarn start