Skip to content

Commit

Permalink
Updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmit committed Jan 23, 2016
1 parent 52dcc4a commit 4712418
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 54 deletions.
50 changes: 7 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,21 @@ 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}}
{{moment-from-now date}}
{{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}}
Expand Down
2 changes: 1 addition & 1 deletion addon/computeds/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
8 changes: 4 additions & 4 deletions addon/computeds/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
8 changes: 2 additions & 6 deletions addon/computeds/tz.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 4712418

Please sign in to comment.