update static functions for more advanced TimeStamp generation
This commit is contained in:
@ -11,15 +11,46 @@ export class TimeStamp {
|
||||
date: Date
|
||||
|
||||
/**
|
||||
* The time as linux time
|
||||
* The time as linux time (milliseconds, not seconds though)
|
||||
* good for comparison
|
||||
*/
|
||||
linuxtime: number
|
||||
constructor (creatorArg?: number | TimeStamp) {
|
||||
milliSeconds: number
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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
|
||||
*/
|
||||
isOlderThan (TimeStampArg: TimeStamp) {
|
||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
||||
if (this.milliSeconds < TimeStampArg.milliSeconds) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@ -35,7 +66,7 @@ export class TimeStamp {
|
||||
}
|
||||
|
||||
isYoungerThan (TimeStampArg: TimeStamp) {
|
||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
||||
if (this.milliSeconds > TimeStampArg.milliSeconds) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
|
Reference in New Issue
Block a user