add better younger comperator for millisenconds
This commit is contained in:
parent
526771d1df
commit
4c87caedfe
3
dist/smarttime.classes.timestamp.d.ts
vendored
3
dist/smarttime.classes.timestamp.d.ts
vendored
@ -35,5 +35,6 @@ export declare class TimeStamp {
|
||||
* @param TimeStampArg
|
||||
*/
|
||||
isOlderThan(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
||||
isYoungerThan(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
||||
isYoungerThanOtherTimeStamp(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
||||
isYoungerThanMilliSeconds(millisecondArg: number): boolean;
|
||||
}
|
||||
|
12
dist/smarttime.classes.timestamp.js
vendored
12
dist/smarttime.classes.timestamp.js
vendored
@ -30,7 +30,7 @@ class TimeStamp {
|
||||
* @param timeStampArg
|
||||
*/
|
||||
static fromTimeStamp(timeStampArg) {
|
||||
let localTimeStamp = new TimeStamp();
|
||||
const localTimeStamp = new TimeStamp();
|
||||
localTimeStamp.change = localTimeStamp.milliSeconds - timeStampArg.milliSeconds;
|
||||
return localTimeStamp;
|
||||
}
|
||||
@ -46,7 +46,7 @@ class TimeStamp {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
isYoungerThan(TimeStampArg, tresholdTimeArg = 0) {
|
||||
isYoungerThanOtherTimeStamp(TimeStampArg, tresholdTimeArg = 0) {
|
||||
if (this.milliSeconds > TimeStampArg.milliSeconds + tresholdTimeArg) {
|
||||
return true;
|
||||
}
|
||||
@ -54,6 +54,12 @@ class TimeStamp {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
isYoungerThanMilliSeconds(millisecondArg) {
|
||||
const nowTimeStamp = new TimeStamp();
|
||||
const compareEpochTime = nowTimeStamp.epochtime - millisecondArg;
|
||||
const compareTimeStamp = new TimeStamp(compareEpochTime);
|
||||
return this.isYoungerThanOtherTimeStamp(compareTimeStamp);
|
||||
}
|
||||
}
|
||||
exports.TimeStamp = TimeStamp;
|
||||
//# sourceMapping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UMsSUFBSSxDQUFDLFlBQVksR0FBRyxlQUFlLEdBQUcsWUFBWSxDQUFDLFlBQVksQ0FBQyxDQUFDLENBQUM7WUFDcEUsTUFBTSxDQUFDLElBQUksQ0FBQztRQUNkLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE1BQU0sQ0FBQyxLQUFLLENBQUM7UUFDZixDQUFDO0lBQ0gsQ0FBQztJQUVNLDJCQUEyQixDQUFDLFlBQXVCLEVBQUUsa0JBQTBCLENBQUM7UUFDckYsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUMsWUFBWSxHQUFHLGVBQWUsQ0FBQyxDQUFDLENBQUM7WUFDcEUsTUFBTSxDQUFDLElBQUksQ0FBQztRQUNkLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE1BQU0sQ0FBQyxLQUFLLENBQUM7UUFDZixDQUFDO0lBQ0gsQ0FBQztJQUVNLHlCQUF5QixDQUFDLGNBQXNCO1FBQ3JELE1BQU0sWUFBWSxHQUFHLElBQUksU0FBUyxFQUFFLENBQUE7UUFDcEMsTUFBTSxnQkFBZ0IsR0FBRyxZQUFZLENBQUMsU0FBUyxHQUFHLGNBQWMsQ0FBQztRQUNqRSxNQUFNLGdCQUFnQixHQUFHLElBQUksU0FBUyxDQUFDLGdCQUFnQixDQUFDLENBQUM7UUFDekQsTUFBTSxDQUFDLElBQUksQ0FBQywyQkFBMkIsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO0lBQzVELENBQUM7Q0FDRjtBQTNFRCw4QkEyRUMifQ==
|
@ -1,3 +1,4 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { expect, tap } from 'tapbundle';
|
||||
import * as smarttime from '../ts/index';
|
||||
|
||||
@ -16,7 +17,7 @@ tap.test('should have valid linuxtime', async () => {
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testTimeStamp.isOlderThan(testTimeStamp2)).to.be.true;
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testTimeStamp.isYoungerThan(testTimeStamp2)).to.be.false;
|
||||
expect(testTimeStamp.isYoungerThanOtherTimeStamp(testTimeStamp2)).to.be.false;
|
||||
});
|
||||
|
||||
let testHrtMeasurement: smarttime.HrtMeasurement;
|
||||
@ -33,8 +34,9 @@ tap.test('should create valid HrtMeasurements', async tools => {
|
||||
|
||||
// check units
|
||||
tap.test('should combine units', async () => {
|
||||
let computedTime = smarttime.getMilliSecondsFromUnits({
|
||||
const computedTime = smarttime.getMilliSecondsFromUnits({
|
||||
years: 2,
|
||||
// tslint:disable-next-line:object-literal-sort-keys
|
||||
months: 2,
|
||||
weeks: 2,
|
||||
days: 2,
|
||||
|
@ -65,11 +65,18 @@ export class TimeStamp {
|
||||
}
|
||||
}
|
||||
|
||||
public isYoungerThan(TimeStampArg: TimeStamp, tresholdTimeArg: number = 0) {
|
||||
public isYoungerThanOtherTimeStamp(TimeStampArg: TimeStamp, tresholdTimeArg: number = 0) {
|
||||
if (this.milliSeconds > TimeStampArg.milliSeconds + tresholdTimeArg) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public isYoungerThanMilliSeconds(millisecondArg: number) {
|
||||
const nowTimeStamp = new TimeStamp()
|
||||
const compareEpochTime = nowTimeStamp.epochtime - millisecondArg;
|
||||
const compareTimeStamp = new TimeStamp(compareEpochTime);
|
||||
return this.isYoungerThanOtherTimeStamp(compareTimeStamp);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user