first implementation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import * as plugins from './smarttime.plugins'
|
||||
|
||||
export let standardExport = 'Hi there! :) This is a exported string'
|
||||
export * from './smarttime.classes.hrtmeasurement'
|
||||
export * from './smarttime.classes.timestamp'
|
||||
|
45
ts/smarttime.classes.hrtmeasurement.ts
Normal file
45
ts/smarttime.classes.hrtmeasurement.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import * as process from 'process'
|
||||
|
||||
/**
|
||||
* easy high resolution time measurement
|
||||
*/
|
||||
export class HrtMeasurement {
|
||||
nanoSeconds: number = null
|
||||
milliSeconds: number = null
|
||||
private _hrTimeStart = null
|
||||
private _hrTimeStopDiff = null
|
||||
private _started: boolean = false
|
||||
|
||||
/**
|
||||
* start the measurement
|
||||
*/
|
||||
start () {
|
||||
this._started = true
|
||||
this._hrTimeStart = process.hrtime()
|
||||
}
|
||||
|
||||
/**
|
||||
* stop the measurement
|
||||
*/
|
||||
stop () {
|
||||
if (this._started === false) {
|
||||
console.log('Hasn\'t started yet')
|
||||
return
|
||||
}
|
||||
this._hrTimeStopDiff = process.hrtime(this._hrTimeStart)
|
||||
this.nanoSeconds = (this._hrTimeStopDiff[0] * 1e9) + this._hrTimeStopDiff[1]
|
||||
this.milliSeconds = this.nanoSeconds / 1000000
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* reset the measurement
|
||||
*/
|
||||
reset () {
|
||||
this.nanoSeconds = null
|
||||
this.milliSeconds = null
|
||||
this._hrTimeStart = null
|
||||
this._hrTimeStopDiff = null
|
||||
this._started = false
|
||||
}
|
||||
}
|
44
ts/smarttime.classes.timestamp.ts
Normal file
44
ts/smarttime.classes.timestamp.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import * as plugins from './smarttime.plugins'
|
||||
|
||||
/**
|
||||
* TimeStamp
|
||||
* smart timestamp
|
||||
*/
|
||||
export class TimeStamp {
|
||||
/**
|
||||
* The standard JavaScript Date
|
||||
*/
|
||||
date: Date
|
||||
|
||||
/**
|
||||
* The time as linux time
|
||||
* good for comparison
|
||||
*/
|
||||
linuxtime: number
|
||||
constructor (creatorArg?: number | TimeStamp) {
|
||||
if (!creatorArg) {
|
||||
this.date = new Date()
|
||||
this.linuxtime = this.date.getTime()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current instance older than the argument
|
||||
* @param TimeStampArg
|
||||
*/
|
||||
isOlderThan (TimeStampArg: TimeStamp) {
|
||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
isYoungerThan (TimeStampArg: TimeStamp) {
|
||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user