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-16 14:43:44 +00:00
|
|
|
isOlderThan(TimeStampArg, compareTimeArg) {
|
|
|
|
if (this.milliSeconds < TimeStampArg.milliSeconds &&
|
|
|
|
(!compareTimeArg ||
|
|
|
|
(compareTimeArg && ((TimeStampArg.milliSeconds - this.milliSeconds) > compareTimeArg)))) {
|
2017-08-16 12:29:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-08-16 14:43:44 +00:00
|
|
|
isYoungerThan(TimeStampArg, compareTimeArg) {
|
|
|
|
if (this.milliSeconds > TimeStampArg.milliSeconds &&
|
|
|
|
(!compareTimeArg ||
|
|
|
|
(compareTimeArg && ((this.milliSeconds - TimeStampArg.milliSeconds) > compareTimeArg)))) {
|
2017-08-16 12:29:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.TimeStamp = TimeStamp;
|
2017-08-16 14:43:44 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7OztHQUdHO0FBQ0g7SUFzQkUsWUFBYSxVQUFtQjtRQUxoQzs7V0FFRztRQUNILFdBQU0sR0FBVyxJQUFJLENBQUE7UUFHbkIsRUFBRSxDQUFDLENBQUMsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQ2hCLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQTtRQUN4QixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sVUFBVSxLQUFLLFFBQVEsQ0FBQyxDQUFDLENBQUM7WUFDMUMsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUNsQyxDQUFDO1FBQ0QsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUMsSUFB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