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) {
|
2018-03-11 15:44:32 +00:00
|
|
|
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) {
|
2018-03-11 15:44:32 +00:00
|
|
|
if (this.milliSeconds > TimeStampArg.milliSeconds + tresholdTimeArg) {
|
2017-08-16 12:29:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.TimeStamp = TimeStamp;
|
2018-03-11 15:44:32 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7OztHQUdHO0FBQ0g7SUF1Q0UsWUFBWSxVQUFtQjtRQUwvQjs7V0FFRztRQUNJLFdBQU0sR0FBVyxJQUFJLENBQUM7UUFHM0IsRUFBRSxDQUFDLENBQUMsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQ2hCLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQztRQUN6QixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sVUFBVSxLQUFLLFFBQVEsQ0FBQyxDQUFDLENBQUM7WUFDMUMsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQztRQUNuQyxDQUFDO1FBQ0QsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ3hDLElBQUksQ0FBQyxTQUFTLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0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