Compare commits

...

21 Commits

Author SHA1 Message Date
51943fad1c 4.2.0 2024-12-14 02:22:43 +01:00
ce3af11ca8 feat(ondemand): Add on-demand timestamp feature 2024-12-14 02:22:43 +01:00
a941f10af3 4.1.1 2024-12-13 22:09:31 +01:00
6e7f8f3dda fix(smarttime.units): Fix issue in getMilliSecondsAsHumanReadableAgoTime 2024-12-13 22:09:30 +01:00
bfa00feadd 4.1.0 2024-12-13 22:04:26 +01:00
55c2d95b7d feat(smarttime.units): Add function to get human-readable time ago string from milliseconds. 2024-12-13 22:04:26 +01:00
71ce4de8ff 4.0.9 2024-12-13 21:55:02 +01:00
491176bb35 fix(dependencies): Updated dependencies in package.json and resolved cron function issues. 2024-12-13 21:55:02 +01:00
35e387da7c 4.0.8 2024-06-23 23:30:15 +02:00
c96248ea72 fix(documentation): Corrected formatting issues in changelog.md 2024-06-23 23:30:14 +02:00
7eb8e9c4f7 4.0.7 2024-06-23 23:27:11 +02:00
c0e9a7f19a fix(build): Remove GitLab CI configuration and update dependencies in package.json 2024-06-23 23:27:10 +02:00
6e18d6e13c update description 2024-05-29 14:16:49 +02:00
580b33448e update tsconfig 2024-04-14 18:28:37 +02:00
691c4f0aba update tsconfig 2024-04-01 21:41:37 +02:00
f06abc49b6 update npmextra.json: githost 2024-04-01 19:59:55 +02:00
1adfed02df update npmextra.json: githost 2024-03-30 21:48:56 +01:00
22e6798a3c 4.0.6 2023-10-20 12:50:48 +02:00
4dd4980374 fix(core): update 2023-10-20 12:50:47 +02:00
edadbe6cf5 4.0.5 2023-08-13 21:55:07 +02:00
58f213a099 fix(core): update 2023-08-13 21:55:06 +02:00
20 changed files with 9077 additions and 3616 deletions

View File

@ -119,6 +119,6 @@ jobs:
run: | run: |
npmci node install stable npmci node install stable
npmci npm install npmci npm install
pnpm install -g @gitzone/tsdoc pnpm install -g @git.zone/tsdoc
npmci command tsdoc npmci command tsdoc
continue-on-error: true continue-on-error: true

View File

@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

120
changelog.md Normal file
View File

