@push.rocks/smarttime 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_bundle/bundle.js +15434 -0
- package/dist_bundle/bundle.js.map +7 -0
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/index.d.ts +8 -0
- package/dist_ts/index.js +9 -0
- package/dist_ts/smarttime.classes.cronjob.d.ts +22 -0
- package/dist_ts/smarttime.classes.cronjob.js +44 -0
- package/dist_ts/smarttime.classes.cronmanager.d.ts +18 -0
- package/dist_ts/smarttime.classes.cronmanager.js +71 -0
- package/dist_ts/smarttime.classes.cronparser.d.ts +7 -0
- package/dist_ts/smarttime.classes.cronparser.js +74 -0
- package/dist_ts/smarttime.classes.extendeddate.d.ts +42 -0
- package/dist_ts/smarttime.classes.extendeddate.js +114 -0
- package/dist_ts/smarttime.classes.hrtmeasurement.d.ts +22 -0
- package/dist_ts/smarttime.classes.hrtmeasurement.js +43 -0
- package/dist_ts/smarttime.classes.interval.d.ts +12 -0
- package/dist_ts/smarttime.classes.interval.js +34 -0
- package/dist_ts/smarttime.classes.timer.d.ts +38 -0
- package/dist_ts/smarttime.classes.timer.js +54 -0
- package/dist_ts/smarttime.classes.timestamp.d.ts +51 -0
- package/dist_ts/smarttime.classes.timestamp.js +81 -0
- package/dist_ts/smarttime.plugins.d.ts +8 -0
- package/dist_ts/smarttime.plugins.js +13 -0
- package/dist_ts/smarttime.units.d.ts +18 -0
- package/dist_ts/smarttime.units.js +50 -0
- package/license +21 -0
- package/npmextra.json +17 -0
- package/package.json +48 -0
- package/readme.md +63 -0
- package/ts/00_commitinfo_data.ts +8 -0
- package/ts/index.ts +8 -0
- package/ts/smarttime.classes.cronjob.ts +58 -0
- package/ts/smarttime.classes.cronmanager.ts +85 -0
- package/ts/smarttime.classes.cronparser.ts +88 -0
- package/ts/smarttime.classes.extendeddate.ts +151 -0
- package/ts/smarttime.classes.hrtmeasurement.ts +43 -0
- package/ts/smarttime.classes.interval.ts +43 -0
- package/ts/smarttime.classes.timer.ts +86 -0
- package/ts/smarttime.classes.timestamp.ts +100 -0
- package/ts/smarttime.plugins.ts +16 -0
- package/ts/smarttime.units.ts +62 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as plugins from './smarttime.plugins.js';
|
|
2
|
+
import { TimeStamp } from './smarttime.classes.timestamp.js';
|
|
3
|
+
export class Timer {
|
|
4
|
+
get timeLeft() {
|
|
5
|
+
return this.timeInMilliseconds - this.pausedAt.change;
|
|
6
|
+
}
|
|
7
|
+
constructor(timeInMillisecondsArg) {
|
|
8
|
+
/**
|
|
9
|
+
* the state of the timer
|
|
10
|
+
*/
|
|
11
|
+
this.state = 'initiated';
|
|
12
|
+
// a deferred triggeted when Timer has completed
|
|
13
|
+
this.completedDeferred = plugins.smartpromise.defer();
|
|
14
|
+
this.timeInMilliseconds = timeInMillisecondsArg;
|
|
15
|
+
this.completed = this.completedDeferred.promise;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* starts the timer
|
|
19
|
+
*/
|
|
20
|
+
start() {
|
|
21
|
+
if (!this.startedAt) {
|
|
22
|
+
this.currentTimeout = setTimeout(() => {
|
|
23
|
+
this.completedDeferred.resolve();
|
|
24
|
+
}, this.timeInMilliseconds);
|
|
25
|
+
this.startedAt = new TimeStamp();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error('timer has been started before. Please use resume instead');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
pause() {
|
|
32
|
+
if (this.startedAt) {
|
|
33
|
+
clearTimeout(this.currentTimeout);
|
|
34
|
+
this.currentTimeout = null;
|
|
35
|
+
this.pausedAt = TimeStamp.fromTimeStamp(this.startedAt);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
resume() {
|
|
39
|
+
if (this.startedAt) {
|
|
40
|
+
this.currentTimeout = setTimeout(() => {
|
|
41
|
+
this.completedDeferred.resolve();
|
|
42
|
+
}, this.timeLeft);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error('timer has NOT been started before. Please use .start() instead');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
reset() {
|
|
49
|
+
this.pause();
|
|
50
|
+
this.startedAt = null;
|
|
51
|
+
this.pausedAt = null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy50aW1lci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLHdCQUF3QixDQUFDO0FBRWxELE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxrQ0FBa0MsQ0FBQztBQUk3RCxNQUFNLE9BQU8sS0FBSztJQTBCaEIsSUFBSSxRQUFRO1FBQ1YsT0FBTyxJQUFJLENBQUMsa0JBQWtCLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUM7SUFDeEQsQ0FBQztJQVNELFlBQVkscUJBQTZCO1FBL0J6Qzs7V0FFRztRQUNJLFVBQUssR0FBZSxXQUFXLENBQUM7UUF5QnZDLGdEQUFnRDtRQUN4QyxzQkFBaUIsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLEtBQUssRUFBUSxDQUFDO1FBRzdELElBQUksQ0FBQyxrQkFBa0IsR0FBRyxxQkFBcUIsQ0FBQztRQUNoRCxJQUFJLENBQUMsU0FBUyxHQUFHLElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxPQUFPLENBQUM7SUFDbEQsQ0FBQztJQUVEOztPQUVHO0lBQ0ksS0FBSztRQUNWLElBQUksQ0FBQyxJQUFJ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BSSxDQUFDLFFBQVEsR0FBRyxJQUFJLENBQUM7SUFDdkIsQ0FBQztDQUNGIn0=
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimeStamp
|
|
3
|
+
* smart timestamp
|
|
4
|
+
*/
|
|
5
|
+
export declare class TimeStamp {
|
|
6
|
+
/**
|
|
7
|
+
* returns new TimeStamp from milliseconds
|
|
8
|
+
*/
|
|
9
|
+
static fromMilliSeconds(milliSecondsArg: number): TimeStamp;
|
|
10
|
+
/**
|
|
11
|
+
* returns new TimeStamp for now with change set
|
|
12
|
+
* @param timeStampArg
|
|
13
|
+
*/
|
|
14
|
+
static fromTimeStamp(timeStampArg: TimeStamp): TimeStamp;
|
|
15
|
+
/**
|
|
16
|
+
* The standard JavaScript Date
|
|
17
|
+
*/
|
|
18
|
+
date: Date;
|
|
19
|
+
/**
|
|
20
|
+
* The time as linux time (milliseconds, not seconds though)
|
|
21
|
+
* good for comparison
|
|
22
|
+
*/
|
|
23
|
+
milliSeconds: number;
|
|
24
|
+
/**
|
|
25
|
+
* The standard epoch time in seconds
|
|
26
|
+
*/
|
|
27
|
+
epochtime: number;
|
|
28
|
+
/**
|
|
29
|
+
* if derived from another TimeStamp points out the change in milliseconds
|
|
30
|
+
*/
|
|
31
|
+
change: number;
|
|
32
|
+
constructor(creatorArg?: number);
|
|
33
|
+
/**
|
|
34
|
+
* returns a boolean for wether the timestamp is older than another timestamp
|
|
35
|
+
* @param TimeStampArg
|
|
36
|
+
* @param tresholdTimeArg
|
|
37
|
+
*/
|
|
38
|
+
isOlderThanOtherTimeStamp(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Is the current instance older than the argument
|
|
41
|
+
* @param TimeStampArg
|
|
42
|
+
*/
|
|
43
|
+
isOlderThan(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* returns a boolean for wether the timestamp is younger than another timestamp
|
|
46
|
+
* @param TimeStampArg
|
|
47
|
+
* @param tresholdTimeArg
|
|
48
|
+
*/
|
|
49
|
+
isYoungerThanOtherTimeStamp(TimeStampArg: TimeStamp, tresholdTimeArg?: number): boolean;
|
|
50
|
+
isYoungerThanMilliSeconds(millisecondArg: number): boolean;
|
|
51
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import './smarttime.plugins.js';
|
|
2
|
+
/**
|
|
3
|
+
* TimeStamp
|
|
4
|
+
* smart timestamp
|
|
5
|
+
*/
|
|
6
|
+
export class TimeStamp {
|
|
7
|
+
/**
|
|
8
|
+
* returns new TimeStamp from milliseconds
|
|
9
|
+
*/
|
|
10
|
+
static fromMilliSeconds(milliSecondsArg) {
|
|
11
|
+
return new TimeStamp(milliSecondsArg);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* returns new TimeStamp for now with change set
|
|
15
|
+
* @param timeStampArg
|
|
16
|
+
*/
|
|
17
|
+
static fromTimeStamp(timeStampArg) {
|
|
18
|
+
const localTimeStamp = new TimeStamp();
|
|
19
|
+
localTimeStamp.change = localTimeStamp.milliSeconds - timeStampArg.milliSeconds;
|
|
20
|
+
return localTimeStamp;
|
|
21
|
+
}
|
|
22
|
+
constructor(creatorArg) {
|
|
23
|
+
/**
|
|
24
|
+
* if derived from another TimeStamp points out the change in milliseconds
|
|
25
|
+
*/
|
|
26
|
+
this.change = null;
|
|
27
|
+
if (!creatorArg) {
|
|
28
|
+
this.date = new Date();
|
|
29
|
+
}
|
|
30
|
+
else if (typeof creatorArg === 'number') {
|
|
31
|
+
this.date = new Date(creatorArg);
|
|
32
|
+
}
|
|
33
|
+
this.milliSeconds = this.date.getTime();
|
|
34
|
+
this.epochtime = Math.floor(this.milliSeconds / 1000);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* returns a boolean for wether the timestamp is older than another timestamp
|
|
38
|
+
* @param TimeStampArg
|
|
39
|
+
* @param tresholdTimeArg
|
|
40
|
+
*/
|
|
41
|
+
isOlderThanOtherTimeStamp(TimeStampArg, tresholdTimeArg = 0) {
|
|
42
|
+
if (this.milliSeconds < TimeStampArg.milliSeconds - tresholdTimeArg) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Is the current instance older than the argument
|
|
51
|
+
* @param TimeStampArg
|
|
52
|
+
*/
|
|
53
|
+
isOlderThan(TimeStampArg, tresholdTimeArg = 0) {
|
|
54
|
+
if (this.milliSeconds + tresholdTimeArg < TimeStampArg.milliSeconds) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* returns a boolean for wether the timestamp is younger than another timestamp
|
|
63
|
+
* @param TimeStampArg
|
|
64
|
+
* @param tresholdTimeArg
|
|
65
|
+
*/
|
|
66
|
+
isYoungerThanOtherTimeStamp(TimeStampArg, tresholdTimeArg = 0) {
|
|
67
|
+
if (this.milliSeconds > TimeStampArg.milliSeconds + tresholdTimeArg) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
isYoungerThanMilliSeconds(millisecondArg) {
|
|
75
|
+
const nowTimeStamp = new TimeStamp();
|
|
76
|
+
const compareEpochTime = nowTimeStamp.epochtime - millisecondArg;
|
|
77
|
+
const compareTimeStamp = new TimeStamp(compareEpochTime);
|
|
78
|
+
return this.isYoungerThanOtherTimeStamp(compareTimeStamp);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdX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 @@
|
|
|
1
|
+
import * as lik from '@pushrocks/lik';
|
|
2
|
+
import * as smartdelay from '@pushrocks/smartdelay';
|
|
3
|
+
import * as smartpromise from '@pushrocks/smartpromise';
|
|
4
|
+
export { lik, smartdelay, smartpromise };
|
|
5
|
+
import croner from 'croner';
|
|
6
|
+
import dayjs from 'dayjs';
|
|
7
|
+
import prettyMs from 'pretty-ms';
|
|
8
|
+
export { croner, dayjs, prettyMs };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @pushrocks scope
|
|
2
|
+
import * as lik from '@pushrocks/lik';
|
|
3
|
+
import * as smartdelay from '@pushrocks/smartdelay';
|
|
4
|
+
import * as smartpromise from '@pushrocks/smartpromise';
|
|
5
|
+
export { lik, smartdelay, smartpromise };
|
|
6
|
+
// third parties;
|
|
7
|
+
import croner from 'croner';
|
|
8
|
+
import dayjs from 'dayjs';
|
|
9
|
+
import isToday from 'dayjs/plugin/isToday.js';
|
|
10
|
+
import prettyMs from 'pretty-ms';
|
|
11
|
+
dayjs.extend(isToday);
|
|
12
|
+
export { croner, dayjs, prettyMs };
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxtQkFBbUI7QUFDbkIsT0FBTyxLQUFLLEdBQUcsTUFBTSxnQkFBZ0IsQ0FBQztBQUN0QyxPQUFPLEtBQUssVUFBVSxNQUFNLHVCQUF1QixDQUFDO0FBQ3BELE9BQU8sS0FBSyxZQUFZLE1BQU0seUJBQXlCLENBQUM7QUFFeEQsT0FBTyxFQUFFLEdBQUcsRUFBRSxVQUFVLEVBQUUsWUFBWSxFQUFFLENBQUM7QUFFekMsaUJBQWlCO0FBQ2pCLE9BQU8sTUFBTSxNQUFNLFFBQVEsQ0FBQztBQUM1QixPQUFPLEtBQUssTUFBTSxPQUFPLENBQUM7QUFDMUIsT0FBTyxPQUFPLE1BQU0seUJBQXlCLENBQUM7QUFDOUMsT0FBTyxRQUFRLE1BQU0sV0FBVyxDQUFDO0FBRWpDLEtBQUssQ0FBQyxNQUFNLENBQUMsT0FBTyxDQUFDLENBQUM7QUFFdEIsT0FBTyxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsUUFBUSxFQUFFLENBQUMifQ==
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare let units: {
|
|
2
|
+
years: (timesArg?: number) => number;
|
|
3
|
+
months: (timesArg?: number) => number;
|
|
4
|
+
weeks: (timesArg?: number) => number;
|
|
5
|
+
days: (timesArg?: number) => number;
|
|
6
|
+
hours: (timesArg?: number) => number;
|
|
7
|
+
minutes: (timesArg?: number) => number;
|
|
8
|
+
};
|
|
9
|
+
export interface IUnitCombinationArg {
|
|
10
|
+
years?: number;
|
|
11
|
+
months?: number;
|
|
12
|
+
weeks?: number;
|
|
13
|
+
days?: number;
|
|
14
|
+
hours?: number;
|
|
15
|
+
minutes?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare let getMilliSecondsFromUnits: (combinationArg: IUnitCombinationArg) => number;
|
|
18
|
+
export declare const getMilliSecondsAsHumanReadableString: (milliSecondsArg: number) => string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as plugins from './smarttime.plugins.js';
|
|
2
|
+
export let units = {
|
|
3
|
+
years: (timesArg = 1) => {
|
|
4
|
+
return timesArg * 3.154e10;
|
|
5
|
+
},
|
|
6
|
+
months: (timesArg = 1) => {
|
|
7
|
+
return timesArg * 2.628e9;
|
|
8
|
+
},
|
|
9
|
+
weeks: (timesArg = 1) => {
|
|
10
|
+
return timesArg * 6.048e8;
|
|
11
|
+
},
|
|
12
|
+
days: (timesArg = 1) => {
|
|
13
|
+
return timesArg * 8.64e7;
|
|
14
|
+
},
|
|
15
|
+
hours: (timesArg = 1) => {
|
|
16
|
+
return timesArg * 3.6e6;
|
|
17
|
+
},
|
|
18
|
+
minutes: (timesArg = 1) => {
|
|
19
|
+
return timesArg * 60000;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export let getMilliSecondsFromUnits = (combinationArg) => {
|
|
23
|
+
let timeInMilliseconds = 0;
|
|
24
|
+
let addMilliSeconds = (milliSecondsArg) => {
|
|
25
|
+
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
|
26
|
+
};
|
|
27
|
+
if (combinationArg.years) {
|
|
28
|
+
addMilliSeconds(units.years(combinationArg.years));
|
|
29
|
+
}
|
|
30
|
+
if (combinationArg.months) {
|
|
31
|
+
addMilliSeconds(units.months(combinationArg.months));
|
|
32
|
+
}
|
|
33
|
+
if (combinationArg.weeks) {
|
|
34
|
+
addMilliSeconds(units.weeks(combinationArg.weeks));
|
|
35
|
+
}
|
|
36
|
+
if (combinationArg.days) {
|
|
37
|
+
addMilliSeconds(units.days(combinationArg.days));
|
|
38
|
+
}
|
|
39
|
+
if (combinationArg.hours) {
|
|
40
|
+
addMilliSeconds(units.hours(combinationArg.hours));
|
|
41
|
+
}
|
|
42
|
+
if (combinationArg.minutes) {
|
|
43
|
+
addMilliSeconds(units.minutes(combinationArg.minutes));
|
|
44
|
+
}
|
|
45
|
+
return timeInMilliseconds;
|
|
46
|
+
};
|
|
47
|
+
export const getMilliSecondsAsHumanReadableString = (milliSecondsArg) => {
|
|
48
|
+
return plugins.prettyMs(milliSecondsArg);
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnVuaXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLnVuaXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sd0JBQXdCLENBQU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The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Lossless GmbH (hello@lossless.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/npmextra.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"npmci": {
|
|
3
|
+
"npmGlobalTools": [],
|
|
4
|
+
"npmAccessLevel": "public"
|
|
5
|
+
},
|
|
6
|
+
"gitzone": {
|
|
7
|
+
"projectType": "npm",
|
|
8
|
+
"module": {
|
|
9
|
+
"githost": "gitlab.com",
|
|
10
|
+
"gitscope": "pushrocks",
|
|
11
|
+
"gitrepo": "smarttime",
|
|
12
|
+
"description": "handle time in smart ways",
|
|
13
|
+
"npmPackagename": "@pushrocks/smarttime",
|
|
14
|
+
"license": "MIT"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@push.rocks/smarttime",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "4.0.1",
|
|
5
|
+
"description": "handle time in smart ways",
|
|
6
|
+
"main": "dist_ts/index.js",
|
|
7
|
+
"typings": "dist_ts/index.d.ts",
|
|
8
|
+
"author": "Lossless GmbH",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "(tstest ./test)",
|
|
12
|
+
"build": "(tsbuild --web && tsbundle npm)",
|
|
13
|
+
"buildDocs": "tsdoc"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@gitzone/tsbuild": "^2.1.29",
|
|
17
|
+
"@gitzone/tsbundle": "^2.0.7",
|
|
18
|
+
"@gitzone/tsrun": "^1.2.18",
|
|
19
|
+
"@gitzone/tstest": "^1.0.60",
|
|
20
|
+
"@pushrocks/tapbundle": "^5.0.4",
|
|
21
|
+
"@types/node": "^18.11.9"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@pushrocks/lik": "^6.0.0",
|
|
25
|
+
"@pushrocks/smartdelay": "^2.0.13",
|
|
26
|
+
"@pushrocks/smartpromise": "^3.1.6",
|
|
27
|
+
"croner": "^5.3.4",
|
|
28
|
+
"dayjs": "^1.10.7",
|
|
29
|
+
"is-nan": "^1.3.2",
|
|
30
|
+
"pretty-ms": "^8.0.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"ts/**/*",
|
|
34
|
+
"ts_web/**/*",
|
|
35
|
+
"dist/**/*",
|
|
36
|
+
"dist_*/**/*",
|
|
37
|
+
"dist_ts/**/*",
|
|
38
|
+
"dist_ts_web/**/*",
|
|
39
|
+
"assets/**/*",
|
|
40
|
+
"cli.js",
|
|
41
|
+
"npmextra.json",
|
|
42
|
+
"readme.md"
|
|
43
|
+
],
|
|
44
|
+
"browserslist": [
|
|
45
|
+
"last 1 chrome versions"
|
|
46
|
+
],
|
|
47
|
+
"type": "module"
|
|
48
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @pushrocks/smarttime
|
|
2
|
+
handle time in smart ways
|
|
3
|
+
|
|
4
|
+
## Availabililty and Links
|
|
5
|
+
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smarttime)
|
|
6
|
+
* [gitlab.com (source)](https://gitlab.com/pushrocks/smarttime)
|
|
7
|
+
* [github.com (source mirror)](https://github.com/pushrocks/smarttime)
|
|
8
|
+
* [docs (typedoc)](https://pushrocks.gitlab.io/smarttime/)
|
|
9
|
+
|
|
10
|
+
## Status for master
|
|
11
|
+
|
|
12
|
+
Status Category | Status Badge
|
|
13
|
+
-- | --
|
|
14
|
+
GitLab Pipelines | [](https://lossless.cloud)
|
|
15
|
+
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
16
|
+
npm | [](https://lossless.cloud)
|
|
17
|
+
Snyk | [](https://lossless.cloud)
|
|
18
|
+
TypeScript Support | [](https://lossless.cloud)
|
|
19
|
+
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
20
|
+
Code Style | [](https://lossless.cloud)
|
|
21
|
+
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
22
|
+
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
23
|
+
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
24
|
+
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Use TypeScript for best in class instellisense.
|
|
29
|
+
|
|
30
|
+
Smarttime offers smart ways to deal with time.
|
|
31
|
+
|
|
32
|
+
### class CronManager
|
|
33
|
+
|
|
34
|
+
This class provides scheduling of functions with a cron syntax
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { CronManager } from '@pushrocks/smarrtime';
|
|
38
|
+
const cronManagerInstance = new CronManager();
|
|
39
|
+
cronManagerInstance.addCronjob('* * * * * *', async () => {
|
|
40
|
+
console.log('hello'); // will log 'hello' to console once every second;
|
|
41
|
+
});
|
|
42
|
+
cronManagerInstance.start();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### class ExtendedDate
|
|
46
|
+
|
|
47
|
+
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
|
|
48
|
+
|
|
49
|
+
```TypeScript
|
|
50
|
+
import { ExtendedDate } from '@pushrocks/smarttime'
|
|
51
|
+
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Contribution
|
|
55
|
+
|
|
56
|
+
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). :)
|
|
57
|
+
|
|
58
|
+
For further information read the linked docs at the top of this readme.
|
|
59
|
+
|
|
60
|
+
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
61
|
+
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
62
|
+
|
|
63
|
+
[](https://maintainedby.lossless.com)
|
package/ts/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './smarttime.classes.cronmanager.js';
|
|
2
|
+
export * from './smarttime.classes.cronjob.js';
|
|
3
|
+
export * from './smarttime.classes.extendeddate.js';
|
|
4
|
+
export * from './smarttime.classes.hrtmeasurement.js';
|
|
5
|
+
export * from './smarttime.classes.interval.js';
|
|
6
|
+
export * from './smarttime.classes.timer.js';
|
|
7
|
+
export * from './smarttime.classes.timestamp.js';
|
|
8
|
+
export * from './smarttime.units.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as plugins from './smarttime.plugins.js';
|
|
2
|
+
import { CronManager } from './smarttime.classes.cronmanager.js';
|
|
3
|
+
|
|
4
|
+
import { CronParser } from './smarttime.classes.cronparser.js';
|
|
5
|
+
|
|
6
|
+
export type TJobFunction =
|
|
7
|
+
| ((triggerTimeArg?: number) => void)
|
|
8
|
+
| ((triggerTimeArg?: number) => Promise<any>);
|
|
9
|
+
|
|
10
|
+
export class CronJob {
|
|
11
|
+
public cronParser: plugins.croner;
|
|
12
|
+
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
|
13
|
+
public cronExpression: string;
|
|
14
|
+
public jobFunction: TJobFunction;
|
|
15
|
+
private nextExecutionUnix: number = 0;
|
|
16
|
+
|
|
17
|
+
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
|
18
|
+
this.cronExpression = cronExpressionArg;
|
|
19
|
+
this.jobFunction = jobFunction;
|
|
20
|
+
this.cronParser = plugins.croner(cronExpressionArg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* checks wether the cronjob needs to be executed
|
|
25
|
+
*/
|
|
26
|
+
public checkExecution(): number {
|
|
27
|
+
if (this.nextExecutionUnix === 0) {
|
|
28
|
+
this.getNextExecutionTime();
|
|
29
|
+
}
|
|
30
|
+
if (Date.now() > this.nextExecutionUnix) {
|
|
31
|
+
const maybePromise = this.jobFunction(this.nextExecutionUnix);
|
|
32
|
+
if (maybePromise instanceof Promise) {
|
|
33
|
+
maybePromise.catch((e) => console.log(e));
|
|
34
|
+
}
|
|
35
|
+
this.nextExecutionUnix = this.getNextExecutionTime();
|
|
36
|
+
}
|
|
37
|
+
return this.nextExecutionUnix;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public getNextExecutionTime() {
|
|
41
|
+
return (this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* gets the time to next execution
|
|
46
|
+
*/
|
|
47
|
+
public getTimeToNextExecution() {
|
|
48
|
+
return this.cronParser.msToNext();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public start() {
|
|
52
|
+
this.status = 'started';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public stop() {
|
|
56
|
+
this.status = 'stopped';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as plugins from './smarttime.plugins.js';
|
|
2
|
+
import { CronJob, TJobFunction } from './smarttime.classes.cronjob.js';
|
|
3
|
+
import { getMilliSecondsAsHumanReadableString } from './smarttime.units.js';
|
|
4
|
+
|
|
5
|
+
export class CronManager {
|
|
6
|
+
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
|
7
|
+
|
|
8
|
+
public status: 'started' | 'stopped' = 'stopped';
|
|
9
|
+
public cronjobs = new plugins.lik.ObjectMap<CronJob>();
|
|
10
|
+
|
|
11
|
+
constructor() {}
|
|
12
|
+
|
|
13
|
+
public addCronjob(cronIdentifierArg: string, cronFunctionArg: TJobFunction) {
|
|
14
|
+
const newCronJob = new CronJob(this, cronIdentifierArg, cronFunctionArg);
|
|
15
|
+
this.cronjobs.add(newCronJob);
|
|
16
|
+
if (this.status === 'started') {
|
|
17
|
+
newCronJob.start();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return newCronJob;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public removeCronjob(cronjobArg: CronJob) {
|
|
24
|
+
cronjobArg.stop();
|
|
25
|
+
this.cronjobs.remove(cronjobArg);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* starts the cronjob
|
|
30
|
+
*/
|
|
31
|
+
public start() {
|
|
32
|
+
if (this.status !== 'started') {
|
|
33
|
+
this.status = 'started';
|
|
34
|
+
for (const cronJob of this.cronjobs.getArray()) {
|
|
35
|
+
cronJob.start();
|
|
36
|
+
}
|
|
37
|
+
const runCronCycle = async () => {
|
|
38
|
+
this.executionTimeout = new plugins.smartdelay.Timeout(0);
|
|
39
|
+
do {
|
|
40
|
+
let nextRunningCronjob: CronJob;
|
|
41
|
+
for (const cronJob of this.cronjobs.getArray()) {
|
|
42
|
+
cronJob.checkExecution();
|
|
43
|
+
if (
|
|
44
|
+
!nextRunningCronjob ||
|
|
45
|
+
cronJob.getTimeToNextExecution() < nextRunningCronjob.getTimeToNextExecution()
|
|
46
|
+
) {
|
|
47
|
+
nextRunningCronjob = cronJob;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (nextRunningCronjob) {
|
|
51
|
+
this.executionTimeout = new plugins.smartdelay.Timeout(
|
|
52
|
+
nextRunningCronjob.getTimeToNextExecution()
|
|
53
|
+
);
|
|
54
|
+
console.log(
|
|
55
|
+
`Next CronJob scheduled in ${getMilliSecondsAsHumanReadableString(
|
|
56
|
+
this.executionTimeout.getTimeLeft()
|
|
57
|
+
)}`
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
60
|
+
this.executionTimeout = new plugins.smartdelay.Timeout(1000);
|
|
61
|
+
console.log('no cronjobs specified! Checking again in 1 second');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await this.executionTimeout.promise;
|
|
65
|
+
} while (this.status === 'started');
|
|
66
|
+
};
|
|
67
|
+
runCronCycle();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* stops all cronjobs
|
|
73
|
+
*/
|
|
74
|
+
public stop() {
|
|
75
|
+
if (this.status === 'started') {
|
|
76
|
+
this.status = 'stopped';
|
|
77
|
+
this.executionTimeout.cancel();
|
|
78
|
+
} else {
|
|
79
|
+
console.log(`You tried to stop a CronManager that was not actually started.`);
|
|
80
|
+
}
|
|
81
|
+
for (const cron of this.cronjobs.getArray()) {
|
|
82
|
+
cron.stop();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|