Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
7825085db4 | |||
0d34554fab | |||
73b1002451 | |||
824e055cbd | |||
633ec0606b | |||
d9dd881e6e | |||
37319fa278 | |||
8bc4de5eac |
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1,2 +1,3 @@
|
|||||||
export * from './smarttime.classes.hrtmeasurement';
|
export * from './smarttime.classes.hrtmeasurement';
|
||||||
export * from './smarttime.classes.timestamp';
|
export * from './smarttime.classes.timestamp';
|
||||||
|
export * from './smarttime.units';
|
||||||
|
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -5,4 +5,5 @@ function __export(m) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
__export(require("./smarttime.classes.hrtmeasurement"));
|
__export(require("./smarttime.classes.hrtmeasurement"));
|
||||||
__export(require("./smarttime.classes.timestamp"));
|
__export(require("./smarttime.classes.timestamp"));
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLHdEQUFrRDtBQUNsRCxtREFBNkMifQ==
|
__export(require("./smarttime.units"));
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLHdEQUFrRDtBQUNsRCxtREFBNkM7QUFDN0MsdUNBQWlDIn0=
|
27
dist/smarttime.classes.timestamp.d.ts
vendored
27
dist/smarttime.classes.timestamp.d.ts
vendored
@ -8,15 +8,32 @@ 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
|
||||||
*/
|
*/
|
||||||
isOlderThan(TimeStampArg: TimeStamp): boolean;
|
isOlderThan(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
||||||
isYoungerThan(TimeStampArg: TimeStamp): boolean;
|
isYoungerThan(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
||||||
}
|
}
|
||||||
|
35
dist/smarttime.classes.timestamp.js
vendored
35
dist/smarttime.classes.timestamp.js
vendored
@ -6,25 +6,48 @@ 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, tresholdTimeArg = 0) {
|
||||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
if ((this.milliSeconds + tresholdTimeArg) < TimeStampArg.milliSeconds) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isYoungerThan(TimeStampArg) {
|
isYoungerThan(TimeStampArg, tresholdTimeArg = 0) {
|
||||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
if (this.milliSeconds > (TimeStampArg.milliSeconds + tresholdTimeArg)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -33,4 +56,4 @@ class TimeStamp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.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GFBQWEsQ0FBRSxZQUF1QjtRQUMzQyxJQUFJLGNBQWMsR0FBRyxJQUFJLFNBQVMsRUFBRSxDQUFBO1FBQ3BDLGNBQWMsQ0FBQyxNQUFNLEdBQUcsY0FBYyxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUMsWUFBWSxDQUFBO1FBQy9FLE1BQU0sQ0FBQyxjQUFjLENBQUE7SUFDdkIsQ0FBQztJQUVEOzs7T0FHRztJQUNILFdBQVcsQ0FBRSxZQUF1QixFQUFFLGtCQUEwQixDQUFDO1FBQy9ELEVBQUUsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLFlBQVksR0FBRyxlQUFlLENBQUMsR0FBRyxZQUFZLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQztZQUN0RSxNQUFNLENBQUMsSUFBSSxDQUFBO1FBQ2IsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sTUFBTSxDQUFDLEtBQUssQ0FBQTtRQUNkLENBQUM7SUFDSCxDQUFDO0lBRUQsYUFBYSxDQUFFLFlBQXVCLEVBQUUsa0JBQTBCLENBQUM7UUFDakUsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFlBQVksR0FBRyxDQUFDLFlBQVksQ0FBQyxZQUFZLEdBQUcsZUFBZSxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBQ3RFLE1BQU0sQ0FBQyxJQUFJLENBQUE7UUFDYixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixNQUFNLENBQUMsS0FBSyxDQUFBO1FBQ2QsQ0FBQztJQUNILENBQUM7Q0FDRjtBQXBFRCw4QkFvRUMifQ==
|
17
dist/smarttime.units.d.ts
vendored
Normal file
17
dist/smarttime.units.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export declare let units: {
|
||||||
|
years: (timesArg?: number) => number;
|
||||||
|
months: (timesArg?: number) => number;
|
||||||
|
weeks: (timesArg?: number) => number;
|
||||||
|
days: (timesArg?: number) => number;
|
||||||
|
hours: (timesArg?: number) => number;
|
||||||
|
minutes: (timesArg?: number) => number;
|
||||||
|
};
|
||||||
|
export interface IUnitCombinationArg {
|
||||||
|
years?: number;
|
||||||
|
months?: number;
|
||||||
|
weeks?: number;
|
||||||
|
days?: number;
|
||||||
|
hours?: number;
|
||||||
|
minutes?: number;
|
||||||
|
}
|
||||||
|
export declare let getMilliSecondsFromUnits: (combinationArg: IUnitCombinationArg) => number;
|
48
dist/smarttime.units.js
vendored
Normal file
48
dist/smarttime.units.js
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.units = {
|
||||||
|
years: (timesArg = 1) => {
|
||||||
|
return timesArg * 3154e+10;
|
||||||
|
},
|
||||||
|
months: (timesArg = 1) => {
|
||||||
|
return timesArg * 2628e+9;
|
||||||
|
},
|
||||||
|
weeks: (timesArg = 1) => {
|
||||||
|
return timesArg * 6048e+8;
|
||||||
|
},
|
||||||
|
days: (timesArg = 1) => {
|
||||||
|
return timesArg * 864e+7;
|
||||||
|
},
|
||||||
|
hours: (timesArg = 1) => {
|
||||||
|
return timesArg * 36e+6;
|
||||||
|
},
|
||||||
|
minutes: (timesArg = 1) => {
|
||||||
|
return timesArg * 60000;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
exports.getMilliSecondsFromUnits = (combinationArg) => {
|
||||||
|
let timeInMilliseconds = 0;
|
||||||
|
let addMilliSeconds = (milliSecondsArg) => {
|
||||||
|
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
||||||
|
};
|
||||||
|
if (combinationArg.years) {
|
||||||
|
addMilliSeconds(exports.units.years(combinationArg.years));
|
||||||
|
}
|
||||||
|
if (combinationArg.months) {
|
||||||
|
addMilliSeconds(exports.units.months(combinationArg.months));
|
||||||
|
}
|
||||||
|
if (combinationArg.weeks) {
|
||||||
|
addMilliSeconds(exports.units.weeks(combinationArg.weeks));
|
||||||
|
}
|
||||||
|
if (combinationArg.days) {
|
||||||
|
addMilliSeconds(exports.units.days(combinationArg.days));
|
||||||
|
}
|
||||||
|
if (combinationArg.hours) {
|
||||||
|
addMilliSeconds(exports.units.hours(combinationArg.hours));
|
||||||
|
}
|
||||||
|
if (combinationArg.minutes) {
|
||||||
|
addMilliSeconds(exports.units.minutes(combinationArg.minutes));
|
||||||
|
}
|
||||||
|
return timeInMilliseconds;
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnVuaXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLnVuaXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQVcsUUFBQSxLQUFLLEdBQUc7SUFDakIsS0FBSyxFQUFFLENBQUMsUUFBUSxHQUFHLENBQUM7UUFDbEIsTUFBTSxDQUFDLFFBQVEsR0FBRyxRQUFRLENBQUE7SUFDNUIsQ0FBQztJQUNELE1BQU0sRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDO1FBQ25CLE1BQU0sQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFBO0lBQzNCLENBQUM7SUFDRCxLQUFLLEVBQUUsQ0FBQyxRQUFRLEdBQUcsQ0FBQztRQUNsQixNQUFNLENBQUMsUUFBUSxHQUFHLE9BQU8sQ0FBQTtJQUMzQixDQUFDO0lBQ0QsSUFBSSxFQUFFLENBQUMsUUFBUSxHQUFHLENBQUM7UUFDakIsTUFBTSxDQUFDLFFBQVEsR0FBRyxNQUFNLENBQUE7SUFDMUIsQ0FBQztJQUNELEtBQUssRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDO1FBQ2xCLE1BQU0sQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFBO0lBQ3pCLENBQUM7SUFDRCxPQUFPLEVBQUUsQ0FBQyxRQUFRLEdBQUc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O1FBQUMsZUFBZSxDQUFDLGFBQUssQ0FBQyxLQUFLLENBQUMsY0FBYyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUE7SUFBQyxDQUFDO0lBQ2hGLEVBQUUsQ0FBQyxDQUFDLGNBQWMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO1FBQUMsZUFBZSxDQUFDLGFBQUssQ0FBQyxPQUFPLENBQUMsY0FBYyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUE7SUFBQyxDQUFDO0lBRXRGLE1BQU0sQ0FBQyxrQkFBa0IsQ0FBQTtBQUMzQixDQUFDLENBQUEifQ==
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smarttime",
|
"name": "smarttime",
|
||||||
"version": "1.0.3",
|
"version": "1.0.7",
|
||||||
"description": "handle timeformats in smart ways",
|
"description": "handle timeformats in smart ways",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
12
test/test.ts
12
test/test.ts
@ -32,5 +32,17 @@ tap.test('should create valid HrtMeasurements', async (tools) => {
|
|||||||
expect(testHrtMeasurement.milliSeconds).to.be.lessThan(25)
|
expect(testHrtMeasurement.milliSeconds).to.be.lessThan(25)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// check units
|
||||||
|
tap.test('should combine units', async () => {
|
||||||
|
let computedTime = smarttime.getMilliSecondsFromUnits({
|
||||||
|
years: 2,
|
||||||
|
months: 2,
|
||||||
|
weeks: 2,
|
||||||
|
days: 2,
|
||||||
|
hours: 2,
|
||||||
|
minutes: 2
|
||||||
|
})
|
||||||
|
console.log(computedTime)
|
||||||
|
})
|
||||||
|
|
||||||
tap.start()
|
tap.start()
|
||||||
|
@ -2,3 +2,4 @@ import * as plugins from './smarttime.plugins'
|
|||||||
|
|
||||||
export * from './smarttime.classes.hrtmeasurement'
|
export * from './smarttime.classes.hrtmeasurement'
|
||||||
export * from './smarttime.classes.timestamp'
|
export * from './smarttime.classes.timestamp'
|
||||||
|
export * from './smarttime.units'
|
||||||
|
@ -11,31 +11,62 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the current instance older than the argument
|
* Is the current instance older than the argument
|
||||||
* @param TimeStampArg
|
* @param TimeStampArg
|
||||||
*/
|
*/
|
||||||
isOlderThan (TimeStampArg: TimeStamp) {
|
isOlderThan (TimeStampArg: TimeStamp, tresholdTimeArg: number = 0) {
|
||||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
if ((this.milliSeconds + tresholdTimeArg) < TimeStampArg.milliSeconds) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isYoungerThan (TimeStampArg: TimeStamp) {
|
isYoungerThan (TimeStampArg: TimeStamp, tresholdTimeArg: number = 0) {
|
||||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
if (this.milliSeconds > (TimeStampArg.milliSeconds + tresholdTimeArg)) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
45
ts/smarttime.units.ts
Normal file
45
ts/smarttime.units.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
export let units = {
|
||||||
|
years: (timesArg = 1): number => {
|
||||||
|
return timesArg * 3154e+10
|
||||||
|
},
|
||||||
|
months: (timesArg = 1): number => {
|
||||||
|
return timesArg * 2628e+9
|
||||||
|
},
|
||||||
|
weeks: (timesArg = 1) => {
|
||||||
|
return timesArg * 6048e+8
|
||||||
|
},
|
||||||
|
days: (timesArg = 1) => {
|
||||||
|
return timesArg * 864e+7
|
||||||
|
},
|
||||||
|
hours: (timesArg = 1) => {
|
||||||
|
return timesArg * 36e+6
|
||||||
|
},
|
||||||
|
minutes: (timesArg = 1) => {
|
||||||
|
return timesArg * 60000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IUnitCombinationArg {
|
||||||
|
years?: number
|
||||||
|
months?: number
|
||||||
|
weeks?: number
|
||||||
|
days?: number
|
||||||
|
hours?: number
|
||||||
|
minutes?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
||||||
|
let timeInMilliseconds = 0
|
||||||
|
let addMilliSeconds = (milliSecondsArg) => {
|
||||||
|
timeInMilliseconds = timeInMilliseconds + milliSecondsArg
|
||||||
|
}
|
||||||
|
if (combinationArg.years) { addMilliSeconds(units.years(combinationArg.years)) }
|
||||||
|
if (combinationArg.months) { addMilliSeconds(units.months(combinationArg.months)) }
|
||||||
|
if (combinationArg.weeks) { addMilliSeconds(units.weeks(combinationArg.weeks)) }
|
||||||
|
if (combinationArg.days) { addMilliSeconds(units.days(combinationArg.days)) }
|
||||||
|
if (combinationArg.hours) { addMilliSeconds(units.hours(combinationArg.hours)) }
|
||||||
|
if (combinationArg.minutes) { addMilliSeconds(units.minutes(combinationArg.minutes)) }
|
||||||
|
|
||||||
|
return timeInMilliseconds
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user