Compare commits

...

22 Commits

Author SHA1 Message Date
725102d02c 3.0.24 2020-07-12 00:25:56 +00:00
7c73579c9f fix(core): update 2020-07-12 00:25:55 +00:00
a1996ea1bd 3.0.23 2020-07-12 00:00:50 +00:00
dc92ae7140 fix(core): update 2020-07-12 00:00:50 +00:00
3e862f233c 3.0.22 2020-07-11 23:36:24 +00:00
73f7360f8c fix(core): update 2020-07-11 23:36:24 +00:00
2c74de8aef 3.0.21 2020-07-11 23:31:10 +00:00
78498626ea fix(core): update 2020-07-11 23:31:09 +00:00
b2299b149a 3.0.20 2020-07-11 21:41:33 +00:00
885b2432a8 fix(core): update 2020-07-11 21:41:33 +00:00
7a231b7686 3.0.19 2020-07-07 22:37:42 +00:00
ef6e21080e fix(core): update 2020-07-07 22:37:41 +00:00
3ea8b1564d 3.0.18 2020-05-27 18:16:12 +00:00
1b92240c4e fix(core): update 2020-05-27 18:16:11 +00:00
95bf558503 3.0.17 2020-05-27 16:59:27 +00:00
d1ff77d9f5 fix(core): update 2020-05-27 16:59:26 +00:00
b77677b089 3.0.16 2020-05-25 22:21:55 +00:00
5ebd9ce6de fix(core): update 2020-05-25 22:21:55 +00:00
702365aba3 3.0.15 2020-05-25 21:49:36 +00:00
93778e1bcf fix(core): update 2020-05-25 21:49:35 +00:00
4d0fb3eb30 3.0.14 2020-05-25 21:49:08 +00:00
3f0b230d23 fix(core): update 2020-05-25 21:49:08 +00:00
42 changed files with 8962 additions and 17748 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -1,16 +1,16 @@
# gitzone ci_default
image: hosttoday/ht-docker-node:npmci
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@ -18,60 +18,66 @@ stages:
mirror:
stage: security
script:
- npmci git mirror
- npmci git mirror
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
snyk:
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
@ -81,31 +87,35 @@ codequality:
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
@ -113,5 +123,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${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"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

7
dist_ts/index.d.ts vendored
View File

@ -1,7 +0,0 @@
export * from './smarttime.classes.cronmanager';
export * from './smarttime.classes.extendeddate';
export * from './smarttime.classes.hrtmeasurement';
export * from './smarttime.classes.timer';
export * from './smarttime.classes.timestamp';
export * from './smarttime.units';
export { luxon } from './smarttime.plugins';

View File

@ -1,21 +0,0 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./smarttime.classes.cronmanager"), exports);
__exportStar(require("./smarttime.classes.extendeddate"), exports);
__exportStar(require("./smarttime.classes.hrtmeasurement"), exports);
__exportStar(require("./smarttime.classes.timer"), exports);
__exportStar(require("./smarttime.classes.timestamp"), exports);
__exportStar(require("./smarttime.units"), exports);
var smarttime_plugins_1 = require("./smarttime.plugins");
Object.defineProperty(exports, "luxon", { enumerable: true, get: function () { return smarttime_plugins_1.luxon; } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFFQSxrRUFBZ0Q7QUFDaEQsbUVBQWlEO0FBQ2pELHFFQUFtRDtBQUNuRCw0REFBMEM7QUFDMUMsZ0VBQThDO0FBQzlDLG9EQUFrQztBQUVsQyx5REFBNEM7QUFBbkMsMEdBQUEsS0FBSyxPQUFBIn0=

View File

@ -1,17 +0,0 @@
import { CronManager } from './smarttime.classes.cronmanager';
export declare type TJobFunction = (() => void) | (() => Promise<any>);
export declare class CronJob {
status: 'started' | 'stopped' | 'initial';
cronExpression: string;
jobFunction: TJobFunction;
private cronInterval;
private nextExecutionUnix;
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction);
/**
* checks wether the cronjob needs to be executed
*/
checkExecution(): void;
start(): void;
stop(): void;
private getCronInterval;
}

View File

@ -1,57 +0,0 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CronJob = void 0;
const plugins = __importStar(require("./smarttime.plugins"));
class CronJob {
constructor(cronManager, cronExpressionArg, jobFunction) {
this.status = 'initial';
this.cronInterval = plugins.cronParser.parseExpression('* * * * * *');
this.nextExecutionUnix = 0;
this.cronExpression = cronExpressionArg;
this.jobFunction = jobFunction;
}
/**
* checks wether the cronjob needs to be executed
*/
checkExecution() {
if (this.nextExecutionUnix === 0) {
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
return;
}
if (Date.now() > this.nextExecutionUnix) {
this.jobFunction();
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
}
}
start() {
this.cronInterval = this.getCronInterval();
this.status = 'started';
}
stop() {
this.status = 'stopped';
}
getCronInterval() {
return plugins.cronParser.parseExpression(this.cronExpression);
}
}
exports.CronJob = CronJob;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuY3JvbmpvYi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0dGltZS5jbGFzc2VzLmNyb25qb2IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDZEQUErQztBQUsvQyxNQUFhLE9BQU87SUFRbEIsWUFBWSxXQUF3QixFQUFFLGlCQUF5QixFQUFFLFdBQXlCO1FBUG5GLFdBQU0sR0FBc0MsU0FBUyxDQUFDO1FBSXJELGlCQUFZLEdBQUUsT0FBTyxDQUFDLFVBQVUsQ0FBQyxlQUFlLENBQUMsYUFBYSxDQUFDLENBQUM7UUFDaEUsc0JBQWlCLEdBQVcsQ0FBQyxDQUFDO1FBR3BDLElBQUksQ0FBQyxjQUFjLEdBQUcsaUJBQWlCLENBQUM7UUFDeEMsSUFBSSxDQUFDLFdBQVcsR0FBRyxXQUFXLENBQUM7SUFDakMsQ0FBQztJQUVEOztPQUVHO0lBQ0ksY0FBYztRQUNuQixJQUFJLElBQUksQ0FBQyxpQkFBaUIsS0FBSyxDQUFDLEVBQUU7WUFDaEMsSUFBSSxDQUFDLGlCQUFpQixHQUFHLElBQUksQ0FBQyxZQUFZLENBQUMsSUFBSSxFQUFFLENBQUMsTUFBTSxFQUFFLENBQUMsT0FBTyxFQUFFLENBQUM7WUFDckUsT0FBTztTQUNSO1FBQ0QsSUFBSSxJQUFJLENBQUMsR0FBRyxFQUFFLEdBQUcsSUFBSSxDQUFDLGlCQUFpQixFQUFFO1lBQ3ZDLElBQUksQ0FBQyxXQUFXLEVBQUUsQ0FBQztZQUNuQixJQUFJLENBQUMsaUJBQWlCLEdBQUcsSUFBSSxDQUFDLFlBQVksQ0FBQyxJQUFJLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxPQUFPLEVBQUUsQ0FBQztTQUN0RTtJQUNILENBQUM7SUFFTSxLQUFLO1FBQ1YsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUMsZUFBZSxFQUFFLENBQUM7UUFDM0MsSUFBSSxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUM7SUFDMUIsQ0FBQztJQUVNLElBQUk7UUFDVCxJQUFJLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQztJQUMxQixDQUFDO0lBRU8sZUFBZTtRQUNyQixPQUFPLE9BQU8sQ0FBQyxVQUFVLENBQUMsZUFBZSxDQUFDLElBQUksQ0FBQyxjQUFjLENBQUMsQ0FBQztJQUNqRSxDQUFDO0NBQ0Y7QUF2Q0QsMEJBdUNDIn0=

View File

@ -1,17 +0,0 @@
import { CronJob } from './smarttime.classes.cronjob';
import { Interval } from './smarttime.classes.interval';
export declare class CronManager {
cronInterval: Interval;
status: 'started' | 'stopped';
cronjobs: CronJob[];
constructor();
addCronjob(cronIdentifierArg: string, cronFunctionArg: () => any): void;
/**
* starts the cronjob
*/
start(): void;
/**
* stops all cronjobs
*/
stop(): void;
}

View File

@ -1,46 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CronManager = void 0;
const smarttime_classes_cronjob_1 = require("./smarttime.classes.cronjob");
const smarttime_classes_interval_1 = require("./smarttime.classes.interval");
class CronManager {
constructor() {
this.cronInterval = new smarttime_classes_interval_1.Interval(1000);
this.status = 'stopped';
this.cronjobs = [];
this.cronInterval.addIntervalJob(() => {
for (const cronJob of this.cronjobs) {
cronJob.checkExecution();
}
});
}
addCronjob(cronIdentifierArg, cronFunctionArg) {
const newCronJob = new smarttime_classes_cronjob_1.CronJob(this, cronIdentifierArg, cronFunctionArg);
this.cronjobs.push(newCronJob);
if (this.status === 'started') {
newCronJob.start();
}
}
/**
* starts the cronjob
*/
start() {
this.status = 'started';
for (const cron of this.cronjobs) {
cron.start();
}
this.cronInterval.start();
}
/**
* stops all cronjobs
*/
stop() {
this.status = 'stopped';
for (const cron of this.cronjobs) {
cron.stop();
}
this.cronInterval.stop();
}
}
exports.CronManager = CronManager;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuY3Jvbm1hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy5jcm9ubWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFDQSwyRUFBc0Q7QUFFdEQsNkVBQXdEO0FBRXhELE1BQWEsV0FBVztJQU10QjtRQUxPLGlCQUFZLEdBQUcsSUFBSSxxQ0FBUSxDQUFDLElBQUksQ0FBQyxDQUFDO1FBRWxDLFdBQU0sR0FBMEIsU0FBUyxDQUFDO1FBQzFDLGFBQVEsR0FBYyxFQUFFLENBQUM7UUFHOUIsSUFBSSxDQUFDLFlBQVksQ0FBQyxjQUFjLENBQUMsR0F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0 @@
export declare type TAvailableZone = 'Europe/Berlin';
export interface IDateUnits {
year: number;
yearString: string;
month: number;
monthString: string;
monthName: string;
day: number;
dayString: string;
dayOfTheWeek: number;
dayOfTheWeekName: string;
}
export declare class ExtendedDate extends Date {
static fromMillis(milliSeconds: number): ExtendedDate;
static fromDate(dateArg: Date): ExtendedDate;
static fromEuropeanDate(europeanDate: string): ExtendedDate;
/**
* creates an Extended date from a hypedDate like "2018-03-28"
* @param dateString
*/
static fromHyphedDate(dateString: string): ExtendedDate;
/**
* Same as .fromEuropeanDate(), but accepts additional timeArg and zoneArg
*/
static fromEuropeanDateAndTime(europeanDateArg: string, timeArg?: string, zoneArg?: TAvailableZone): ExtendedDate;
timezone: TAvailableZone;
constructor(unixMilli: number);
exportToEuropeanDate(): string;
/**
* exports units
*/
exportToUnits(): IDateUnits;
}

View File

@ -1,117 +0,0 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtendedDate = void 0;
const plugins = __importStar(require("./smarttime.plugins"));
class ExtendedDate extends Date {
constructor(unixMilli) {
super(unixMilli);
}
// STATIC factories
static fromMillis(milliSeconds) {
return new ExtendedDate(milliSeconds);
}
static fromDate(dateArg) {
return new ExtendedDate(dateArg.getTime());
}
static fromEuropeanDate(europeanDate) {
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate);
const luxonDate = plugins.luxon.DateTime.utc(parseFloat(dateArray[3]), // year
parseFloat(dateArray[2]), // month
parseFloat(dateArray[1]) // day
);
const unixMilli = luxonDate.toMillis();
return new ExtendedDate(unixMilli);
}
/**
* creates an Extended date from a hypedDate like "2018-03-28"
* @param dateString
*/
static fromHyphedDate(dateString) {
// guards
// implementation
const dateMillis = new Date(dateString).getTime();
return new ExtendedDate(dateMillis);
}
/**
* Same as .fromEuropeanDate(), but accepts additional timeArg and zoneArg
*/
static fromEuropeanDateAndTime(europeanDateArg, timeArg = '12:00:00', zoneArg = 'Europe/Berlin') {
// guards
// implementation
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDateArg);
const sliceDate = (dateString) => {
return `0${dateString}`.slice(-2);
};
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();
return new ExtendedDate(unixMilli);
}
//
exportToEuropeanDate() {
const units = this.exportToUnits();
return `${units.dayString}.${units.monthString}.${units.yearString}`;
}
/**
* exports units
*/
exportToUnits() {
const monthsArray = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
const daysArray = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
];
return {
year: this.getFullYear(),
yearString: `${this.getFullYear()}`,
month: this.getMonth() + 1,
monthString: ("0" + (this.getMonth() + 1)).slice(-2),
monthName: monthsArray[this.getMonth()],
day: this.getDate(),
dayString: ("0" + this.getDate()).slice(-2),
dayOfTheWeek: this.getDay(),
dayOfTheWeekName: daysArray[this.getDay()]
};
}
}
exports.ExtendedDate = ExtendedDate;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuZXh0ZW5kZ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UsV0FBVyxDQUFDLElBQUksQ0FBQyxRQUFRLEVBQUUsQ0FBQztZQUN2QyxHQUFHLEVBQUUsSUFBSSxDQUFDLE9BQU8sRUFBRTtZQUNuQixTQUFTLEVBQUUsQ0FBQyxHQUFHLEdBQUcsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBQzNDLFlBQVksRUFBRSxJQUFJLENBQUMsTUFBTSxFQUFFO1lBQzNCLGdCQUFnQixFQUFFLFNBQVMsQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUM7U0FDM0MsQ0FBQztJQUNKLENBQUM7Q0FDRjtBQTlHRCxvQ0E4R0MifQ==

