mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 09:53:32 +03:00
75a138cb39
refs https://github.com/TryGhost/Admin/pull/2227 - a continuation of #2227 that runs the native classes codemod against app/services
38 lines
808 B
JavaScript
38 lines
808 B
JavaScript
import Service from '@ember/service';
|
|
import classic from 'ember-classic-decorator';
|
|
import config from 'ghost-admin/config/environment';
|
|
import moment from 'moment';
|
|
import {run} from '@ember/runloop';
|
|
|
|
const ONE_SECOND = 1000;
|
|
|
|
// Creates a clock service to run intervals.
|
|
|
|
@classic
|
|
export default class ClockService extends Service {
|
|
second = null;
|
|
minute = null;
|
|
hour = null;
|
|
|
|
init() {
|
|
super.init(...arguments);
|
|
this.tick();
|
|
}
|
|
|
|
tick() {
|
|
let now = moment().utc();
|
|
|
|
this.setProperties({
|
|
second: now.seconds(),
|
|
minute: now.minutes(),
|
|
hour: now.hours()
|
|
});
|
|
|
|
if (config.environment !== 'test') {
|
|
run.later(() => {
|
|
this.tick();
|
|
}, ONE_SECOND);
|
|
}
|
|
}
|
|
}
|