@ -0,0 +1,120 @@
# Changelog
## 2024-12-14 - 4.2.0 - feat(ondemand)
Add on-demand timestamp feature
- Added an on-demand script to output human-readable time ago for current timestamp.
## 2024-12-13 - 4.1.1 - fix(smarttime.units)
Fix issue in getMilliSecondsAsHumanReadableAgoTime
- Corrected the parameter type passed to date-fns.formatDistanceToNow within getMilliSecondsAsHumanReadableAgoTime function.
## 2024-12-13 - 4.1.0 - feat(smarttime.units)
Add function to get human-readable time ago string from milliseconds.
- Introduced `getMilliSecondsAsHumanReadableAgoTime` to convert a timestamp to a human-readable text indicating time ago.
## 2024-12-13 - 4.0.9 - fix(dependencies)
Updated dependencies in package.json and resolved cron function issues.
- Updated multiple dependencies in package.json to their latest versions.
- Fixed issue in cron job instantiation by correcting the import and initialization of the croner.Cron class.
## 2024-06-23 - 4.0.8 - fix(documentation)
Corrected formatting issues in changelog.md
- Fixed markdown formatting by removing unnecessary newlines.
## 2024-06-23 - 4.0.7 - fix(build)
Remove GitLab CI configuration and update dependencies in package.json
- Removed .gitlab-ci.yml from the project
- Updated @git.zone/tsbuild from ^2.1.72 to ^2.1.80
- Updated @git.zone/tstest from ^1.0.86 to ^1.0.90
- Updated @push.rocks/tapbundle from ^5.0.15 to ^5.0.23
- Updated @types/node from ^20.11.19 to ^20.14.8
- Updated @push.rocks/lik from ^6.0.12 to ^6.0.15
- Updated dayjs from ^1.11.10 to ^1.11.11
- Fixed test files to export default tap.start()
## 2024-05-29 - 4.0.6 - Maintenance Updates
Updates to configuration files and metadata.
- Updated description in the project documentation.
- Revised tsconfig settings.
- Changes to npmextra.json regarding githost configuration.
## 2023-10-20 - 4.0.5 to 4.0.6 - Maintenance Fixes
Routine fixes and updates.
- fix(core): update
## 2023-08-13 - 4.0.4 to 4.0.5 - Maintenance Fixes
Routine fixes and updates.
- fix(core): update
## 2023-07-21 - 4.0.2 to 4.0.4 - Maintenance Fixes
Routine fixes and updates.
- fix(core): update
## 2023-01-06 - 4.0.0 to 4.0.1 - Core Changes
Routine fixes and core updates.
- fix(core): update
## 2022-11-21 - 3.0.45 to 4.0.0 - Major Release
Significant changes and breaking updates.
- BREAKING CHANGE(core): switch to esm
## 2021-11-08 - 3.0.41 to 3.0.42 - Timestamp Update
Updates and bug fixes for the timestamp feature.
- fix(timestamp): add missing .isOlderThanOtherTimeStamp() to TimeStamp class
- fix(readme): fix readme
- fix(update croner): update croner package, closes #1. Thank you @Hexagon4
## 2020-09-04 - 3.0.28 to 3.0.31 - Maintenance Fixes
Routine fixes and updates.
- fix(core): update
## 2020-07-11 - 3.0.19 to 3.0.20 - Maintenance Fixes
Routine fixes and updates.
- fix(core): update
## 2020-05-25 - 3.0.12 to 3.0.16 - Maintenance Fixes
Routine fixes and updates.
- fix(core): update
## 2019-06-18 - 3.0.8 to 3.0.12 - Maintenance Fixes
Routine fixes and updates.
- fix(core): update
## 2018-10-21 - 3.0.0 to 3.0.1 - Date Handling
Updates to date and time support.
- fix(date): now supports date and time
- fix(ExtendedDate): now respects single digit dates
## 2018-10-17 - 2.0.2 to 3.0.0 - Major Release
Breaking changes and dependency updates.
- BREAKING CHANGE(deps): remove moment and use luxon
## 2018-06-10 - 2.0.0 to 2.0.1 - Core Changes
Updated and changed the scope of core functionalities.
- fix(core): update and change scope
## 2017-08-16 - 1.0.0 to 1.0.3 - Initial Implementation
Inception of project with core functionalities.
- first implementation

View File

@ -6,12 +6,24 @@
"gitzone": { "gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smarttime", "gitrepo": "smarttime",
"description": "handle time in smart ways", "description": "Provides utilities for advanced time handling including cron jobs, timestamps, intervals, and more.",
"npmPackagename": "@push.rocks/smarttime", "npmPackagename": "@push.rocks/smarttime",
"license": "MIT" "license": "MIT",
"keywords": [
"time handling",
"cron jobs",
"timestamps",
"time intervals",
"date operations",
"time formatting",
"scheduling"
]
} }
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
} }
} }

View File

@ -1,8 +1,8 @@
{ {
"name": "@push.rocks/smarttime", "name": "@push.rocks/smarttime",
"private": false, "private": false,
"version": "4.0.4", "version": "4.2.0",
"description": "handle time in smart ways", "description": "Provides utilities for advanced time handling including cron jobs, timestamps, intervals, and more.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
@ -13,21 +13,22 @@
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.66", "@git.zone/tsbuild": "^2.2.0",
"@gitzone/tsbundle": "^2.0.8", "@git.zone/tsbundle": "^2.1.0",
"@gitzone/tsrun": "^1.2.44", "@git.zone/tsrun": "^1.3.3",
"@gitzone/tstest": "^1.0.77", "@git.zone/tstest": "^1.0.90",
"@push.rocks/tapbundle": "^5.0.12", "@push.rocks/tapbundle": "^5.5.3",
"@types/node": "^20.4.2" "@types/node": "^22.10.2"
}, },
"dependencies": { "dependencies": {
"@push.rocks/lik": "^6.0.3", "@push.rocks/lik": "^6.1.0",
"@push.rocks/smartdelay": "^3.0.5", "@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartpromise": "^4.0.3", "@push.rocks/smartpromise": "^4.0.4",
"croner": "^5.3.4", "croner": "^9.0.0",
"dayjs": "^1.11.9", "date-fns": "^4.1.0",
"dayjs": "^1.11.13",
"is-nan": "^1.3.2", "is-nan": "^1.3.2",
"pretty-ms": "^8.0.0" "pretty-ms": "^9.2.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@ -44,5 +45,19 @@
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
], ],
"type": "module" "type": "module",
"keywords": [
"time handling",
"cron jobs",
"timestamps",
"time intervals",
"date operations",
"time formatting",
"scheduling"
],
"homepage": "https://code.foss.global/push.rocks/smarttime",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smarttime.git"
}
} }

