Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
5f5957b0c0 | |||
31275536ec | |||
c759d436dd | |||
010c9e7bed | |||
264c08d848 | |||
b2a5cda468 | |||
d3dd03534a | |||
9b96779d19 | |||
20b181b2f3 | |||
d278722da2 | |||
e3daf08d67 | |||
0483b55a9e | |||
c3a772c155 | |||
a2ffdd436f | |||
da9c71eedb | |||
63405fc577 | |||
d789eec558 | |||
22027d2308 | |||
87d29fbb50 | |||
1c5a1c21da | |||
969088ad04 | |||
76768a1307 | |||
419fe80bde | |||
5a9584917c | |||
2b21ee9a24 | |||
3a110c9fd9 | |||
25f7ad37ae | |||
992d167a34 | |||
cfcfde2132 | |||
b5ab945501 | |||
88378e2f31 | |||
db92311daa |
@ -12,40 +12,36 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- pnpm install -g pnpm
|
||||||
|
- pnpm install -g @shipzone/npmci
|
||||||
|
- npmci npm prepare
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm install --production --ignore-scripts
|
- npmci command pnpm audit --audit-level=high --prod
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high --only=dev
|
- npmci command pnpm audit --audit-level=high --dev
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
@ -56,7 +52,6 @@ auditDevDependencies:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -67,7 +62,6 @@ testStable:
|
|||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
@ -96,10 +90,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -119,11 +112,9 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smarttime",
|
"gitrepo": "smarttime",
|
||||||
"shortDescription": "handle time in smart ways",
|
"description": "handle time in smart ways",
|
||||||
"npmPackagename": "@pushrocks/smarttime",
|
"npmPackagename": "@pushrocks/smarttime",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
11011
package-lock.json
generated
11011
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.33",
|
"version": "4.0.0",
|
||||||
"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",
|
||||||
@ -9,24 +9,25 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest ./test)",
|
"test": "(tstest ./test)",
|
||||||
"build": "(tsbuild --web && tsbundle npm)"
|
"build": "(tsbuild --web && tsbundle npm)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.29",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^2.0.7",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.18",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.60",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^14.6.2",
|
"@types/node": "^18.11.9"
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^4.0.17",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"dayjs": "^1.8.35",
|
"croner": "^5.3.4",
|
||||||
"is-nan": "^1.3.0"
|
"dayjs": "^1.10.7",
|
||||||
|
"is-nan": "^1.3.2",
|
||||||
|
"pretty-ms": "^8.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@ -42,5 +43,6 @@
|
|||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
]
|
],
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
4344
pnpm-lock.yaml
generated
Normal file
4344
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
// tslint:disable-next-line:no-implicit-dependencies
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index.js';
|
||||||
|
|
||||||
// Test TimeStamp class
|
// Test TimeStamp class
|
||||||
let testTimeStamp: smarttime.TimeStamp;
|
let testTimeStamp: smarttime.TimeStamp;
|
||||||
@ -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
|
@ -1,12 +1,12 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index.js';
|
||||||
|
|
||||||
let testCronManager: smarttime.CronManager;
|
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) => {
|
||||||
@ -17,7 +17,7 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
let counter2 = 0;
|
let counter2 = 0;
|
||||||
let counter3 = 0;
|
let counter3 = 0;
|
||||||
const cronJob = testCronManager.addCronjob('*/2 * * * * *', async () => {
|
const cronJob = testCronManager.addCronjob('*/2 * * * * *', async () => {
|
||||||
if (counter === 10) {
|
if (counter === 5) {
|
||||||
testCronManager.removeCronjob(cronJob);
|
testCronManager.removeCronjob(cronJob);
|
||||||
done.resolve();
|
done.resolve();
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
console.log(`${new Date().getSeconds()} hey ${counter} -> runs every 2 seconds`);
|
console.log(`${new Date().getSeconds()} hey ${counter} -> runs every 2 seconds`);
|
||||||
});
|
});
|
||||||
const cronJob2 = testCronManager.addCronjob('*/3 * * * * *', async () => {
|
const cronJob2 = testCronManager.addCronjob('*/3 * * * * *', async () => {
|
||||||
if (counter2 === 10) {
|
if (counter2 === 5) {
|
||||||
testCronManager.removeCronjob(cronJob2);
|
testCronManager.removeCronjob(cronJob2);
|
||||||
done2.resolve();
|
done2.resolve();
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
console.log(`${new Date().getSeconds()} hey ${counter2} -> runs every 3 seconds`);
|
console.log(`${new Date().getSeconds()} hey ${counter2} -> runs every 3 seconds`);
|
||||||
});
|
});
|
||||||
const cronJob3 = testCronManager.addCronjob('*/4 * * * * *', async () => {
|
const cronJob3 = testCronManager.addCronjob('*/4 * * * * *', async () => {
|
||||||
if (counter3 === 10) {
|
if (counter3 === 5) {
|
||||||
done3.resolve();
|
done3.resolve();
|
||||||
}
|
}
|
||||||
counter3++;
|
counter3++;
|
||||||
@ -44,6 +44,17 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
await done2.promise;
|
await done2.promise;
|
||||||
await done3.promise;
|
await done3.promise;
|
||||||
testCronManager.stop();
|
testCronManager.stop();
|
||||||
|
testCronManager.removeCronjob(cronJob3);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('runs every full minute', async (tools) => {
|
||||||
|
const done = tools.defer();
|
||||||
|
const cronJob = testCronManager.addCronjob('0 * * * * *', async () => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
testCronManager.start();
|
||||||
|
await done.promise;
|
||||||
|
testCronManager.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
@ -1,27 +0,0 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
|
||||||
|
|
||||||
import * as smarttime from '../ts/index';
|
|
||||||
|
|
||||||
let testCronManager: smarttime.CronManager;
|
|
||||||
|
|
||||||
tap.test('should create a valid instance of cronmanager', async () => {
|
|
||||||
testCronManager = new smarttime.CronManager();
|
|
||||||
expect(testCronManager).to.be.instanceOf(smarttime.CronManager);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should create a valid cronJon', async (tools) => {
|
|
||||||
const done = tools.defer();
|
|
||||||
let counter = 0;
|
|
||||||
testCronManager.addCronjob('*/2 * * * * *', async () => {
|
|
||||||
if (counter === 10) {
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
console.log(`hey ${counter}`);
|
|
||||||
});
|
|
||||||
testCronManager.start();
|
|
||||||
await done.promise;
|
|
||||||
testCronManager.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
@ -1,6 +1,11 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index.js';
|
||||||
|
|
||||||
|
tap.test('should create a valid JavaScript Date', async () => {
|
||||||
|
const extendedDate = new smarttime.ExtendedDate(Date.now());
|
||||||
|
console.log(extendedDate);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
||||||
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
|
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
|
||||||
@ -18,7 +23,12 @@ 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 () => {
|
||||||
|
const extendedDate = new smarttime.ExtendedDate(Date.now());
|
||||||
|
console.log(extendedDate.format('YYYY-MM-DD - hh:mm'));
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
// tslint:disable-next-line:no-implicit-dependencies
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import { Timer } from '../ts/index';
|
import { Timer } from '../ts/index.js';
|
||||||
|
|
||||||
let testTimer: Timer;
|
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
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smarttime',
|
||||||
|
version: '4.0.0',
|
||||||
|
description: 'handle time in smart ways'
|
||||||
|
}
|
16
ts/index.ts
16
ts/index.ts
@ -1,8 +1,8 @@
|
|||||||
export * from './smarttime.classes.cronmanager';
|
export * from './smarttime.classes.cronmanager.js';
|
||||||
export * from './smarttime.classes.cronjob';
|
export * from './smarttime.classes.cronjob.js';
|
||||||
export * from './smarttime.classes.extendeddate';
|
export * from './smarttime.classes.extendeddate.js';
|
||||||
export * from './smarttime.classes.hrtmeasurement';
|
export * from './smarttime.classes.hrtmeasurement.js';
|
||||||
export * from './smarttime.classes.interval';
|
export * from './smarttime.classes.interval.js';
|
||||||
export * from './smarttime.classes.timer';
|
export * from './smarttime.classes.timer.js';
|
||||||
export * from './smarttime.classes.timestamp';
|
export * from './smarttime.classes.timestamp.js';
|
||||||
export * from './smarttime.units';
|
export * from './smarttime.units.js';
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
import { CronManager } from './smarttime.classes.cronmanager';
|
import { CronManager } from './smarttime.classes.cronmanager.js';
|
||||||
|
|
||||||
import { CronParser } from './smarttime.classes.cronparser';
|
import { CronParser } from './smarttime.classes.cronparser.js';
|
||||||
|
|
||||||
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;
|
public cronParser: 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;
|
||||||
@ -15,7 +17,7 @@ export class CronJob {
|
|||||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
||||||
this.cronExpression = cronExpressionArg;
|
this.cronExpression = cronExpressionArg;
|
||||||
this.jobFunction = jobFunction;
|
this.jobFunction = jobFunction;
|
||||||
this.cronParser = new CronParser(cronExpressionArg);
|
this.cronParser = plugins.croner(cronExpressionArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,9 +28,9 @@ 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));
|
||||||
}
|
}
|
||||||
this.nextExecutionUnix = this.getNextExecutionTime();
|
this.nextExecutionUnix = this.getNextExecutionTime();
|
||||||
}
|
}
|
||||||
@ -36,14 +38,14 @@ export class CronJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getNextExecutionTime() {
|
public getNextExecutionTime() {
|
||||||
return this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution();
|
return (this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the time to next execution
|
* gets the time to next execution
|
||||||
*/
|
*/
|
||||||
public getTimeToNextExecution() {
|
public getTimeToNextExecution() {
|
||||||
return this.cronParser.getMsToNextTimeMatch();
|
return this.cronParser.msToNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
import { CronJob } from './smarttime.classes.cronjob';
|
import { CronJob } from './smarttime.classes.cronjob.js';
|
||||||
|
import { getMilliSecondsAsHumanReadableString } from './smarttime.units.js';
|
||||||
|
|
||||||
export class CronManager {
|
export class CronManager {
|
||||||
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
||||||
@ -47,16 +48,19 @@ export class CronManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextRunningCronjob) {
|
if (nextRunningCronjob) {
|
||||||
this.executionTimeout = new plugins.smartdelay.Timeout(nextRunningCronjob.getTimeToNextExecution());
|
this.executionTimeout = new plugins.smartdelay.Timeout(
|
||||||
|
nextRunningCronjob.getTimeToNextExecution()
|
||||||
|
);
|
||||||
console.log(
|
console.log(
|
||||||
`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`
|
`Next CronJob scheduled in ${getMilliSecondsAsHumanReadableString(
|
||||||
|
this.executionTimeout.getTimeLeft()
|
||||||
|
)}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.executionTimeout = new plugins.smartdelay.Timeout(1000);
|
this.executionTimeout = new plugins.smartdelay.Timeout(1000);
|
||||||
console.log('no cronjobs specified! Checking again in 1 second');
|
console.log('no cronjobs specified! Checking again in 1 second');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await this.executionTimeout.promise;
|
await this.executionTimeout.promise;
|
||||||
} while (this.status === 'started');
|
} while (this.status === 'started');
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
export class CronParser {
|
export class CronParser {
|
||||||
public cronExpression: string;
|
public cronExpression: string;
|
||||||
@ -18,7 +18,7 @@ export class CronParser {
|
|||||||
}
|
}
|
||||||
if (cronPart.includes('/')) {
|
if (cronPart.includes('/')) {
|
||||||
const every = parseInt(cronPart.split('/')[1], 10);
|
const every = parseInt(cronPart.split('/')[1], 10);
|
||||||
const findEvenMatch = (recursionStartArg: number) => {
|
const findEvenMatch = (recursionStartArg: number): number => {
|
||||||
if (recursionStartArg % every === 0) {
|
if (recursionStartArg % every === 0) {
|
||||||
return recursionStartArg;
|
return recursionStartArg;
|
||||||
} else {
|
} else {
|
||||||
@ -27,13 +27,13 @@ export class CronParser {
|
|||||||
};
|
};
|
||||||
return findEvenMatch(startValue);
|
return findEvenMatch(startValue);
|
||||||
}
|
}
|
||||||
if (parseInt(cronPart, 10)) {
|
if (parseInt(cronPart, 10) || cronPart === '0') {
|
||||||
const match = parseInt(cronPart, 10);
|
const match = parseInt(cronPart, 10);
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMsToNextTimeMatch() {
|
public msToNext() {
|
||||||
const cronArray = this.cronArray;
|
const cronArray = this.cronArray;
|
||||||
const secondExpression = cronArray[0];
|
const secondExpression = cronArray[0];
|
||||||
const minuteExpression = cronArray[1];
|
const minuteExpression = cronArray[1];
|
||||||
@ -42,19 +42,36 @@ export class CronParser {
|
|||||||
const monthExpression = cronArray[4];
|
const monthExpression = cronArray[4];
|
||||||
const yearExpression = cronArray[5];
|
const yearExpression = cronArray[5];
|
||||||
|
|
||||||
const currentDate = new Date();
|
let currentDate = new Date();
|
||||||
const currentSecond = currentDate.getSeconds() + 1;
|
let currentSecond = currentDate.getSeconds() + 1;
|
||||||
const currentMinute = currentDate.getMinutes();
|
let currentMinute = currentDate.getMinutes();
|
||||||
const currentHour = currentDate.getHours();
|
let currentHour = currentDate.getHours();
|
||||||
const currentDay = currentDate.getDate();
|
let currentDay = currentDate.getDate();
|
||||||
const currentMonth = currentDate.getMonth();
|
let currentMonth = currentDate.getMonth();
|
||||||
const currentYear = currentDate.getFullYear();
|
let currentYear = currentDate.getFullYear();
|
||||||
|
|
||||||
const targetSecond = this.getNextPartMatch(secondExpression, currentSecond, 59);
|
const targetSecond = this.getNextPartMatch(secondExpression, currentSecond, 59);
|
||||||
|
if (targetSecond < currentSecond) {
|
||||||
|
currentMinute = (currentMinute + 1) % 59;
|
||||||
|
}
|
||||||
const targetMinute = this.getNextPartMatch(minuteExpression, currentMinute, 59);
|
const targetMinute = this.getNextPartMatch(minuteExpression, currentMinute, 59);
|
||||||
|
if (targetMinute < currentMinute) {
|
||||||
|
currentHour = (currentHour + 1) % 23;
|
||||||
|
}
|
||||||
const targetHour = this.getNextPartMatch(hourExpression, currentHour, 23);
|
const targetHour = this.getNextPartMatch(hourExpression, currentHour, 23);
|
||||||
|
if (targetHour < currentHour) {
|
||||||
|
currentDay = (currentDay + 1) % 30;
|
||||||
|
}
|
||||||
|
|
||||||
const targetDay = currentDay;
|
const targetDay = currentDay;
|
||||||
|
if (targetDay < currentDay) {
|
||||||
|
currentMonth = (currentMonth + 1) % 11;
|
||||||
|
}
|
||||||
|
|
||||||
const targetMonth = currentMonth;
|
const targetMonth = currentMonth;
|
||||||
|
if (targetMonth < currentMonth) {
|
||||||
|
currentYear = currentYear + 1;
|
||||||
|
}
|
||||||
const targetYear = currentYear;
|
const targetYear = currentYear;
|
||||||
|
|
||||||
const targetDate = new Date(
|
const targetDate = new Date(
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
import * as units from './smarttime.units.js';
|
||||||
|
|
||||||
export type TAvailableZone = 'Europe/Berlin';
|
export type TAvailableZone = 'Europe/Berlin';
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ export class ExtendedDate extends Date {
|
|||||||
// INSTANCE
|
// INSTANCE
|
||||||
public timezone: TAvailableZone;
|
public timezone: TAvailableZone;
|
||||||
|
|
||||||
constructor(unixMilli: number) {
|
constructor(unixMilli: number = Date.now()) {
|
||||||
super(unixMilli);
|
super(unixMilli);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,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
|
||||||
*/
|
*/
|
||||||
@ -121,4 +127,25 @@ export class ExtendedDate extends Date {
|
|||||||
dayOfTheWeekName: daysArray[this.getDay()],
|
dayOfTheWeekName: daysArray[this.getDay()],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public format(formatArg: string) {
|
||||||
|
return plugins.dayjs(this.getTime()).format(formatArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* boolean checks
|
||||||
|
*/
|
||||||
|
public isToday() {
|
||||||
|
return plugins.dayjs(this.getTime()).isToday();
|
||||||
|
}
|
||||||
|
|
||||||
|
public lessTimePassedToNow(unitArgs: units.IUnitCombinationArg): boolean {
|
||||||
|
const maxPassedUnixTime = units.getMilliSecondsFromUnits(unitArgs);
|
||||||
|
const actualPassedUnixTime = Date.now() - this.getTime();
|
||||||
|
return actualPassedUnixTime < maxPassedUnixTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public moreTimePassedToNow(unitArgs: units.IUnitCombinationArg) {
|
||||||
|
return !this.lessTimePassedToNow(unitArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
export class Interval {
|
export class Interval {
|
||||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
import { TimeStamp } from './smarttime.classes.timestamp';
|
import { TimeStamp } from './smarttime.classes.timestamp.js';
|
||||||
|
|
||||||
export type TimerState = 'initiated' | 'started' | 'paused' | 'completed';
|
export type TimerState = 'initiated' | 'started' | 'paused' | 'completed';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TimeStamp
|
* TimeStamp
|
||||||
@ -8,7 +8,7 @@ export class TimeStamp {
|
|||||||
/**
|
/**
|
||||||
* returns new TimeStamp from milliseconds
|
* returns new TimeStamp from milliseconds
|
||||||
*/
|
*/
|
||||||
public static fromMilliSeconds(milliSecondsArg) {
|
public static fromMilliSeconds(milliSecondsArg: number) {
|
||||||
return new TimeStamp(milliSecondsArg);
|
return new TimeStamp(milliSecondsArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -5,7 +5,12 @@ import * as smartpromise from '@pushrocks/smartpromise';
|
|||||||
|
|
||||||
export { lik, smartdelay, smartpromise };
|
export { lik, smartdelay, smartpromise };
|
||||||
|
|
||||||
// third parties
|
// third parties;
|
||||||
|
import croner from 'croner';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import isToday from 'dayjs/plugin/isToday.js';
|
||||||
|
import prettyMs from 'pretty-ms';
|
||||||
|
|
||||||
export { dayjs };
|
dayjs.extend(isToday);
|
||||||
|
|
||||||
|
export { croner, dayjs, prettyMs };
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
export let units = {
|
export let units = {
|
||||||
years: (timesArg = 1): number => {
|
years: (timesArg = 1): number => {
|
||||||
return timesArg * 3.154e10;
|
return timesArg * 3.154e10;
|
||||||
@ -30,7 +32,7 @@ export interface IUnitCombinationArg {
|
|||||||
|
|
||||||
export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
||||||
let timeInMilliseconds = 0;
|
let timeInMilliseconds = 0;
|
||||||
let addMilliSeconds = (milliSecondsArg) => {
|
let addMilliSeconds = (milliSecondsArg: number) => {
|
||||||
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
||||||
};
|
};
|
||||||
if (combinationArg.years) {
|
if (combinationArg.years) {
|
||||||
@ -54,3 +56,7 @@ export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
|||||||
|
|
||||||
return timeInMilliseconds;
|
return timeInMilliseconds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getMilliSecondsAsHumanReadableString = (milliSecondsArg: number): string => {
|
||||||
|
return plugins.prettyMs(milliSecondsArg);
|
||||||
|
};
|
||||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user