Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
19b5ba4a5d | |||
457182a97a | |||
a7a961c869 | |||
f1d7771e30 | |||
ff16b70206 | |||
8e43ce7e9b | |||
f129ce42b6 | |||
56a802664f | |||
743c9fb847 | |||
ac2edd6d74 | |||
725102d02c | |||
7c73579c9f | |||
a1996ea1bd | |||
dc92ae7140 | |||
3e862f233c | |||
73f7360f8c | |||
2c74de8aef | |||
78498626ea | |||
b2299b149a | |||
885b2432a8 | |||
7a231b7686 | |||
ef6e21080e | |||
3ea8b1564d | |||
1b92240c4e | |||
95bf558503 | |||
d1ff77d9f5 |
@ -19,23 +19,35 @@ mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -50,9 +62,7 @@ testStable:
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
@ -63,9 +73,7 @@ testBuild:
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@ -85,6 +93,8 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm"]
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
license
Normal file
21
license
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Lossless GmbH (hello@lossless.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
9453
package-lock.json
generated
9453
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@pushrocks/smarttime",
|
||||
"private": false,
|
||||
"version": "3.0.16",
|
||||
"version": "3.0.29",
|
||||
"description": "handle time in smart ways",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
@ -9,25 +9,25 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest ./test/)",
|
||||
"build": "(tsbuild && tsbundle npm --production)"
|
||||
"build": "(tsbuild --web && tsbundle npm)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tsbundle": "^1.0.69",
|
||||
"@gitzone/tsrun": "^1.2.6",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.9",
|
||||
"@types/node": "^14.0.5",
|
||||
"tslint": "^6.1.2",
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsbundle": "^1.0.78",
|
||||
"@gitzone/tsrun": "^1.2.12",
|
||||
"@gitzone/tstest": "^1.0.44",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.6.2",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.6",
|
||||
"@pushrocks/lik": "^4.0.17",
|
||||
"@pushrocks/smartdelay": "^2.0.10",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@types/cron": "^1.7.1",
|
||||
"@types/luxon": "^1.15.1",
|
||||
"cron-parser": "^2.14.0",
|
||||
"luxon": "^1.16.0"
|
||||
"croner": "^1.1.23",
|
||||
"dayjs": "^1.8.35",
|
||||
"is-nan": "^1.3.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -40,5 +40,8 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
22
readme.md
22
readme.md
@ -8,13 +8,20 @@ handle time in smart ways
|
||||
* [docs (typedoc)](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/@pushrocks/smarttime)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smarttime)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
@ -44,7 +51,6 @@ import { ExtendedDate } from '@pushrocks/smarttime'
|
||||
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
||||
```
|
||||
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
27
test/test.cronmanager.browser.ts
Normal file
27
test/test.cronmanager.browser.ts
Normal file
@ -0,0 +1,27 @@
|
||||
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();
|
@ -9,18 +9,40 @@ tap.test('should create a valid instance of cronmanager', async () => {
|
||||
expect(testCronManager).to.be.instanceOf(smarttime.CronManager);
|
||||
});
|
||||
|
||||
tap.test('should create a valid cronJon', async tools => {
|
||||
tap.test('should create a valid cronJon', async (tools) => {
|
||||
const done = tools.defer();
|
||||
const done2 = tools.defer();
|
||||
const done3 = tools.defer();
|
||||
let counter = 0;
|
||||
testCronManager.addCronjob('* * * * * *', () => {
|
||||
let counter2 = 0;
|
||||
let counter3 = 0;
|
||||
const cronJob = testCronManager.addCronjob('*/2 * * * * *', async () => {
|
||||
if (counter === 10) {
|
||||
testCronManager.removeCronjob(cronJob);
|
||||
done.resolve();
|
||||
}
|
||||
counter++;
|
||||
console.log(`hey ${counter}`);
|
||||
console.log(`${new Date().getSeconds()} hey ${counter} -> runs every 2 seconds`);
|
||||
});
|
||||
const cronJob2 = testCronManager.addCronjob('*/3 * * * * *', async () => {
|
||||
if (counter2 === 10) {
|
||||
testCronManager.removeCronjob(cronJob2);
|
||||
done2.resolve();
|
||||
}
|
||||
counter2++;
|
||||
console.log(`${new Date().getSeconds()} hey ${counter2} -> runs every 3 seconds`);
|
||||
});
|
||||
const cronJob3 = testCronManager.addCronjob('*/4 * * * * *', async () => {
|
||||
if (counter3 === 10) {
|
||||
done3.resolve();
|
||||
}
|
||||
counter3++;
|
||||
console.log(`${new Date().getSeconds()} hey ${counter3} -> runs every 4 seconds`);
|
||||
});
|
||||
testCronManager.start();
|
||||
await done.promise;
|
||||
await done2.promise;
|
||||
await done3.promise;
|
||||
testCronManager.stop();
|
||||
});
|
||||
|
||||
|
@ -5,7 +5,7 @@ import * as smarttime from '../ts/index';
|
||||
// Test TimeStamp class
|
||||
let testTimeStamp: smarttime.TimeStamp;
|
||||
let testTimeStamp2: smarttime.TimeStamp;
|
||||
tap.test('should create valid testTimeStamp instance', async tools => {
|
||||
tap.test('should create valid testTimeStamp instance', async (tools) => {
|
||||
testTimeStamp = new smarttime.TimeStamp();
|
||||
await tools.delayFor(2);
|
||||
testTimeStamp2 = new smarttime.TimeStamp();
|
||||
@ -23,7 +23,7 @@ tap.test('should have valid linuxtime', async () => {
|
||||
let testHrtMeasurement: smarttime.HrtMeasurement;
|
||||
|
||||
// Test HrtMeasurement
|
||||
tap.test('should create valid HrtMeasurements', async tools => {
|
||||
tap.test('should create valid HrtMeasurements', async (tools) => {
|
||||
testHrtMeasurement = new smarttime.HrtMeasurement();
|
||||
testHrtMeasurement.start();
|
||||
await tools.delayFor(20);
|
||||
@ -41,7 +41,7 @@ tap.test('should combine units', async () => {
|
||||
weeks: 2,
|
||||
days: 2,
|
||||
hours: 2,
|
||||
minutes: 2
|
||||
minutes: 2,
|
||||
});
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(computedTime);
|
||||
|
@ -1,6 +1,8 @@
|
||||
export * from './smarttime.classes.cronmanager';
|
||||
export * from './smarttime.classes.cronjob';
|
||||
export * from './smarttime.classes.extendeddate';
|
||||
export * from './smarttime.classes.hrtmeasurement';
|
||||
export * from './smarttime.classes.interval';
|
||||
export * from './smarttime.classes.timer';
|
||||
export * from './smarttime.classes.timestamp';
|
||||
export * from './smarttime.units';
|
||||
|
@ -4,48 +4,51 @@ import { CronManager } from './smarttime.classes.cronmanager';
|
||||
export type TJobFunction = (() => void) | (() => Promise<any>);
|
||||
|
||||
export class CronJob {
|
||||
public croner;
|
||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||
public cronExpression: string;
|
||||
public jobFunction: TJobFunction;
|
||||
|
||||
private cronInterval = plugins.cronParser.parseExpression('* * * * * *');
|
||||
private nextExecutionUnix: number = 0;
|
||||
|
||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
||||
this.cronExpression = cronExpressionArg;
|
||||
this.jobFunction = jobFunction;
|
||||
this.croner = plugins.croner(this.cronExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks wether the cronjob needs to be executed
|
||||
*/
|
||||
public checkExecution() {
|
||||
public checkExecution(): number {
|
||||
if (this.nextExecutionUnix === 0) {
|
||||
this.nextExecutionUnix = this.cronInterval
|
||||
.next()
|
||||
.toDate()
|
||||
.getTime();
|
||||
return;
|
||||
this.getNextExecutionTime();
|
||||
}
|
||||
if (Date.now() > this.nextExecutionUnix) {
|
||||
this.jobFunction();
|
||||
this.nextExecutionUnix = this.cronInterval
|
||||
.next()
|
||||
.toDate()
|
||||
.getTime();
|
||||
const maybePromise = this.jobFunction();
|
||||
if (maybePromise instanceof Promise) {
|
||||
maybePromise.catch(e => console.log(e));
|
||||
}
|
||||
this.nextExecutionUnix = this.getNextExecutionTime();
|
||||
}
|
||||
return this.nextExecutionUnix;
|
||||
}
|
||||
|
||||
public getNextExecutionTime() {
|
||||
return this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the time to next execution
|
||||
*/
|
||||
public getTimeToNextExecution() {
|
||||
return this.croner.msToNext();
|
||||
}
|
||||
|
||||
public start() {
|
||||
this.cronInterval = this.getCronInterval();
|
||||
this.status = 'started';
|
||||
}
|
||||
|
||||
public stop() {
|
||||
this.status = 'stopped';
|
||||
}
|
||||
|
||||
private getCronInterval() {
|
||||
return plugins.cronParser.parseExpression(this.cronExpression);
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,74 @@
|
||||
import * as plugins from './smarttime.plugins';
|
||||
import { CronJob } from './smarttime.classes.cronjob';
|
||||
import { Timer } from './smarttime.classes.timer';
|
||||
import { Interval } from './smarttime.classes.interval';
|
||||
|
||||
export class CronManager {
|
||||
public cronInterval = new Interval(1000);
|
||||
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
||||
|
||||
public status: 'started' | 'stopped' = 'stopped';
|
||||
public cronjobs: CronJob[] = [];
|
||||
public cronjobs = new plugins.lik.ObjectMap<CronJob>();
|
||||
|
||||
constructor() {
|
||||
this.cronInterval.addIntervalJob(() => {
|
||||
for (const cronJob of this.cronjobs) {
|
||||
cronJob.checkExecution();
|
||||
}
|
||||
});
|
||||
}
|
||||
constructor() {}
|
||||
|
||||
public addCronjob(cronIdentifierArg: string, cronFunctionArg: () => any) {
|
||||
public addCronjob(cronIdentifierArg: string, cronFunctionArg: () => Promise<void>) {
|
||||
const newCronJob = new CronJob(this, cronIdentifierArg, cronFunctionArg);
|
||||
this.cronjobs.push(newCronJob);
|
||||
this.cronjobs.add(newCronJob);
|
||||
if (this.status === 'started') {
|
||||
newCronJob.start();
|
||||
}
|
||||
|
||||
return newCronJob;
|
||||
}
|
||||
|
||||
public removeCronjob(cronjobArg: CronJob) {
|
||||
cronjobArg.stop();
|
||||
this.cronjobs.remove(cronjobArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* starts the cronjob
|
||||
*/
|
||||
public start() {
|
||||
this.status = 'started';
|
||||
for (const cron of this.cronjobs) {
|
||||
cron.start();
|
||||
if (this.status !== 'started') {
|
||||
this.status = 'started';
|
||||
for (const cronJob of this.cronjobs.getArray()) {
|
||||
cronJob.start();
|
||||
}
|
||||
const runCronCycle = async () => {
|
||||
this.executionTimeout = new plugins.smartdelay.Timeout(0);
|
||||
do {
|
||||
let nextRunningCronjob: CronJob;
|
||||
for (const cronJob of this.cronjobs.getArray()) {
|
||||
cronJob.checkExecution();
|
||||
if (
|
||||
!nextRunningCronjob ||
|
||||
cronJob.getTimeToNextExecution() < nextRunningCronjob.getTimeToNextExecution()
|
||||
) {
|
||||
nextRunningCronjob = cronJob;
|
||||
}
|
||||
}
|
||||
this.executionTimeout = new plugins.smartdelay.Timeout(nextRunningCronjob.getTimeToNextExecution());
|
||||
console.log(
|
||||
`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`
|
||||
);
|
||||
await this.executionTimeout.promise;
|
||||
} while (this.status === 'started');
|
||||
};
|
||||
runCronCycle();
|
||||
}
|
||||
this.cronInterval.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* stops all cronjobs
|
||||
*/
|
||||
public stop() {
|
||||
this.status = 'stopped';
|
||||
for (const cron of this.cronjobs) {
|
||||
if (this.status === 'started') {
|
||||
this.status = 'stopped';
|
||||
this.executionTimeout.cancel();
|
||||
} else {
|
||||
console.log(`You tried to stop a CronManager that was not actually started.`);
|
||||
}
|
||||
for (const cron of this.cronjobs.getArray()) {
|
||||
cron.stop();
|
||||
}
|
||||
this.cronInterval.stop();
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ export class ExtendedDate extends Date {
|
||||
|
||||
public static fromEuropeanDate(europeanDate: string) {
|
||||
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate);
|
||||
const luxonDate = plugins.luxon.DateTime.utc(
|
||||
const date = new Date(
|
||||
parseFloat(dateArray[3]), // year
|
||||
parseFloat(dateArray[2]), // month
|
||||
parseFloat(dateArray[2]) - 1, // month
|
||||
parseFloat(dateArray[1]) // day
|
||||
);
|
||||
const unixMilli = luxonDate.toMillis();
|
||||
const unixMilli = date.getTime();
|
||||
return new ExtendedDate(unixMilli);
|
||||
}
|
||||
|
||||
@ -64,10 +64,8 @@ export class ExtendedDate extends Date {
|
||||
const dateTimeString = `${dateArray[3]}-${sliceDate(dateArray[2])}-${sliceDate(
|
||||
dateArray[1]
|
||||
)}T${timeArg}`;
|
||||
const luxonDate = plugins.luxon.DateTime.fromISO(dateTimeString, {
|
||||
zone: zoneArg
|
||||
});
|
||||
const unixMilli = luxonDate.toMillis();
|
||||
const date = plugins.dayjs(dateTimeString);
|
||||
const unixMilli = date.toDate().getTime();
|
||||
return new ExtendedDate(unixMilli);
|
||||
}
|
||||
|
||||
@ -100,7 +98,7 @@ export class ExtendedDate extends Date {
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December'
|
||||
'December',
|
||||
];
|
||||
const daysArray = [
|
||||
'Monday',
|
||||
@ -109,7 +107,7 @@ export class ExtendedDate extends Date {
|
||||
'Thursday',
|
||||
'Friday',
|
||||
'Saturday',
|
||||
'Sunday'
|
||||
'Sunday',
|
||||
];
|
||||
return {
|
||||
year: this.getFullYear(),
|
||||
@ -120,7 +118,7 @@ export class ExtendedDate extends Date {
|
||||
day: this.getDate(),
|
||||
dayString: ('0' + this.getDate()).slice(-2),
|
||||
dayOfTheWeek: this.getDay(),
|
||||
dayOfTheWeekName: daysArray[this.getDay()]
|
||||
dayOfTheWeekName: daysArray[this.getDay()],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
export class HrtMeasurement {
|
||||
public nanoSeconds: number = null;
|
||||
public milliSeconds: number = null;
|
||||
private _hrTimeStart = null;
|
||||
private _hrTimeStopDiff = null;
|
||||
private _milliStart: number = null;
|
||||
private _milliDiff: number = null;
|
||||
private _started: boolean = false;
|
||||
|
||||
/**
|
||||
@ -13,7 +13,7 @@ export class HrtMeasurement {
|
||||
*/
|
||||
public start() {
|
||||
this._started = true;
|
||||
this._hrTimeStart = process.hrtime();
|
||||
this._milliStart = Date.now();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,9 +24,9 @@ export class HrtMeasurement {
|
||||
console.log("Hasn't started yet");
|
||||
return;
|
||||
}
|
||||
this._hrTimeStopDiff = process.hrtime(this._hrTimeStart);
|
||||
this.nanoSeconds = this._hrTimeStopDiff[0] * 1e9 + this._hrTimeStopDiff[1];
|
||||
this.milliSeconds = this.nanoSeconds / 1000000;
|
||||
this._milliDiff = Date.now() - this._milliStart;
|
||||
this.nanoSeconds = this._milliDiff * 1000;
|
||||
this.milliSeconds = this._milliDiff;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -36,8 +36,8 @@ export class HrtMeasurement {
|
||||
public reset() {
|
||||
this.nanoSeconds = null;
|
||||
this.milliSeconds = null;
|
||||
this._hrTimeStart = null;
|
||||
this._hrTimeStopDiff = null;
|
||||
this._milliStart = null;
|
||||
this._milliDiff = null;
|
||||
this._started = false;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ export class Interval {
|
||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||
private statusAuthorization: any = null;
|
||||
|
||||
// timings
|
||||
public intervalMilliseconds: number;
|
||||
public nextIntervalMillisenconds: number;
|
||||
|
||||
public intervalJobs: Array<() => any> = [];
|
||||
constructor(intervalMillisencondsArg: number) {
|
||||
this.intervalMilliseconds = intervalMillisencondsArg;
|
||||
|
@ -1,11 +1,12 @@
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export { smartdelay, smartpromise };
|
||||
export { lik, smartdelay, smartpromise };
|
||||
|
||||
// third parties
|
||||
import cronParser from 'cron-parser';
|
||||
import * as luxon from 'luxon';
|
||||
import croner from 'croner';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export { cronParser, luxon };
|
||||
export { croner, dayjs };
|
||||
|
@ -16,7 +16,7 @@ export let units = {
|
||||
},
|
||||
minutes: (timesArg = 1) => {
|
||||
return timesArg * 60000;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export interface IUnitCombinationArg {
|
||||
@ -30,7 +30,7 @@ export interface IUnitCombinationArg {
|
||||
|
||||
export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
||||
let timeInMilliseconds = 0;
|
||||
let addMilliSeconds = milliSecondsArg => {
|
||||
let addMilliSeconds = (milliSecondsArg) => {
|
||||
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
||||
};
|
||||
if (combinationArg.years) {
|
||||
|
Reference in New Issue
Block a user