verstak
Version:
Verstak - Front-End Library
43 lines (42 loc) • 1.71 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { RxObject, transaction } from "reactronic";
export class LiveTime extends RxObject {
constructor(interval = 1000) {
super();
this.hour = 0;
this.minute = 0;
this.second = 0;
this.ms = 0;
this.interval = 0;
this.interval = interval;
this.tick();
}
tick() {
let calibration = 0;
try {
const now = new Date();
this.hour = now.getHours();
this.minute = now.getMinutes();
this.second = now.getSeconds();
this.ms = now.getMilliseconds();
calibration = now.getTime() % this.interval;
}
finally {
setTimeout(() => this.tick(), this.interval - calibration);
}
}
}
__decorate([
transaction,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], LiveTime.prototype, "tick", null);