diff --git a/README.md b/README.md index 58051e6b..52857b52 100644 --- a/README.md +++ b/README.md @@ -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 --}} diff --git a/addon/helpers/unix.js b/addon/helpers/unix.js new file mode 100644 index 00000000..208cbb4c --- /dev/null +++ b/addon/helpers/unix.js @@ -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); + } +}); diff --git a/app/helpers/unix.js b/app/helpers/unix.js new file mode 100644 index 00000000..bcb8bf29 --- /dev/null +++ b/app/helpers/unix.js @@ -0,0 +1 @@ +export { default, unix } from 'ember-moment/helpers/unix'; diff --git a/tests/dummy/app/controllers/index.js b/tests/dummy/app/controllers/index.js index 7bee8d4d..2d993d24 100644 --- a/tests/dummy/app/controllers/index.js +++ b/tests/dummy/app/controllers/index.js @@ -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, diff --git a/tests/dummy/app/templates/partials/format.hbs b/tests/dummy/app/templates/partials/format.hbs index a73361ba..ec574318 100644 --- a/tests/dummy/app/templates/partials/format.hbs +++ b/tests/dummy/app/templates/partials/format.hbs @@ -39,3 +39,10 @@ \{{moment-format currentTime 'LL' 'LLLL'}} + +
+{{moment-format (unix unixTimeStamp) 'LL' 'LLLL'}} + + \{{moment-format (unix unixTimeStamp) 'LL' 'LLLL'}} + +
diff --git a/tests/unit/helpers/unix-test.js b/tests/unit/helpers/unix-test.js new file mode 100644 index 00000000..2cd1ebd9 --- /dev/null +++ b/tests/unit/helpers/unix-test.js @@ -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'); +});