Compare commits

..

10 Commits

Author SHA1 Message Date
d3dd03534a 3.0.46 2022-11-21 01:19:39 +01:00
9b96779d19 fix(core): update 2022-11-21 01:19:38 +01:00
20b181b2f3 3.0.45 2022-02-02 17:03:59 +01:00
d278722da2 fix(core): update 2022-02-02 17:03:58 +01:00
e3daf08d67 3.0.44 2022-02-02 16:55:13 +01:00
0483b55a9e fix(core): update 2022-02-02 16:55:12 +01:00
c3a772c155 3.0.43 2021-11-08 16:56:11 +01:00
a2ffdd436f fix(timestamp): add missing .isOlderThanOtherTimeStamp() to TimeStamp class 2021-11-08 16:56:11 +01:00
da9c71eedb 3.0.42 2021-11-08 16:52:14 +01:00
63405fc577 fix(readme): fix readme 2021-11-08 16:52:13 +01:00
11 changed files with 1600 additions and 1297 deletions

2827
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/smarttime", "name": "@pushrocks/smarttime",
"private": false, "private": false,
"version": "3.0.41", "version": "3.0.46",
"description": "handle time in smart ways", "description": "handle time in smart ways",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
@ -12,20 +12,20 @@
"build": "(tsbuild --web && tsbundle npm)" "build": "(tsbuild --web && tsbundle npm)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.28", "@gitzone/tsbuild": "^2.1.29",
"@gitzone/tsbundle": "^1.0.88", "@gitzone/tsbundle": "^1.0.89",
"@gitzone/tsrun": "^1.2.18", "@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.60", "@gitzone/tstest": "^1.0.60",
"@pushrocks/tapbundle": "^3.2.14", "@pushrocks/tapbundle": "^4.0.3",
"@types/node": "^16.11.6", "@types/node": "^17.0.14",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^5.0.0", "@pushrocks/lik": "^5.0.4",
"@pushrocks/smartdelay": "^2.0.13", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartpromise": "^3.1.6", "@pushrocks/smartpromise": "^3.1.6",
"croner": "^4.0.69", "croner": "^4.0.86",
"dayjs": "^1.10.7", "dayjs": "^1.10.7",
"is-nan": "^1.3.2", "is-nan": "^1.3.2",
"pretty-ms": "^7.0.1" "pretty-ms": "^7.0.1"

View File

@ -36,7 +36,7 @@ This class provides scheduling of functions with a cron syntax
```typescript ```typescript
import { CronManager } from '@pushrocks/smarrtime'; import { CronManager } from '@pushrocks/smarrtime';
const cronManagerInstance = new CronManager(); const cronManagerInstance = new CronManager();
cronManagerInstance.addConrjob('* * * * * *', async () => { cronManagerInstance.addCronjob('* * * * * *', async () => {
console.log('hello'); // will log 'hello' to console once every second; console.log('hello'); // will log 'hello' to console once every second;
}); });
cronManagerInstance.start(); cronManagerInstance.start();

View File

@ -9,15 +9,15 @@ tap.test('should create valid testTimeStamp instance', async (tools) => {
testTimeStamp = new smarttime.TimeStamp(); testTimeStamp = new smarttime.TimeStamp();
await tools.delayFor(2); await tools.delayFor(2);
testTimeStamp2 = new smarttime.TimeStamp(); testTimeStamp2 = new smarttime.TimeStamp();
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp); expect(testTimeStamp).toBeInstanceOf(smarttime.TimeStamp);
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp); expect(testTimeStamp).toBeInstanceOf(smarttime.TimeStamp);
}); });
tap.test('should have valid linuxtime', async () => { tap.test('should have valid linuxtime', async () => {
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(testTimeStamp.isOlderThan(testTimeStamp2)).to.be.true; expect(testTimeStamp.isOlderThan(testTimeStamp2)).toBeTrue();
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(testTimeStamp.isYoungerThanOtherTimeStamp(testTimeStamp2)).to.be.false; expect(testTimeStamp.isYoungerThanOtherTimeStamp(testTimeStamp2)).toBeFalse();
}); });
let testHrtMeasurement: smarttime.HrtMeasurement; let testHrtMeasurement: smarttime.HrtMeasurement;
@ -28,8 +28,8 @@ tap.test('should create valid HrtMeasurements', async (tools) => {
testHrtMeasurement.start(); testHrtMeasurement.start();
await tools.delayFor(20); await tools.delayFor(20);
testHrtMeasurement.stop(); testHrtMeasurement.stop();
expect(testHrtMeasurement.milliSeconds).to.be.greaterThan(19); expect(testHrtMeasurement.milliSeconds).toBeGreaterThan(19);
expect(testHrtMeasurement.milliSeconds).to.be.lessThan(25); expect(testHrtMeasurement.milliSeconds).toBeLessThan(25);
}); });
// check units // check units