12094
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

164
readme.md
View File

@ -1,61 +1,147 @@
# @push.rocks/smarttime # @push.rocks/smarttime
handle time in smart ways handle time in smart ways
## Availabililty and Links ## Install
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smarttime) To install `@push.rocks/smarttime`, use the following npm command:
* [gitlab.com (source)](https://gitlab.com/push.rocks/smarttime)
* [github.com (source mirror)](https://github.com/push.rocks/smarttime)
* [docs (typedoc)](https://push.rocks.gitlab.io/smarttime/)
## Status for master ```bash
npm install @push.rocks/smarttime --save
```
Status Category | Status Badge This will add `@push.rocks/smarttime` to your project's dependencies.
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smarttime/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smarttime/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smarttime)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/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/@push.rocks/smarttime)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smarttime)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smarttime)](https://lossless.cloud)
## Usage ## Usage
Use TypeScript for best in class instellisense. `@push.rocks/smarttime` provides a comprehensive toolkit for handling various aspects of time manipulation, scheduling, and comparison in a TypeScript project. The following sections will guide you through the capabilities of this package, showcasing how to use its classes and functions effectively.
Smarttime offers smart ways to deal with time. ### Handling Time Units and Calculations
### class CronManager #### Working with Units
```typescript
import { units, getMilliSecondsFromUnits } from '@push.rocks/smarttime';
This class provides scheduling of functions with a cron syntax // Define a duration using a combination of time units
let durationInMilliseconds = getMilliSecondsFromUnits({
years: 1,
months: 2,
weeks: 3,
days: 4,
hours: 5,
minutes: 6,
seconds: 7
});
console.log(`Duration in milliseconds: ${durationInMilliseconds}`);
```
In the example above, we specify a complex duration made up of various time units using the `getMilliSecondsFromUnits` function. This is quite useful for calculations where you need to define durations in a more human-readable format.
### Scheduling with CronManager
`@push.rocks/smarttime` includes a powerful scheduling tool called `CronManager`, which allows you to schedule tasks using cron syntax.
#### Creating and Starting a CronManager
```typescript
import { CronManager } from '@push.rocks/smarttime';
const cronManager = new CronManager();
// Adding a cron job that runs every minute
cronManager.addCronjob('* * * * *', async () => {
console.log('This task runs every minute.');
});
// Starting the CronManager
cronManager.start();
```
The example demonstrates how to create a `CronManager`, add a cron job that runs every minute, and start the scheduling. You can add multiple cron jobs to a single manager, each with its own scheduling and task.
### Working with Extended Date Class
The `ExtendedDate` class extends the native JavaScript `Date` object, providing additional functionality for handling dates in various formats and zones.
#### Creating ExtendedDate Instances
```typescript
import { ExtendedDate } from '@push.rocks/smarttime';
// Creating a date from a European format string
const dateFromEuroString = ExtendedDate.fromEuropeanDate('31.12.2023');
console.log(dateFromEuroString.toString());
// Creating a date from a hyphed date string
const dateFromHyphedString = ExtendedDate.fromHyphedDate('2023-12-31');
console.log(dateFromHyphedString.toString());
```
#### Checking if a Date is Today
```typescript
import { ExtendedDate } from '@push.rocks/smarttime';
const someDate = new ExtendedDate();
console.log(`Is someDate today? ${someDate.isToday()}`);
```
Using `ExtendedDate`, you can also easily check if a given date is today. This simplifies certain date comparisons that are common in web and application development.
### High-Resolution Time Measurement
For performance testing and high-resolution time tracking, `@push.rocks/smarttime` provides the `HrtMeasurement` class.
```typescript ```typescript
import { CronManager } from '@pushrocks/smarrtime'; import { HrtMeasurement } from '@push.rocks/smarttime';
const cronManagerInstance = new CronManager();
cronManagerInstance.addCronjob('* * * * * *', async () => { const hrtMeasurement = new HrtMeasurement();
console.log('hello'); // will log 'hello' to console once every second; hrtMeasurement.start();
// Simulate some operations...
setTimeout(() => {
hrtMeasurement.stop();
console.log(`Operation took ${hrtMeasurement.milliSeconds} milliseconds.`);
}, 1000);
```
This class allows you to measure the duration of operations in your code with high precision, offering both milliseconds and nanoseconds resolutions.
### Interval and Timer functionalities
`@push.rocks/smarttime` includes classes for managing intervals and timers with enhanced control, such as pause, resume, and reset capabilities.
#### Using the Timer class
```typescript
import { Timer } from '@push.rocks/smarttime';
const timer = new Timer(5000); // A 5-second timer
timer.start();
timer.completed.then(() => {
console.log('Timer completed!');
}); });
cronManagerInstance.start();
// Resetting the timer
timer.reset();
timer.start();
``` ```
### class ExtendedDate The `Timer` class allows for asynchronous waiting in a more object-oriented manner. In the example, a `Timer` is created for five seconds, started, and then reset for demonstration purposes.
This class offers static functions to create zone specific JavaScript dates from European formated time strings. ### Conclusion
```TypeScript `@push.rocks/smarttime` offers an extensive toolkit for dealing with time in JavaScript and TypeScript applications. Whether you need precise timing, scheduled tasks, or extended date functionalities, this package provides a suite of tools designed to handle time in smart and efficient ways. The examples provided herein demonstrate the core functionalities, aiming to help you integrate time-related features into your projects with ease.
import { ExtendedDate } from '@pushrocks/smarttime'
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
```
## Contribution ## License and Legal Information
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). :) This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
For further information read the linked docs at the top of this readme. **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
## Legal ### Trademarks
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

3
test/ondemand.ts Normal file
View File

@ -0,0 +1,3 @@
import * as smarttime from '../ts/index.js';
console.log(smarttime.getMilliSecondsAsHumanReadableAgoTime(Date.now()));

View File

@ -47,4 +47,4 @@ tap.test('should combine units', async () => {
console.log(computedTime); console.log(computedTime);
}); });
tap.start(); export default tap.start();

View File

@ -57,4 +57,4 @@ tap.test('runs every full minute', async (tools) => {
testCronManager.stop(); testCronManager.stop();
}); });
tap.start(); export default tap.start();

View File

@ -31,4 +31,4 @@ tap.test('should format a date', async () => {
console.log(extendedDate.format('YYYY-MM-DD - hh:mm')); console.log(extendedDate.format('YYYY-MM-DD - hh:mm'));
}); });
tap.start(); export default tap.start();

View File

@ -23,4 +23,4 @@ tap.test('should reset a timer', async () => {
await testTimer.completed; await testTimer.completed;
}); });
tap.start(); export default tap.start();

View File

@ -1,8 +1,8 @@
/** /**
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @push.rocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smarttime', name: '@push.rocks/smarttime',
version: '4.0.4', version: '4.2.0',
description: 'handle time in smart ways' description: 'Provides utilities for advanced time handling including cron jobs, timestamps, intervals, and more.'
} }

View File

@ -8,7 +8,7 @@ export type TJobFunction =
| ((triggerTimeArg?: number) => Promise<any>); | ((triggerTimeArg?: number) => Promise<any>);
export class CronJob { export class CronJob {
public cronParser: plugins.croner; public cronParser: plugins.croner.Cron;
public status: 'started' | 'stopped' | 'initial' = 'initial'; public status: 'started' | 'stopped' | 'initial' = 'initial';
public cronExpression: string; public cronExpression: string;
public jobFunction: TJobFunction; public jobFunction: TJobFunction;
@ -17,7 +17,7 @@ export class CronJob {
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) { constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
this.cronExpression = cronExpressionArg; this.cronExpression = cronExpressionArg;
this.jobFunction = jobFunction; this.jobFunction = jobFunction;
this.cronParser = plugins.croner(cronExpressionArg); this.cronParser = new plugins.croner.Cron(cronExpressionArg);
} }
/** /**

View File

@ -34,7 +34,11 @@ export class CronManager {
for (const cronJob of this.cronjobs.getArray()) { for (const cronJob of this.cronjobs.getArray()) {
cronJob.start(); cronJob.start();
} }
const runCronCycle = async () => { this.runCronCycle();
}
}
private async runCronCycle() {
this.executionTimeout = new plugins.smartdelay.Timeout(0); this.executionTimeout = new plugins.smartdelay.Timeout(0);
do { do {
let nextRunningCronjob: CronJob; let nextRunningCronjob: CronJob;
@ -64,9 +68,6 @@ export class CronManager {
await this.executionTimeout.promise; await this.executionTimeout.promise;
} while (this.status === 'started'); } while (this.status === 'started');
}; };
runCronCycle();
}
}
/** /**
* stops all cronjobs * stops all cronjobs

View File

@ -36,7 +36,7 @@ export class Timer {
/** /**
* the current timeout the needs to be canceled when this Timer is stopped * the current timeout the needs to be canceled when this Timer is stopped
*/ */
private currentTimeout: NodeJS.Timer; private currentTimeout: NodeJS.Timeout;
// a deferred triggeted when Timer has completed // a deferred triggeted when Timer has completed
private completedDeferred = plugins.smartpromise.defer<void>(); private completedDeferred = plugins.smartpromise.defer<void>();

View File

@ -6,11 +6,12 @@ import * as smartpromise from '@push.rocks/smartpromise';
export { lik, smartdelay, smartpromise }; export { lik, smartdelay, smartpromise };
// third parties; // third parties;
import croner from 'croner'; import * as croner from 'croner';
import * as dateFns from 'date-fns';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import isToday from 'dayjs/plugin/isToday.js'; import isToday from 'dayjs/plugin/isToday.js';
import prettyMs from 'pretty-ms'; import prettyMs from 'pretty-ms';
dayjs.extend(isToday); dayjs.extend(isToday);
export { croner, dayjs, prettyMs }; export { croner, dateFns, dayjs, prettyMs };

View File

@ -19,6 +19,9 @@ export let units = {
minutes: (timesArg = 1) => { minutes: (timesArg = 1) => {
return timesArg * 60000; return timesArg * 60000;
}, },
seconds: (timesArg = 1) => {
return timesArg * 1000;
},
}; };
export interface IUnitCombinationArg { export interface IUnitCombinationArg {
@ -28,6 +31,7 @@ export interface IUnitCombinationArg {
days?: number; days?: number;
hours?: number; hours?: number;
minutes?: number; minutes?: number;
seconds?: number;
} }
export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => { export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
@ -53,6 +57,9 @@ export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
if (combinationArg.minutes) { if (combinationArg.minutes) {
addMilliSeconds(units.minutes(combinationArg.minutes)); addMilliSeconds(units.minutes(combinationArg.minutes));
} }
if (combinationArg.seconds) {
addMilliSeconds(units.seconds(combinationArg.seconds));
}
return timeInMilliseconds; return timeInMilliseconds;
}; };
@ -60,3 +67,7 @@ export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
export const getMilliSecondsAsHumanReadableString = (milliSecondsArg: number): string => { export const getMilliSecondsAsHumanReadableString = (milliSecondsArg: number): string => {
return plugins.prettyMs(milliSecondsArg); return plugins.prettyMs(milliSecondsArg);
}; };
export const getMilliSecondsAsHumanReadableAgoTime = (timeStampArg: number): string => {
return plugins.dateFns.formatDistanceToNow(new Date(timeStampArg));
}

View File

@ -3,9 +3,12 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"useDefineForClassFields": false, "useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "NodeNext",
"moduleResolution": "nodenext", "moduleResolution": "NodeNext",
"esModuleInterop": true, "esModuleInterop": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true
} },
"exclude": [
"dist_*/**/*.d.ts"
]
} }