diff --git a/addon/helpers/-base.js b/addon/helpers/-base.js index e44c4ec7..56f646ee 100644 --- a/addon/helpers/-base.js +++ b/addon/helpers/-base.js @@ -1,7 +1,6 @@ import Ember from 'ember'; -const { observer, inject, get, Helper } = Ember; -const { bind:runBind } = Ember.run; +const { observer, inject, get, Helper, run } = Ember; export default Helper.extend({ moment: inject.service(), @@ -17,7 +16,7 @@ export default Helper.extend({ this.clearTimer(); if (interval) { - this.intervalTimer = setTimeout(runBind(this, this.recompute), parseInt(interval, 10)); + this.intervalTimer = run.later(this, 'recompute', parseInt(interval, 10)); } }, @@ -39,7 +38,7 @@ export default Helper.extend({ }, clearTimer() { - clearTimeout(this.intervalTimer); + run.cancel(this.intervalTimer); }, destroy() { diff --git a/addon/helpers/moment.js b/addon/helpers/moment.js index 1a3b57c9..18a6509c 100644 --- a/addon/helpers/moment.js +++ b/addon/helpers/moment.js @@ -1,8 +1,10 @@ -import Ember from 'ember'; import moment from 'moment'; +import BaseHelper from './-base'; -export default Ember.Helper.extend({ - compute(params) { - return moment(...params); +export default BaseHelper.extend({ + compute(params, { locale, timeZone }) { + this._super(...arguments); + + return this.morphMoment(moment(...params), { locale, timeZone }); } }); diff --git a/bower.json b/bower.json index 7a8e66a4..6d87d824 100644 --- a/bower.json +++ b/bower.json @@ -3,5 +3,8 @@ "dependencies": { "ember": "~2.8.0", "ember-cli-shims": "0.1.1" + }, + "resolutions": { + "ember": "~2.8.0" } } diff --git a/tests/integration/moment-test.js b/tests/integration/moment-test.js index 766bacd1..36348b2b 100644 --- a/tests/integration/moment-test.js +++ b/tests/integration/moment-test.js @@ -5,7 +5,8 @@ import { moduleForComponent, test } from 'ember-qunit'; moduleForComponent('moment', { integration: true, beforeEach() { - moment.locale('en'); + this.momentService = this.container.lookup('service:moment'); + this.momentService.changeLocale('en'); } }); @@ -27,7 +28,7 @@ test('moment-from and moment integration', function(assert) { assert.equal(this.$().text(), 'in a day'); }); -test('moment and monent-format helper integration', function(assert) { +test('moment and monent-format helper integration #2', function(assert) { assert.expect(1); this.setProperties({ @@ -39,3 +40,17 @@ test('moment and monent-format helper integration', function(assert) { this.render(hbs`{{moment-format (moment date inputFormat) outputFormat}}`); assert.equal(this.$().text(), 'May 3, 2010'); }); + +test('moment can use the global locale', function(assert) { + assert.expect(1); + + this.setProperties({ + inputFormat: 'M/D/YY', + outputFormat: 'MMMM D, YYYY', + date: '5/3/10' + }); + + this.momentService.changeLocale('fr'); + this.render(hbs`{{moment-format (moment date inputFormat) outputFormat}}`); + assert.equal(this.$().text(), 'mai 3, 2010'); +});