59 lines
3.5 KiB
JavaScript
59 lines
3.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
/**
|
|
* TimeStamp
|
|
* smart timestamp
|
|
*/
|
|
class TimeStamp {
|
|
constructor(creatorArg) {
|
|
/**
|
|
* if derived from another TimeStamp points out the change in milliseconds
|
|
*/
|
|
this.change = null;
|
|
if (!creatorArg) {
|
|
this.date = new Date();
|
|
}
|
|
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;
|
|
}
|
|
/**
|
|
* Is the current instance older than the argument
|
|
* @param TimeStampArg
|
|
*/
|
|
isOlderThan(TimeStampArg, tresholdTimeArg = 0) {
|
|
if ((this.milliSeconds + tresholdTimeArg) < TimeStampArg.milliSeconds) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
isYoungerThan(TimeStampArg, tresholdTimeArg = 0) {
|
|
if (this.milliSeconds > (TimeStampArg.milliSeconds + tresholdTimeArg)) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
exports.TimeStamp = TimeStamp;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMv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