Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
633ec0606b | |||
d9dd881e6e | |||
37319fa278 | |||
8bc4de5eac | |||
c19bafdad0 | |||
f157711d83 |
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.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 });
|
||||
__export(require("./smarttime.classes.hrtmeasurement"));
|
||||
__export(require("./smarttime.classes.timestamp"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLHdEQUFrRDtBQUNsRCxtREFBNkMifQ==
|
||||
__export(require("./smarttime.units"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLHdEQUFrRDtBQUNsRCxtREFBNkM7QUFDN0MsdUNBQWlDIn0=
|
23
dist/smarttime.classes.timestamp.d.ts
vendored
23
dist/smarttime.classes.timestamp.d.ts
vendored
@ -8,11 +8,28 @@ export declare class TimeStamp {
|
||||
*/
|
||||
date: Date;
|
||||
/**
|
||||
* The time as linux time
|
||||
* The time as linux time (milliseconds, not seconds though)
|
||||
* good for comparison
|
||||
*/
|
||||
linuxtime: number;
|
||||
constructor(creatorArg?: number | TimeStamp);
|
||||
milliSeconds: number;
|
||||
/**
|
||||
* 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
|
||||
* @param TimeStampArg
|
||||
|
31
dist/smarttime.classes.timestamp.js
vendored
31
dist/smarttime.classes.timestamp.js
vendored
@ -6,17 +6,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
*/
|
||||
class TimeStamp {
|
||||
constructor(creatorArg) {
|
||||
/**
|
||||
* if derived from another TimeStamp points out the change in milliseconds
|
||||
*/
|
||||
this.change = null;
|
||||
if (!creatorArg) {
|
||||
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
|
||||
* @param TimeStampArg
|
||||
*/
|
||||
isOlderThan(TimeStampArg) {
|
||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
||||
if (this.milliSeconds < TimeStampArg.milliSeconds) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@ -24,7 +47,7 @@ class TimeStamp {
|
||||
}
|
||||
}
|
||||
isYoungerThan(TimeStampArg) {
|
||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
||||
if (this.milliSeconds > TimeStampArg.milliSeconds) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@ -33,4 +56,4 @@ class TimeStamp {
|
||||
}
|
||||
}
|
||||
exports.TimeStamp = TimeStamp;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7OztHQUdHO0FBQ0g7SUFXRSxZQUFhLFVBQStCO1FBQzFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQztZQUNoQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksSUFBSSxFQUFFLENBQUE7WUFDdEIsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ3RDLENBQUM7SUFDSCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsV0FBVyxDQUFFLFlBQXVCO1FBQ2xDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxTQUFTLEdBQUcsWUFBWSxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUM7WUFDNUMsTUFBTSxDQUFDLElBQUksQ0FBQTtRQUNiLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE1BQU0sQ0FBQyxLQUFLLENBQUE7UUFDZCxDQUFDO0lBQ0gsQ0FBQztJQUV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al 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnVuaXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLnVuaXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQVcsUUFBQSxLQUFLLEdBQUc7SUFDakIsS0FBSyxFQUFFLENBQUMsUUFBUSxHQUFHLENBQUM7UUFDbEIsTUFBTSxDQUFDLFFBQVEsR0FBRyxRQUFRLENBQUE7SUFDNUIsQ0FBQztJQUNELE1BQU0sRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDO1FBQ25CLE1BQU0sQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFBO0lBQzNCLENBQUM7SUFDRCxLQUFLLEVBQUUsQ0FBQyxRQUFRLEdBQUcsQ0FBQztRQUNsQixNQUFNLENBQUMsUUFBUSxHQUFHLE9BQU8sQ0FBQTtJQUMzQixDQUFDO0lBQ0QsSUFBSSxFQUFFLENBQUMsUUFBUSxHQUFHLENBQUM7UUFDakIsTUFBTSxDQUFDLFFBQVEsR0FBRyxNQUFNLENBQUE7SUFDMUIsQ0FBQztJQUNELEtBQUssRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDO1FBQ2xCLE1BQU0sQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFBO0lBQ3pCLENBQUM7SUFDRCxPQUFPLEVBQUUsQ0FBQyxRQUFRLEdBQUcsQ0FBQztRQUNwQixNQUFNLENBQUMsUUFBUSxHQUFHLEtBQUssQ0FBQTt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DQUFDLEtBQUssQ0FBQyxDQUFDLENBQUE7SUFBQyxDQUFDO0lBQ2hGLEVBQUUsQ0FBQyxDQUFDLGNBQWMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO1FBQUMsZUFBZSxDQUFDLGFBQUssQ0FBQyxPQUFPLENBQUMsY0FBYyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUE7SUFBQyxDQUFDO0lBRXRGLE1BQU0sQ0FBQyxrQkFBa0IsQ0FBQTtBQUMzQixDQUFDLENBQUEifQ==
|
29
docs/index.md
Normal file
29
docs/index.md
Normal file
@ -0,0 +1,29 @@
|
||||
# smarttime
|
||||
handle timeformats in smart ways
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smarttime)
|
||||
[](https://GitLab.com/pushrocks/smarttime)
|
||||
[](https://github.com/pushrocks/smarttime)
|
||||
[](https://pushrocks.gitlab.io/smarttime/)
|
||||
|
||||
## Status for master
|
||||
[](https://GitLab.com/pushrocks/smarttime/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smarttime/commits/master)
|
||||
[](https://www.npmjs.com/package/smarttime)
|
||||
[](https://david-dm.org/pushrocks/smarttime)
|
||||
[](https://www.bithound.io/github/pushrocks/smarttime/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smarttime)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "smarttime",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.5",
|
||||
"description": "handle timeformats in smart ways",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
|
29
readme.md
Normal file
29
readme.md
Normal file
@ -0,0 +1,29 @@
|
||||
# smarttime
|
||||
handle timeformats in smart ways
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smarttime)
|
||||
[](https://GitLab.com/pushrocks/smarttime)
|
||||
[](https://github.com/pushrocks/smarttime)
|
||||
[](https://pushrocks.gitlab.io/smarttime/)
|
||||
|
||||
## Status for master
|
||||
[](https://GitLab.com/pushrocks/smarttime/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smarttime/commits/master)
|
||||
[](https://www.npmjs.com/package/smarttime)
|
||||
[](https://david-dm.org/pushrocks/smarttime)
|
||||
[](https://www.bithound.io/github/pushrocks/smarttime/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smarttime)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
13
test/test.ts
13
test/test.ts
@ -16,6 +16,7 @@ tap.test('should create valid testTimeStamp instance', async (tools) => {
|
||||
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
|
||||
})
|
||||
|
||||
@ -31,5 +32,17 @@ tap.test('should create valid HrtMeasurements', async (tools) => {
|
||||
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()
|
||||
|
@ -2,3 +2,4 @@ import * as plugins from './smarttime.plugins'
|
||||
|
||||
export * from './smarttime.classes.hrtmeasurement'
|
||||
export * from './smarttime.classes.timestamp'
|
||||
export * from './smarttime.units'
|
||||
|
@ -11,15 +11,46 @@ export class TimeStamp {
|
||||
date: Date
|
||||
|
||||
/**
|
||||
* The time as linux time
|
||||
* The time as linux time (milliseconds, not seconds though)
|
||||
* good for comparison
|
||||
*/
|
||||
linuxtime: number
|
||||
constructor (creatorArg?: number | TimeStamp) {
|
||||
milliSeconds: number
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,7 +58,7 @@ export class TimeStamp {
|
||||
* @param TimeStampArg
|
||||
*/
|
||||
isOlderThan (TimeStampArg: TimeStamp) {
|
||||
if (this.linuxtime < TimeStampArg.linuxtime) {
|
||||
if (this.milliSeconds < TimeStampArg.milliSeconds) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@ -35,7 +66,7 @@ export class TimeStamp {
|
||||
}
|
||||
|
||||
isYoungerThan (TimeStampArg: TimeStamp) {
|
||||
if (this.linuxtime > TimeStampArg.linuxtime) {
|
||||
if (this.milliSeconds > TimeStampArg.milliSeconds) {
|
||||
return true
|
||||
} else {
|
||||
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