Ember-moment
moment.js template helpers for ember
Requirements
- HTMLBars (see <= 2.0.0 for Handlebar support)
- Ember >= 1.10
- If you need support for < Ember 1.10 please use ember-moment 1.x-2.x
Usage
- ember-cli < 0.2.3
ember install:addon ember-moment
- ember-cli >= 0.2.3
ember install ember-moment
{{moment-format date}}
{{moment-from-now date}}
{{moment-to-now date}}
{{moment-duration ms}}
Advance
{{moment-format date outputFormat inputFormat}}
{{moment-from-now date}}
{{moment-to-now date}}
{{moment-duration number units}}
Recomputes the time ago every 1-second. This is useful for "live" updating as time elapses.
NOTE: This feature is only supported in Ember >= 1.13.0
{{moment-from-now date interval=1000}}
Upgrading
If your npm dep for ember-moment is not fixed on a version (ie, using ~
or ^
) then you may be required to ember g ember-moment
between versions as the default blueprint may have changed.
Please try this, along with clearing node_modules
and bower_components
before reporting issues after upgrades.
ES6 Moment
This addon provides the ability to import moment as an ES6 module.
import moment from 'moment';
Computed Macro
import momentDuration from 'ember-moment/computeds/duration';
import momentFormat from 'ember-moment/computeds/format';
import momentFromNow from 'ember-moment/computeds/from-now';
import momentToNow from 'ember-moment/computeds/to-now';
export default Ember.Controller.extend({
date: new Date('2013-02-08T09:30:26'),
shortDate: momentFormat('date', 'MM/DD/YYYY'),
timeSince: momentFromNow("12-25-1995", "MM-DD-YYYY", false),
computedNumHours: momentToNow("12-25-1995", "MM-DD-YYYY", false),
computedNumHours: momentDuration(10, 'hours')
});
Include Moment Timezone
You can optionally include the Moment Timezone package in your config/environment.js
like so:
module.exports = function() {
return {
moment: {
includeTimezone: 'all'
}
}
};
i18n support
Cherry pick locales (optimal)
module.exports = function(environment) {
return {
moment: {
includeLocales: ['es', 'fr-ca']
}
};
Include all locales
module.exports = function(environment) {
return {
moment: {
includeLocales: true
}
};
Configure default runtime locale
import moment from 'moment';
export default Ember.Route.extend({
beforeModel() {
moment.locale('es');
}
});
Feature set of i18n support within moment can be found here: http://momentjs.com/docs/#/i18n/
Development
Running Tests
ember test
ember test --server
Building
For more information on using ember-cli, visit http://www.ember-cli.com/.