update static functions for more advanced TimeStamp generation
This commit is contained in:
parent
c19bafdad0
commit
8bc4de5eac
23
dist/smarttime.classes.timestamp.d.ts
vendored
23
dist/smarttime.classes.timestamp.d.ts
vendored
@ -8,11 +8,28 @@ export declare class TimeStamp {
|
|||||||
*/
|
*/
|
||||||
date: Date;
|
date: Date;
|
||||||
/**
|
/**
|
||||||
* The time as linux time
|
* The time as linux time (milliseconds, not seconds though)
|
||||||
* good for comparison
|
* good for comparison
|
||||||
*/
|
*/
|
||||||
linuxtime: number;
|
milliSeconds: number;
|
||||||
constructor(creatorArg?: number | TimeStamp);
|
/**
|
||||||
|
* The standard epoch time in seconds
|
||||||
|
*/
|
||||||
|
epochtime: number;
|
||||||
|
/**
|
||||||
|
* if derived from another TimeStamp points out the change in milliseconds
|
||||||
|
*/
|
||||||
|
change: number;
|
||||||
|
constructor(creatorArg?: number);
|
||||||
|
/**
|
||||||
|
* returns new TimeStamp from milliseconds
|
||||||
|
*/
|
||||||
|
static fromMilliSeconds(milliSecondsArg: any): TimeStamp;
|
||||||
|
/**
|
||||||
|
* returns new TimeStamp for now with change set
|
||||||
|
* @param timeStampArg
|
||||||
|
*/
|
||||||
|
static fromTimeStamp(timeStampArg: TimeStamp): TimeStamp;
|
||||||
/**
|
/**
|
||||||
* Is the current instance older than the argument
|
* Is the current instance older than the argument
|
||||||
* @param TimeStampArg
|
* @param TimeStampArg
|
||||||
|
31
dist/smarttime.classes.timestamp.js
vendored
31
dist/smarttime.classes.timestamp.js
vendored
@ -6,17 +6,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
*/
|
*/
|
||||||
class TimeStamp {
|
class TimeStamp {
|
||||||
constructor(creatorArg) {
|
constructor(creatorArg) {
|
||||||
|
/**
|
||||||
|
* if derived from another TimeStamp points out the change in milliseconds
|
||||||
|
*/
|
||||||
|
this.change = null;
|
||||||
if (!creatorArg) {
|
if (!creatorArg) {
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.linuxtime = this.date.getTime();
|
|
||||||
}
|
}
|
||||||
|
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
|
* Is the current instance older than the argument
|
||||||
* @param TimeStampArg
|
* @param TimeStampArg
|
||||||
*/
|
*/
|
||||||
isOlderThan(TimeStampArg) {
|
isOlderThan(TimeStampArg) {
|
||||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
if (this.milliSeconds < TimeStampArg.milliSeconds) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -24,7 +47,7 @@ class TimeStamp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
isYoungerThan(TimeStampArg) {
|
isYoungerThan(TimeStampArg) {
|
||||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
if (this.milliSeconds > TimeStampArg.milliSeconds) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -33,4 +56,4 @@ class TimeStamp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.TimeStamp = TimeStamp;
|
exports.TimeStamp = TimeStamp;
|
||||||
//# sourceMappingURL=data:application/json;base64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QVMsRUFBRSxDQUFBO1FBQ3BDLGNBQWMsQ0FBQyxNQUFNLEdBQUcsY0FBYyxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUMsWUFBWSxDQUFBO1FBQy9FLE1BQU0sQ0FBQyxjQUFjLENBQUE7SUFDdkIsQ0FBQztJQUVEOzs7T0FHRztJQUNILFdBQVcsQ0FBRSxZQUF1QjtRQUNsQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsWUFBWSxHQUFHLFlBQVksQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDO1lBQ2xELE1BQU0sQ0FBQyxJQUFJLENBQUE7UUFDYixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixNQUFNLENBQUMsS0FBSyxDQUFBO1FBQ2QsQ0FBQztJQUNILENBQUM7SUFFRCxhQUFhLENBQUUsWUFBdUI7UUFDcEMsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQztZQUNsRCxNQUFNLENBQUMsSUFBSSxDQUFBO1FBQ2IsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sTUFBTSxDQUFDLEtBQUssQ0FBQTtRQUNkLENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUFwRUQsOEJBb0VDIn0=
|
@ -11,15 +11,46 @@ export class TimeStamp {
|
|||||||
date: Date
|
date: Date
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time as linux time
|
* The time as linux time (milliseconds, not seconds though)
|
||||||
* good for comparison
|
* good for comparison
|
||||||
*/
|
*/
|
||||||
linuxtime: number
|
milliSeconds: number
|
||||||
constructor (creatorArg?: number | TimeStamp) {
|
|
||||||
|
/**
|
||||||
|
* The standard epoch time in seconds
|
||||||
|
*/
|
||||||
|
epochtime: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if derived from another TimeStamp points out the change in milliseconds
|
||||||
|
*/
|
||||||
|
change: number = null
|
||||||
|
|
||||||
|
constructor (creatorArg?: number) {
|
||||||
if (!creatorArg) {
|
if (!creatorArg) {
|
||||||
this.date = new Date()
|
this.date = new Date()
|
||||||
this.linuxtime = this.date.getTime()
|
} 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: TimeStamp) {
|
||||||
|
let localTimeStamp = new TimeStamp()
|
||||||
|
localTimeStamp.change = localTimeStamp.milliSeconds - timeStampArg.milliSeconds
|
||||||
|
return localTimeStamp
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +58,7 @@ export class TimeStamp {
|
|||||||
* @param TimeStampArg
|
* @param TimeStampArg
|
||||||
*/
|
*/
|
||||||
isOlderThan (TimeStampArg: TimeStamp) {
|
isOlderThan (TimeStampArg: TimeStamp) {
|
||||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
if (this.milliSeconds < TimeStampArg.milliSeconds) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
@ -35,7 +66,7 @@ export class TimeStamp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isYoungerThan (TimeStampArg: TimeStamp) {
|
isYoungerThan (TimeStampArg: TimeStamp) {
|
||||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
if (this.milliSeconds > TimeStampArg.milliSeconds) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user