Ghost/ghost/admin/app/services/clock.js
2018-03-19 13:05:02 +00:00

37 lines
716 B
JavaScript

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