diff --git a/README.md b/README.md index 27d86083..20dd9a24 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,13 @@ It's advisable to run `ember g ember-moment` between upgrades as dependencies ma ## Usage -### Helpers +## Computed Property Macros + +Ships with the following computed property macros: `duration`, `humanize`, `locale`, `tz`, `format`, `calendar`, `moment`, `toNow`, `fromNow`. They can be used individually or composed together. + +[Computed Property Macro Documentation](https://github.com/stefanpenner/ember-moment/wiki/Computed-Property-Macros) + +## Helpers ```hbs {{moment-format date}} @@ -26,49 +32,7 @@ It's advisable to run `ember g ember-moment` between upgrades as dependencies ma {{moment-to-now date}} {{moment-duration ms}} {{moment-calendar date}} -``` - -### Computed Property Macros - -Ships with the following computed property macros: `duration`, `humanize`, `locale`, `format`, `moment`, `toNow`, `fromNow`. They can be used individually or composed together. - -[Full API Documentation](https://github.com/stefanpenner/ember-moment/wiki/Computed-Property-Macros) -#### Moment & Format Computed - -Behaves like `moment()` and will return a moment object. All arguments of the underlying API are supported. - -```js -import momentComputed from 'ember-moment/computeds/moment'; -import format from 'ember-moment/computeds/format'; - -export default Ember.Component.extend({ - createdOn: new Date('01/02/2016'), - createdOnFormatted: format(momentComputed('createdOn'), 'MMMM DD, YYYY') -}); -``` - -#### i18n/Locale - -Locale takes a moment object and apply a locale to that instance - -```js -import momentComputed from 'ember-moment/computeds/moment'; -import format from 'ember-moment/computeds/format'; -import locale from 'ember-moment/computeds/locale'; - -export default Ember.Component.extend({ - moment: Ember.inject.service(), - createdOn: new Date('01/02/2016'), - createdOnFormatted: format(locale(momentComputed('createdOn'), 'moment.locale'), 'MMMM DD, YYYY') -}); -``` - -## Advanced Usage - -### Helpers - -```hbs {{moment-format date outputFormat inputFormat}} {{moment-from-now date}} {{moment-to-now date}} diff --git a/addon/computeds/calendar.js b/addon/computeds/calendar.js index 330440aa..94e61f85 100644 --- a/addon/computeds/calendar.js +++ b/addon/computeds/calendar.js @@ -7,7 +7,7 @@ export default computedFactory(function calendarComputed(params) { throw new TypeError('ember-moment: Invalid Number of arguments, at most 2'); } - const [date, referenceTime] = params; + const [ date, referenceTime ] = params; return moment(date).calendar(referenceTime); }); diff --git a/addon/computeds/locale.js b/addon/computeds/locale.js index a9bee112..d8592edc 100644 --- a/addon/computeds/locale.js +++ b/addon/computeds/locale.js @@ -2,10 +2,10 @@ import moment from 'moment'; import computedFactory from './-base'; -export default computedFactory(function localeComputed([value, locale]) { - if (moment.isMoment(value)) { - value = moment(value); +export default computedFactory(function localeComputed([date, locale]) { + if (!moment.isDuration(date)) { + date = moment(date); } - return value.locale(locale); + return date.locale(locale); }); diff --git a/addon/computeds/tz.js b/addon/computeds/tz.js index d45d73aa..d8c91d5f 100644 --- a/addon/computeds/tz.js +++ b/addon/computeds/tz.js @@ -2,10 +2,6 @@ import moment from 'moment'; import computedFactory from './-base'; -export default computedFactory(function tzComputed([value, tz]) { - if (moment.isMoment(value)) { - value = moment(value); - } - - return value.tz(tz); +export default computedFactory(function tzComputed([date, tz]) { + return moment(date).tz(tz); });