first implementation
This commit is contained in:
parent
e81188e756
commit
5a8214413c
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1 +1,2 @@
|
||||
export declare let standardExport: string;
|
||||
export * from './smarttime.classes.hrtmeasurement';
|
||||
export * from './smarttime.classes.timestamp';
|
||||
|
8
dist/index.js
vendored
8
dist/index.js
vendored
@ -1,4 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.standardExport = 'Hi there! :) This is a exported string';
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVXLFFBQUEsY0FBYyxHQUFHLHdDQUF3QyxDQUFBIn0=
|
||||
__export(require("./smarttime.classes.hrtmeasurement"));
|
||||
__export(require("./smarttime.classes.timestamp"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLHdEQUFrRDtBQUNsRCxtREFBNkMifQ==
|
22
dist/smarttime.classes.hrtmeasurement.d.ts
vendored
Normal file
22
dist/smarttime.classes.hrtmeasurement.d.ts
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* easy high resolution time measurement
|
||||
*/
|
||||
export declare class HrtMeasurement {
|
||||
nanoSeconds: number;
|
||||
milliSeconds: number;
|
||||
private _hrTimeStart;
|
||||
private _hrTimeStopDiff;
|
||||
private _started;
|
||||
/**
|
||||
* start the measurement
|
||||
*/
|
||||
start(): void;
|
||||
/**
|
||||
* stop the measurement
|
||||
*/
|
||||
stop(): this;
|
||||
/**
|
||||
* reset the measurement
|
||||
*/
|
||||
reset(): void;
|
||||
}
|
47
dist/smarttime.classes.hrtmeasurement.js
vendored
Normal file
47
dist/smarttime.classes.hrtmeasurement.js
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const process = require("process");
|
||||
/**
|
||||
* easy high resolution time measurement
|
||||
*/
|
||||
class HrtMeasurement {
|
||||
constructor() {
|
||||
this.nanoSeconds = null;
|
||||
this.milliSeconds = null;
|
||||
this._hrTimeStart = null;
|
||||
this._hrTimeStopDiff = null;
|
||||
this._started = 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;
|
||||
}
|
||||
}
|
||||
exports.HrtMeasurement = HrtMeasurement;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuaHJ0bWVhc3VyZW1lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy5ocnRtZWFzdXJlb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ksQ0FBQyxXQUFXLEdBQUcsSUFBSSxDQUFBO1FBQ3ZCLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQUFBO1FBQ3hCLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQUFBO1FBQ3hCLElBQUksQ0FBQyxlQUFlLEdBQUcsSUFBSSxDQUFBO1FBQzNCLElBQUksQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFBO0lBQ3ZCLENBQUM7Q0FDRjtBQXZDRCx3Q0F1Q0MifQ==
|
22
dist/smarttime.classes.timestamp.d.ts
vendored
Normal file
22
dist/smarttime.classes.timestamp.d.ts
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* TimeStamp
|
||||
* smart timestamp
|
||||
*/
|
||||
export declare class TimeStamp {
|
||||
/**
|
||||
* The standard JavaScript Date
|
||||
*/
|
||||
date: Date;
|
||||
/**
|
||||
* The time as linux time
|
||||
* good for comparison
|
||||
*/
|
||||
linuxtime: number;
|
||||
constructor(creatorArg?: number | TimeStamp);
|
||||
/**
|
||||
* Is the current instance older than the argument
|
||||
* @param TimeStampArg
|
||||
*/
|
||||
isOlderThan(TimeStampArg: TimeStamp): boolean;
|
||||
isYoungerThan(TimeStampArg: TimeStamp): boolean;
|
||||
}
|
36
dist/smarttime.classes.timestamp.js
vendored
Normal file
36
dist/smarttime.classes.timestamp.js
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* TimeStamp
|
||||
* smart timestamp
|
||||
*/
|
||||
class TimeStamp {
|
||||
constructor(creatorArg) {
|
||||
if (!creatorArg) {
|
||||
this.date = new Date();
|
||||
this.linuxtime = this.date.getTime();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Is the current instance older than the argument
|
||||
* @param TimeStampArg
|
||||
*/
|
||||
isOlderThan(TimeStampArg) {
|
||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
isYoungerThan(TimeStampArg) {
|
||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.TimeStamp = TimeStamp;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7OztHQUdHO0FBQ0g7SUFXRSxZQUFhLFVBQStCO1FBQzFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQztZQUNoQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksSUFBSSxFQUFFLENBQUE7WUFDdEIsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ3RDLENBQUM7SUFDSCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsV0FBVyxDQUFFLFlBQXVCO1FBQ2xDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxTQUFTLEdBQUcsWUFBWSxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUM7WUFDNUMsTUFBTSxDQUFDLElBQUksQ0FBQTtRQUNiLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE1BQU0sQ0FBQyxLQUFLLENBQUE7UUFDZCxDQUFDO0lBQ0gsQ0FBQztJQUVELGFBQWEsQ0FBRSxZQUF1QjtRQUNwQyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxHQUFHLFlBQVksQ0FBQyxTQUFTLENBQUMsQ0FBQyxDQUFDO1lBQzVDLE1BQU0sQ0FBQyxJQUFJLENBQUE7UUFDYixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixNQUFNLENBQUMsS0FBSyxDQUFBO1FBQ2QsQ0FBQztJQUNILENBQUM7Q0FDRjtBQXJDRCw4QkFxQ0MifQ==
|
31
test/test.ts
31
test/test.ts
@ -1,8 +1,35 @@
|
||||
import { expect, tap } from 'tapbundle'
|
||||
import * as smarttime from '../ts/index'
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(smarttime.standardExport)
|
||||
|
||||
// Test TimeStamp class
|
||||
let testTimeStamp: smarttime.TimeStamp
|
||||
let testTimeStamp2: smarttime.TimeStamp
|
||||
tap.test('should create valid testTimeStamp instance', async (tools) => {
|
||||
testTimeStamp = new smarttime.TimeStamp()
|
||||
await tools.delayFor(2)
|
||||
testTimeStamp2 = new smarttime.TimeStamp()
|
||||
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp)
|
||||
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp)
|
||||
})
|
||||
|
||||
tap.test('should have valid linuxtime', async () => {
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testTimeStamp.isOlderThan(testTimeStamp2)).to.be.true
|
||||
expect(testTimeStamp.isYoungerThan(testTimeStamp2)).to.be.false
|
||||
})
|
||||
|
||||
let testHrtMeasurement: smarttime.HrtMeasurement
|
||||
|
||||
// Test HrtMeasurement
|
||||
tap.test('should create valid HrtMeasurements', async (tools) => {
|
||||
testHrtMeasurement = new smarttime.HrtMeasurement()
|
||||
testHrtMeasurement.start()
|
||||
await tools.delayFor(20)
|
||||
testHrtMeasurement.stop()
|
||||
expect(testHrtMeasurement.milliSeconds).to.be.greaterThan(19)
|
||||
expect(testHrtMeasurement.milliSeconds).to.be.lessThan(25)
|
||||
})
|
||||
|
||||
|
||||
tap.start()
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user