add unit computation
This commit is contained in:
parent
37319fa278
commit
d9dd881e6e
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=
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnVuaXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLnVuaXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQVcsUUFBQSxLQUFLLEdBQUc7SUFDakIsS0FBSyxFQUFFLENBQUMsUUFBUSxHQUFHLENBQUM7UUFDbEIsTUFBTSxDQUFDLFFBQVEsR0FBRyxRQUFRLENBQUE7SUFDNUIsQ0FBQztJQUNELE1BQU0sRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDO1FBQ25CLE1BQU0sQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFBO0lBQzNCLENBQUM7SUFDRCxLQUFLLEVBQUUsQ0FBQyxRQUFRLEdBQUcsQ0FBQztRQUNsQixNQUFNLENBQUMsUUFBUSxHQUFHLE9BQU8sQ0FBQTtJQUMzQixDQUFDO0lBQ0QsSUFBSSxFQUFFLENBQUMsUUFBUSxHQUFHLENBQUM7UUFDakIsTUFBTSxDQUFDLFFBQVEsR0FBRyxNQUFNLENBQUE7SUFDMUIsQ0FBQztJQUNELEtBQUssRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDO1FBQ2xCLE1BQU0sQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFBO0lBQ3pCLENBQUM7SUFDRCxPQUFPLEVBQUUsQ0FBQyxRQUFRLEdBQUcsQ0FBQztRQUNwQixNQU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FDLGFBQUssQ0FBQyxLQUFLLENBQUMsY0FBYyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUE7SUFBQyxDQUFDO0lBQ2hGLEVBQUUsQ0FBQyxDQUFDLGNBQWMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO1FBQUMsZUFBZSxDQUFDLGFBQUssQ0FBQyxPQUFPLENBQUMsY0FBYyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUE7SUFBQyxDQUFDO0lBRXRGLE1BQU0sQ0FBQyxrQkFBa0IsQ0FBQTtBQUMzQixDQUFDLENBQUEifQ==
|
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'
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user