2017-08-16 12:29:12 +00:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
/**
|
|
|
|
* TimeStamp
|
|
|
|
* smart timestamp
|
|
|
|
*/
|
|
|
|
class TimeStamp {
|
|
|
|
constructor(creatorArg) {
|
2017-08-16 13:34:49 +00:00
|
|
|
/**
|
|
|
|
* if derived from another TimeStamp points out the change in milliseconds
|
|
|
|
*/
|
|
|
|
this.change = null;
|
2017-08-16 12:29:12 +00:00
|
|
|
if (!creatorArg) {
|
|
|
|
this.date = new Date();
|
|
|
|
}
|
2017-08-16 13:34:49 +00:00
|
|
|
else if (typeof creatorArg === 'number') {
|
|
|
|
this.date = new Date(creatorArg);
|
|
|
|
}
|
|
|
|
this.milliSeconds = this.date.getTime();
|
|
|
|
this.epochtime = Math.floor(this.milliSeconds / 1000);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* returns new TimeStamp from milliseconds
|
|
|
|
*/
|
|
|
|
static fromMilliSeconds(milliSecondsArg) {
|
|
|
|
return new TimeStamp(milliSecondsArg);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* returns new TimeStamp for now with change set
|
|
|
|
* @param timeStampArg
|
|
|
|
*/
|
|
|
|
static fromTimeStamp(timeStampArg) {
|
|
|
|
let localTimeStamp = new TimeStamp();
|
|
|
|
localTimeStamp.change = localTimeStamp.milliSeconds - timeStampArg.milliSeconds;
|
|
|
|
return localTimeStamp;
|
2017-08-16 12:29:12 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Is the current instance older than the argument
|
|
|
|
* @param TimeStampArg
|
|
|
|
*/
|
2017-08-19 15:59:54 +00:00
|
|
|
isOlderThan(TimeStampArg, tresholdTimeArg = 0) {
|
|
|
|
if ((this.milliSeconds + tresholdTimeArg) < TimeStampArg.milliSeconds) {
|
2017-08-16 12:29:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-08-19 15:59:54 +00:00
|
|
|
isYoungerThan(TimeStampArg, tresholdTimeArg = 0) {
|
|
|
|
if (this.milliSeconds > (TimeStampArg.milliSeconds + tresholdTimeArg)) {
|
2017-08-16 12:29:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.TimeStamp = TimeStamp;
|
2017-08-19 15:59:54 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7OztHQUdHO0FBQ0g7SUFzQkUsWUFBYSxVQUFtQjtRQUxoQzs7V0FFRztRQUNILFdBQU0sR0FBVyxJQUFJLENBQUE7UUFHbkIsRUFBRSxDQUFDLENBQUMsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQ2hCLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQTtRQUN4QixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sVUFBVSxLQUFLLFFBQVEsQ0FBQyxDQUFDLENBQUM7WUFDMUMsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUNsQyxDQUFDO1FBQ0QsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ3ZDLElBQUksQ0FBQyxTQUFTLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsWUFBWSxHQUFHLEl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