Skip to content

Commit

Permalink
Merge pull request #190 from stavarotti/feature-unix-helper
Browse files Browse the repository at this point in the history
[Feature] Add unix helper
  • Loading branch information
jasonmit authored Sep 26, 2016
2 parents fb1d9de + 500d2b7 commit 566cbef
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Ships with the following computed property macros: `duration`, `humanize`, `loca
```hbs
{{moment-format date outputFormat inputFormat}} {{!-- outputFormat and inputFormat is optional --}}
{{moment-from-now (now) date hideSuffix=true}} {{!-- hideSuffix is optional --}}
{{moment-to-now (now) date hidePrefix=true}} {{!-- hidePrefix is optional --}}
{{moment-to-now (unix timeStamp) date hidePrefix=true}} {{!-- hidePrefix is optional --}}
{{moment-duration number units}} {{!-- units is optional --}}
{{moment-calendar date referenceDate}} {{!-- reference date is optional --}}
{{is-before date comparison precision='year'}} {{!-- precision is optional --}}
Expand Down
10 changes: 10 additions & 0 deletions addon/helpers/unix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import moment from 'moment';
import BaseHelper from './-base';

export default BaseHelper.extend({
compute([unixTimeStamp]) {
this._super(...arguments);

return moment.unix(unixTimeStamp);
}
});
1 change: 1 addition & 0 deletions app/helpers/unix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, unix } from 'ember-moment/helpers/unix';
1 change: 1 addition & 0 deletions tests/dummy/app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default Ember.Controller.extend({
},
emptyDate: null,
currentTime: new Date(),
unixTimeStamp: 946684799,
lastHour: new Date(new Date().valueOf() - (60*60*1000)),
date: new Date(),
numHours: 822,
Expand Down
7 changes: 7 additions & 0 deletions tests/dummy/app/templates/partials/format.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@
\{{moment-format currentTime 'LL' 'LLLL'}}
</code>
</div>

<div class="example">
{{moment-format (unix unixTimeStamp) 'LL' 'LLLL'}}
<code>
\{{moment-format (unix unixTimeStamp) 'LL' 'LLLL'}}
</code>
</div>
17 changes: 17 additions & 0 deletions tests/unit/helpers/unix-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import moment from 'moment';
import hbs from 'htmlbars-inline-precompile';
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('unix', {
integration: true,
beforeEach() {
moment.locale('en');
}
});

test('returns the result of moment.unix', function(assert) {
assert.expect(1);

this.render(hbs`{{moment-format (unix 946684799) 'YYYYMMDD'}}`);
assert.equal(this.$().text(), '19991231');
});

0 comments on commit 566cbef

Please sign in to comment.