View File

@ -1,22 +0,0 @@
/**
* easy high resolution time measurement
*/
export declare class HrtMeasurement {
nanoSeconds: number;
milliSeconds: number;
private _hrTimeStart;
private _hrTimeStopDiff;
private _started;
/**
* start the measurement
*/
start(): void;
/**
* stop the measurement
*/
stop(): this;
/**
* reset the measurement
*/
reset(): void;
}

View File

@ -1,47 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HrtMeasurement = void 0;
/**
* easy high resolution time measurement
*/
class HrtMeasurement {
constructor() {
this.nanoSeconds = null;
this.milliSeconds = null;
this._hrTimeStart = null;
this._hrTimeStopDiff = null;
this._started = false;
}
/**
* start the measurement
*/
start() {
this._started = true;
this._hrTimeStart = process.hrtime();
}
/**
* stop the measurement
*/
stop() {
if (this._started === false) {
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;
return this;
}
/**
* reset the measurement
*/
reset() {
this.nanoSeconds = null;
this.milliSeconds = null;
this._hrTimeStart = null;
this._hrTimeStopDiff = null;
this._started = false;
}
}
exports.HrtMeasurement = HrtMeasurement;
//# sourceMapping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BSSxDQUFDLFdBQVcsR0FBRyxPQUFPLENBQUM7UUFDL0MsT0FBTyxJQUFJLENBQUM7SUFDZCxDQUFDO0lBRUQ7O09BRUc7SUFDSSxLQUFLO1FBQ1YsSUFBSSxDQUFDLFdBQVcsR0FBRyxJQUFJLENBQUM7UUFDeEIsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUM7UUFDekIsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUM7UUFDekIsSUFBSSxDQUFDLGVBQWUsR0FBRyxJQUFJLENBQUM7UUFDNUIsSUFBSSxDQUFDLFFBQVEsR0FBRyxLQUFLLENBQUM7SUFDeEIsQ0FBQztDQUNGO0FBdkNELHdDQXVDQyJ9

View File

@ -1,11 +0,0 @@
export declare class Interval {
status: 'started' | 'stopped' | 'initial';
private statusAuthorization;
intervalMilliseconds: number;
intervalJobs: Array<() => any>;
constructor(intervalMillisencondsArg: number);
start(): void;
stop(): void;
addIntervalJob(funcArg: () => any): void;
private executeIntervalJobs;
}

View File

@ -1,57 +0,0 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Interval = void 0;
const plugins = __importStar(require("./smarttime.plugins"));
class Interval {
constructor(intervalMillisencondsArg) {
this.status = 'initial';
this.statusAuthorization = null;
this.intervalJobs = [];
this.intervalMilliseconds = intervalMillisencondsArg;
}
start() {
this.status = 'started';
const statusAuth = new Date();
this.statusAuthorization = statusAuth;
const runInterval = async () => {
while (this.status === 'started' && this.statusAuthorization === statusAuth) {
await plugins.smartdelay.delayFor(this.intervalMilliseconds);
this.executeIntervalJobs();
}
};
runInterval();
}
stop() {
this.status = 'stopped';
this.statusAuthorization = null;
}
addIntervalJob(funcArg) {
this.intervalJobs.push(funcArg);
}
executeIntervalJobs() {
for (const funcArg of this.intervalJobs) {
funcArg();
}
}
}
exports.Interval = Interval;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuaW50ZXJ2YWwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy5pbnRlcnZhbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsNkRBQStDO0FBRS9DLE1BQWEsUUFBUTtJQU1uQixZQUFZLHdCQUFnQztRQUxyQyxXQUFNLEdBQXNDLFNBQVMsQ0FBQztRQUNyRCx3QkFBbUIsR0FBUSxJQUFJLENBQUM7UUFHakMsaUJBQVksR0FBcUIsRUFBRSxDQUFDO1FBRXpDLElBQUksQ0FBQyxvQkFBb0IsR0FBRyx3QkFBd0IsQ0FBQztJQUN2RCxDQUFDO0lBRU0sS0FBSztRQUNWLElBQUksQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDO1FBQ3hCLE1BQU0sVUFBVSxHQUFHLElBQUksSUFBSSxFQUFFLENBQUM7UUFDOUIsSUFBSSxDQUFDLG1CQUFtQixHQUFHLFVBQVUsQ0FBQztRQUN0QyxNQUFNLFdBQVcsR0FBRyxLQUFLLElBQUksRUFBRTtZQUM3QixPQUFPLElBQUksQ0FBQyxNQUFNLEtBQUssU0FBUyxJQUFJLElBQUksQ0FBQyxtQkFBbUIsS0FBSyxVQUFVLEVBQUU7Z0JBQzNFLE1BQU0sT0FBTyxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLG9CQUFvQixDQUFDLENBQUM7Z0JBQzdELElBQUksQ0FBQyxtQkFBbUIsRUFBRSxDQUFDO2FBQzVCO1FBQ0gsQ0FBQyxDQUFDO1FBQ0YsV0FBVyxFQUFFLENBQUM7SUFDaEIsQ0FBQztJQUVNLElBQUk7UUFDVCxJQUFJLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQztRQUN4QixJQUFJLENBQUMsbUJBQW1CLEdBQUcsSUFBSSxDQUFDO0lBQ2xDLENBQUM7SUFFTSxjQUFjLENBQUMsT0FBa0I7UUFDdEMsSUFBSSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDbEMsQ0FBQztJQUVPLG1CQUFtQjtRQUN6QixLQUFLLE1BQU0sT0FBTyxJQUFJLElBQUksQ0FBQyxZQUFZLEVBQUU7WUFDdkMsT0FBTyxFQUFFLENBQUM7U0FDWDtJQUNILENBQUM7Q0FDRjtBQXJDRCw0QkFxQ0MifQ==

View File

@ -1,38 +0,0 @@
import { TimeStamp } from './smarttime.classes.timestamp';
export declare type TimerState = 'initiated' | 'started' | 'paused' | 'completed';
export declare class Timer {
/**
* the original amount of milliseconds for this Timer
*/
timeInMilliseconds: number;
/**
* the state of the timer
*/
state: TimerState;
/**
* completed Promise
*/
completed: Promise<void>;
/**
* a reference to when the Timeout started
*/
startedAt: TimeStamp;
/**
* a reference to when a Timer has been potentially paused
*/
pausedAt: TimeStamp;
get timeLeft(): number;
/**
* the current timeout the needs to be canceled when this Timer is stopped
*/
private currentTimeout;
private completedDeferred;
constructor(timeInMillisecondsArg: number);
/**
* starts the timer
*/
start(): void;
pause(): void;
resume(): void;
reset(): void;
}

View File

@ -1,77 +0,0 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Timer = void 0;
const plugins = __importStar(require("./smarttime.plugins"));
const smarttime_classes_timestamp_1 = require("./smarttime.classes.timestamp");
class Timer {
constructor(timeInMillisecondsArg) {
/**
* the state of the timer
*/
this.state = 'initiated';
// a deferred triggeted when Timer has completed
this.completedDeferred = plugins.smartpromise.defer();
this.timeInMilliseconds = timeInMillisecondsArg;
this.completed = this.completedDeferred.promise;
}
get timeLeft() {
return this.timeInMilliseconds - this.pausedAt.change;
}
/**
* starts the timer
*/
start() {
if (!this.startedAt) {
this.currentTimeout = setTimeout(() => {
this.completedDeferred.resolve();
}, this.timeInMilliseconds);
this.startedAt = new smarttime_classes_timestamp_1.TimeStamp();
}
else {
throw new Error('timer has been started before. Please use resume instead');
}
}
pause() {
if (this.startedAt) {
clearTimeout(this.currentTimeout);
this.currentTimeout = null;
this.pausedAt = smarttime_classes_timestamp_1.TimeStamp.fromTimeStamp(this.startedAt);
}
}
resume() {
if (this.startedAt) {
this.currentTimeout = setTimeout(() => {
this.completedDeferred.resolve();
}, this.timeLeft);
}
else {
throw new Error('timer has NOT been started before. Please use .start() instead');
}
}
reset() {
this.pause();
this.startedAt = null;
this.pausedAt = null;
}
}
exports.Timer = Timer;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYX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QztJQUVNLEtBQUs7UUFDVixJQUFJLElBQUksQ0FBQyxTQUFTLEVBQUU7WUFDbEIsWUFBWSxDQUFDLElBQUksQ0FBQyxjQUFjLENBQUMsQ0FBQztZQUNsQyxJQUFJLENBQUMsY0FBYyxHQUFHLElBQUksQ0FBQztZQUMzQixJQUFJLENBQUMsUUFBUSxHQUFHLHVDQUFTLENBQUMsYUFBYSxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQztTQUN6RDtJQUNILENBQUM7SUFFTSxNQUFNO1FBQ1gsSUFBSSxJQUFJLENBQUMsU0FBUyxFQUFFO1lBQ2xCLElBQUksQ0FBQyxjQUFjLEdBQUcsVUFBVSxDQUFDLEdBQUcsRUFBRTtnQkFDcEMsSUFBSSxDQUFDLGlCQUFpQixDQUFDLE9BQU8sRUFBRSxDQUFDO1lBQ25DLENBQUMsRUFBRSxJQUFJLENBQUMsUUFBUSxDQUFDLENBQUM7U0FDbkI7YUFBTTtZQUNMLE1BQU0sSUFBSSxLQUFLLENBQUMsZ0VBQWdFLENBQUMsQ0FBQztTQUNuRjtJQUNILENBQUM7SUFFTSxLQUFLO1FBQ1YsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ2IsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUM7UUFDdEIsSUFBSSxDQUFDLFFBQVEsR0FBRyxJQUFJLENBQUM7SUFDdkIsQ0FBQztDQUNGO0FBL0VELHNCQStFQyJ9

View File

@ -1,45 +0,0 @@
/**
* TimeStamp
* smart timestamp
*/
export declare class TimeStamp {
/**
* 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;
/**
* The standard JavaScript Date
*/
date: Date;
/**
* The time as linux time (milliseconds, not seconds though)
* good for comparison
*/
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);
/**
* Is the current instance older than the argument
* @param TimeStampArg
*/
isOlderThan(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
/**
* returns a boolean for wether a timestamp is younger
* @param TimeStampArg
* @param tresholdTimeArg
*/
isYoungerThanOtherTimeStamp(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
isYoungerThanMilliSeconds(millisecondArg: number): boolean;
}

View File

@ -1,71 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeStamp = void 0;
/**
* TimeStamp
* smart timestamp
*/
class TimeStamp {
constructor(creatorArg) {
/**
* if derived from another TimeStamp points out the change in milliseconds
*/
this.change = null;
if (!creatorArg) {
this.date = new Date();
}
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) {
const localTimeStamp = new TimeStamp();
localTimeStamp.change = localTimeStamp.milliSeconds - timeStampArg.milliSeconds;
return localTimeStamp;
}
/**
* Is the current instance older than the argument
* @param TimeStampArg
*/
isOlderThan(TimeStampArg, tresholdTimeArg = 0) {
if (this.milliSeconds + tresholdTimeArg < TimeStampArg.milliSeconds) {
return true;
}
else {
return false;
}
}
/**
* returns a boolean for wether a timestamp is younger
* @param TimeStampArg
* @param tresholdTimeArg
*/
isYoungerThanOtherTimeStamp(TimeStampArg, tresholdTimeArg = 0) {
if (this.milliSeconds > TimeStampArg.milliSeconds + tresholdTimeArg) {
return true;
}
else {
return false;
}
}
isYoungerThanMilliSeconds(millisecondArg) {
const nowTimeStamp = new TimeStamp();
const compareEpochTime = nowTimeStamp.epochtime - millisecondArg;
const compareTimeStamp = new TimeStamp(compareEpochTime);
return this.isYoungerThanOtherTimeStamp(compareTimeStamp);
}
}
exports.TimeStamp = TimeStamp;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUVBOzs7R0FHRztBQUNILE1BQWEsU0FBUztJQXVDcEIsWUFBWSxVQUFtQjtRQUwvQjs7V0FFRztRQUNJLFdBQU0sR0FBVyxJQUFJLENBQUM7UUFHM0IsSUFBSSxDQUFDLFVBQVUsRUFBRTtZQUNmLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQztTQUN4QjthQUFNLElBQUksT0FBTyxVQUFVLEtBQUssUUFBUSxFQUFFO1lBQ3pDLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUM7U0FDbEM7UUFDRCxJQUFJLENBQUMsWUFBWSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDeEMsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQUFDLENBQUM7SUFDeEQsQ0FBQztJQTlDRDs7T0FFRztJQUNJLE1BQU0sQ0FBQyxnQkFBZ0IsQ0FBQyxlQUFlO1FBQzVDLE9BQU8sSUFBSSxTQUFTLENBQUMsZUFBZSxDQUFDLENBQUM7SUFDeEMsQ0FBQztJQUVEOzs7T0FHRztJQUNJLE1BQU0sQ0FBQyxhQUFhLENBQUMsWUFBdUI7UUFDakQsTUFBTSxjQUFjLEdBQUcsSUFBSSxTQUFTLEVBQUUsQ0FBQztRQUN2QyxjQUFjLENBQUMsTUFBTSxHQUFHLGNBQWMsQ0FBQyxZQUFZLEdBQUcsWUFBWSxDQUFDLFlBQVksQ0FBQztRQUNoRixPQUFPLGNBQWMsQ0FBQztJQUN4QixDQUFDO0lBaUNEOzs7T0FHRztJQUNJLFdBQVcsQ0FBQyxZQUF1QixFQUFFLGtCQUEwQixDQUFDO1FBQ3JFLElBQUksSUFBSSxDQUFDLFlBQVksR0FBRyxlQUFlLEdBQUcsWUFBWSxDQUFDLFlBQVksRUFBRTtZQUNuRSxPQUFPLElBQUksQ0FBQztTQUNiO2FBQU07WUFDTCxPQUFPLEtBQUssQ0FBQztTQUNkO0lBQ0gsQ0FBQztJQUVEOzs7O09BSUc7SUFDSSwyQkFBMkIsQ0FBQyxZQUF1QixFQUFFLGtCQUEwQixDQUFDO1FBQ3JGLElBQUksSUFBSSxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUMsWUFBWSxHQUFHLGVBQWUsRUFBRTtZQUNuRSxPQUFPLElBQUksQ0FBQztTQUNiO2FBQU07WUFDTCxPQUFPLEtBQUssQ0FBQztTQUNkO0lBQ0gsQ0FBQztJQUVNLHlCQUF5QixDQUFDLGNBQXNCO1FBQ3JELE1BQU0sWUFBWSxHQUFHLElBQUksU0FBUyxFQUFFLENBQUM7UUFDckMsTUFBTSxnQkFBZ0IsR0FBRyxZQUFZLENBQUMsU0FBUyxHQUFHLGNBQWMsQ0FBQztRQUNqRSxNQUFNLGdCQUFnQixHQUFHLElBQUksU0FBUyxDQUFDLGdCQUFnQixDQUFDLENBQUM7UUFDekQsT0FBTyxJQUFJLENBQUMsMkJBQTJCLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztJQUM1RCxDQUFDO0NBQ0Y7QUFoRkQsOEJBZ0ZDIn0=

View File

@ -1,6 +0,0 @@
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
export { smartdelay, smartpromise };
import cronParser from 'cron-parser';
import * as luxon from 'luxon';
export { cronParser, luxon };

View File

@ -1,36 +0,0 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.luxon = exports.cronParser = exports.smartpromise = exports.smartdelay = void 0;
// @pushrocks scope
const smartdelay = __importStar(require("@pushrocks/smartdelay"));
exports.smartdelay = smartdelay;
const smartpromise = __importStar(require("@pushrocks/smartpromise"));
exports.smartpromise = smartpromise;
// third parties
const cron_parser_1 = __importDefault(require("cron-parser"));
exports.cronParser = cron_parser_1.default;
const luxon = __importStar(require("luxon"));
exports.luxon = luxon;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsbUJBQW1CO0FBQ25CLGtFQUFvRDtBQUczQyxnQ0FBVTtBQUZuQixzRUFBd0Q7QUFFbkMsb0NBQVk7QUFFakMsZ0JBQWdCO0FBQ2hCLDhEQUFxQztBQUc1QixxQkFIRixxQkFBVSxDQUdFO0FBRm5CLDZDQUErQjtBQUVWLHNCQUFLIn0=

View File

@ -1,17 +0,0 @@
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;

View File

@ -1,49 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMilliSecondsFromUnits = exports.units = void 0;
exports.units = {
years: (timesArg = 1) => {
return timesArg * 3.154e10;
},
months: (timesArg = 1) => {
return timesArg * 2.628e9;
},
weeks: (timesArg = 1) => {
return timesArg * 6.048e8;
},
days: (timesArg = 1) => {
return timesArg * 8.64e7;
},
hours: (timesArg = 1) => {
return timesArg * 3.6e6;
},
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnVuaXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4v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LQUFLLEVBQUU7UUFDeEIsZUFBZSxDQUFDLGFBQUssQ0FBQyxLQUFLLENBQUMsY0FBYyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7S0FDcEQ7SUFDRCxJQUFJLGNBQWMsQ0FBQyxNQUFNLEVBQUU7UUFDekIsZUFBZSxDQUFDLGFBQUssQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7S0FDdEQ7SUFDRCxJQUFJLGNBQWMsQ0FBQyxLQUFLLEVBQUU7UUFDeEIsZUFBZSxDQUFDLGFBQUssQ0FBQyxLQUFLLENBQUMsY0FBYyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7S0FDcEQ7SUFDRCxJQUFJLGNBQWMsQ0FBQyxJQUFJLEVBQUU7UUFDdkIsZUFBZSxDQUFDLGFBQUssQ0FBQyxJQUFJLENBQUMsY0FBYyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUM7S0FDbEQ7SUFDRCxJQUFJLGNBQWMsQ0FBQyxLQUFLLEVBQUU7UUFDeEIsZUFBZSxDQUFDLGFBQUssQ0FBQyxLQUFLLENBQUMsY0FBYyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7S0FDcEQ7SUFDRCxJQUFJLGNBQWMsQ0FBQyxPQUFPLEVBQUU7UUFDMUIsZUFBZSxDQUFDLGFBQUssQ0FBQyxPQUFPLENBQUMsY0FBYyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUM7S0FDeEQ7SUFFRCxPQUFPLGtCQUFrQixDQUFDO0FBQzVCLENBQUMsQ0FBQyJ9

21
license Normal file
View 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.

View File

@ -4,6 +4,7 @@
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",

9356
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +1,47 @@
{
"name": "@pushrocks/smarttime",
"private": false,
"version": "3.0.13",
"version": "3.0.24",
"description": "handle time in smart ways",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest ./test/)",
"build": "(tsbuild && tsbundle npm)"
"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",
"@gitzone/tsbundle": "^1.0.72",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.41",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.22",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/lik": "^4.0.13",
"@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.29",
"is-nan": "^1.3.0"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"assets/*",
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -8,13 +8,20 @@ handle time in smart ways
* [docs (typedoc)](https://pushrocks.gitlab.io/smarttime/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smarttime/badges/master/build.svg)](https://gitlab.com/pushrocks/smarttime/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smarttime/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smarttime/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smarttime.svg)](https://www.npmjs.com/package/@pushrocks/smarttime)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smarttime/badge.svg)](https://snyk.io/test/npm/@pushrocks/smarttime)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smarttime/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smarttime/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smarttime)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smarttime)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smarttime)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smarttime)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smarttime)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
@ -23,6 +30,7 @@ Use TypeScript for best in class instellisense.
Smarttime offers smart ways to deal with time.
### class CronManager
This class provides scheduling of functions with a cron syntax
```typescript
@ -30,11 +38,12 @@ import { CronManager } from '@pushrocks/smarrtime';
const cronManagerInstance = new CronManager();
cronManagerInstance.addConrjob('* * * * * *', async () => {
console.log('hello'); // will log 'hello' to console once every second;
})
});
cronManagerInstance.start();
```
### class ExtendedDate
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
```TypeScript
@ -42,9 +51,13 @@ 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). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View 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 * * * * *', () => {
if (counter === 10) {
done.resolve();
}
counter++;
console.log(`hey ${counter}`);
});
testCronManager.start();
await done.promise;
testCronManager.stop();
});
tap.start();

View File

@ -9,10 +9,10 @@ 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();
let counter = 0;
testCronManager.addCronjob('* * * * * *', () => {
testCronManager.addCronjob('*/2 * * * * *', () => {
if (counter === 10) {
done.resolve();
}

View File

@ -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);

View File

@ -1,10 +1,8 @@
import * as plugins from './smarttime.plugins';
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';
export { luxon } from './smarttime.plugins';

View File

@ -1,45 +1,40 @@
import * as plugins from './smarttime.plugins';
import { CronManager } from './smarttime.classes.cronmanager';
export type TJobFunction = (() => void) | (() => Promise<any>);
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 ) {
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.nextExecutionUnix = this.croner.msToNext();
}
if (Date.now() > this.nextExecutionUnix) {
this.jobFunction();
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
this.nextExecutionUnix = this.croner.msToNext();
}
return this.nextExecutionUnix;
}
public start() {
this.cronInterval = this.getCronInterval();
this.status = 'started';
}
public stop() {
this.status = 'stopped';
}
private getCronInterval () {
return plugins.cronParser.parseExpression(this.cronExpression);
}
}
}

View File

@ -1,39 +1,63 @@
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) {
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();
}
this.executionTimeout = new plugins.smartdelay.Timeout(0);
// recursion
const runCheckExecution = () => {
console.log(
`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`
);
this.executionTimeout.promise.then(() => {
let timeToNextOverallExecution: number;
for (const cronJob of this.cronjobs.getArray()) {
const timeToNextJobExecution = cronJob.checkExecution();
if (
timeToNextJobExecution < timeToNextOverallExecution ||
!timeToNextOverallExecution
) {
timeToNextOverallExecution = timeToNextJobExecution;
}
}
this.executionTimeout = new plugins.smartdelay.Timeout(timeToNextOverallExecution);
runCheckExecution();
});
};
runCheckExecution();
}
this.cronInterval.start();
}
/**
@ -41,9 +65,9 @@ export class CronManager {
*/
public stop() {
this.status = 'stopped';
for (const cron of this.cronjobs) {
this.executionTimeout.cancel();
for (const cron of this.cronjobs.getArray()) {
cron.stop();
}
this.cronInterval.stop();
}
}

View File

@ -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,17 +64,14 @@ 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);
}
// INSTANCE
public timezone: TAvailableZone;
constructor(unixMilli: number) {
super(unixMilli);
}
@ -101,7 +98,7 @@ export class ExtendedDate extends Date {
'September',
'October',
'November',
'December'
'December',
];
const daysArray = [
'Monday',
@ -110,18 +107,18 @@ export class ExtendedDate extends Date {
'Thursday',
'Friday',
'Saturday',
'Sunday'
'Sunday',
];
return {
year: this.getFullYear(),
yearString: `${this.getFullYear()}`,
month: this.getMonth() + 1,
monthString: ("0" + (this.getMonth() + 1)).slice(-2),
monthString: ('0' + (this.getMonth() + 1)).slice(-2),
monthName: monthsArray[this.getMonth()],
day: this.getDate(),
dayString: ("0" + this.getDate()).slice(-2),
dayString: ('0' + this.getDate()).slice(-2),
dayOfTheWeek: this.getDay(),
dayOfTheWeekName: daysArray[this.getDay()]
dayOfTheWeekName: daysArray[this.getDay()],
};
}
}

View File

@ -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;
}
}

View File

@ -3,8 +3,11 @@ import * as plugins from './smarttime.plugins';
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;
@ -23,7 +26,7 @@ export class Interval {
runInterval();
}
public stop () {
public stop() {
this.status = 'stopped';
this.statusAuthorization = null;
}
@ -32,9 +35,9 @@ export class Interval {
this.intervalJobs.push(funcArg);
}
private executeIntervalJobs () {
private executeIntervalJobs() {
for (const funcArg of this.intervalJobs) {
funcArg();
}
}
}
}

View File

@ -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 };

View File

@ -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) {