Ghost/ghost/admin/app/services/clock.js
Kevin Ansfield 9487ff9bae switch to ember-cli-moment-shim (#622)
no issue

- preparation for using `ember-pikaday` that utilizes `ember-cli-moment-shim`
- removes usage of `moment` global
- removes custom imports of `moment` and `moment-timezone` libraries
2017-04-05 19:45:35 +02:00

40 lines
727 B
JavaScript

import Ember from 'ember';
import Service from 'ember-service';
import run from 'ember-runloop';
import moment from 'moment';
// ember-cli-shims doesn't export Ember.testing
const {testing} = Ember;
const ONE_SECOND = 1000;
// Creates a clock service to run intervals.
export default Service.extend({
second: null,
minute: null,
hour: null,
init() {
this.tick();
},
tick() {
let now = moment().utc();
this.setProperties({
second: now.seconds(),
minute: now.minutes(),
hour: now.hours()
});
if (!testing) {
run.later(() => {
this.tick();
}, ONE_SECOND);
}
}
});