View File

@ -6,7 +6,7 @@ let testCronManager: smarttime.CronManager;
tap.test('should create a valid instance of cronmanager', async () => { tap.test('should create a valid instance of cronmanager', async () => {
testCronManager = new smarttime.CronManager(); testCronManager = new smarttime.CronManager();
expect(testCronManager).to.be.instanceOf(smarttime.CronManager); expect(testCronManager).toBeInstanceOf(smarttime.CronManager);
}); });
tap.test('should create a valid cronJon', async (tools) => { tap.test('should create a valid cronJon', async (tools) => {

View File

@ -23,7 +23,7 @@ tap.test('should create a date and time with European Format', async () => {
tap.test('should create a European date string', async () => { tap.test('should create a European date string', async () => {
const extendedDate = smarttime.ExtendedDate.fromHyphedDate('2018-02-13'); const extendedDate = smarttime.ExtendedDate.fromHyphedDate('2018-02-13');
expect(extendedDate.exportToEuropeanDate()).to.equal('13.02.2018'); expect(extendedDate.exportToEuropeanDate()).toEqual('13.02.2018');
}); });
tap.test('should format a date', async () => { tap.test('should format a date', async () => {

View File

@ -7,7 +7,7 @@ let testTimer: Timer;
tap.test('should create a valid timer', async () => { tap.test('should create a valid timer', async () => {
testTimer = new Timer(1000); testTimer = new Timer(1000);
expect(testTimer).to.be.instanceof(Timer); expect(testTimer).toBeInstanceOf(Timer);
}); });
tap.test('should start timer', async () => { tap.test('should start timer', async () => {

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smarttime',
version: '3.0.46',
description: 'handle time in smart ways'
}

View File

@ -3,10 +3,10 @@ import { CronManager } from './smarttime.classes.cronmanager';
import { CronParser } from './smarttime.classes.cronparser'; import { CronParser } from './smarttime.classes.cronparser';
export type TJobFunction = (() => void) | (() => Promise<any>); export type TJobFunction = ((triggerTimeArg?: number) => void) | ((triggerTimeArg?: number) => Promise<any>);
export class CronJob { export class CronJob {
public cronParser: CronParser | typeof plugins.croner; public cronParser: typeof plugins.croner;
public status: 'started' | 'stopped' | 'initial' = 'initial'; public status: 'started' | 'stopped' | 'initial' = 'initial';
public cronExpression: string; public cronExpression: string;
public jobFunction: TJobFunction; public jobFunction: TJobFunction;
@ -26,7 +26,7 @@ export class CronJob {
this.getNextExecutionTime(); this.getNextExecutionTime();
} }
if (Date.now() > this.nextExecutionUnix) { if (Date.now() > this.nextExecutionUnix) {
const maybePromise = this.jobFunction(); const maybePromise = this.jobFunction(this.nextExecutionUnix);
if (maybePromise instanceof Promise) { if (maybePromise instanceof Promise) {
maybePromise.catch(e => console.log(e)); maybePromise.catch(e => console.log(e));
} }

View File

@ -83,6 +83,11 @@ export class ExtendedDate extends Date {
return `${units.dayString}.${units.monthString}.${units.yearString}`; return `${units.dayString}.${units.monthString}.${units.yearString}`;
} }
public exportToHyphedSortableDate() {
const units = this.exportToUnits();
return `${units.yearString}-${units.monthString}-${units.dayString}`;
}
/** /**
* exports units * exports units
*/ */

View File

@ -53,6 +53,19 @@ export class TimeStamp {
this.epochtime = Math.floor(this.milliSeconds / 1000); this.epochtime = Math.floor(this.milliSeconds / 1000);
} }
/**
* returns a boolean for wether the timestamp is older than another timestamp
* @param TimeStampArg
* @param tresholdTimeArg
*/
public isOlderThanOtherTimeStamp(TimeStampArg: TimeStamp, tresholdTimeArg: number = 0) {
if (this.milliSeconds < TimeStampArg.milliSeconds - tresholdTimeArg) {
return true;
} else {
return false;
}
}
/** /**
* Is the current instance older than the argument * Is the current instance older than the argument
* @param TimeStampArg * @param TimeStampArg
@ -66,7 +79,7 @@ export class TimeStamp {
} }
/** /**
* returns a boolean for wether a timestamp is younger * returns a boolean for wether the timestamp is younger than another timestamp
* @param TimeStampArg * @param TimeStampArg
* @param tresholdTimeArg * @param tresholdTimeArg
*/ */