Ember-moment
moment.js template helpers for ember
Requirements
- Ember >= 1.10
- If you need support for < Ember 1.10 please use ember-moment 1.x-2.x
- HTMLBars
Usage
- ember-cli < 0.2.3
ember install:addon ember-moment
- ember-cli >= 0.2.3
ember install ember-moment
{{moment date}}
{{ago date}}
{{duration ms}}
Advance
{{moment date outputFormat inputFormat}}
{{ago date inputFormat}}
{{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
{{ago date interval=1000}}
ES6 Moment
This addon provides the ability to import moment as an ES6 module.
import moment from 'moment';
Computed Macro
import computedDuration from 'ember-moment/computeds/duration';
import computedMoment from 'ember-moment/computeds/moment';
import computedAgo from 'ember-moment/computeds/ago';
export default Ember.Controller.extend({
date: new Date('2013-02-08T09:30:26'),
shortDate: computedMoment('date', 'MM/DD/YYYY'),
timeSince: computedAgo('date', true),
computedNumHours: computedDuration(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'
}
}
};
Include moment locales for i18n support
module.exports = function(environment) {
return {
moment: {
includeLocales: ['es', 'fr-ca']
}
};
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/.