Compare commits
105 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 92cb9cd313 | |||
| 306b45ecf4 | |||
| e5a1399857 | |||
| 40d72de979 | |||
| 51943fad1c | |||
| ce3af11ca8 | |||
| a941f10af3 | |||
| 6e7f8f3dda | |||
| bfa00feadd | |||
| 55c2d95b7d | |||
| 71ce4de8ff | |||
| 491176bb35 | |||
| 35e387da7c | |||
| c96248ea72 | |||
| 7eb8e9c4f7 | |||
| c0e9a7f19a | |||
| 6e18d6e13c | |||
| 580b33448e | |||
| 691c4f0aba | |||
| f06abc49b6 | |||
| 1adfed02df | |||
| 22e6798a3c | |||
| 4dd4980374 | |||
| edadbe6cf5 | |||
| 58f213a099 | |||
| 1e5fd80a69 | |||
| 1de9412a31 | |||
| fa3ac0ff77 | |||
| 25eee6cf73 | |||
| c290a75f01 | |||
| 9a20f8f6a1 | |||
| f91fa33568 | |||
| c234cb4caa | |||
| 5f5957b0c0 | |||
| 31275536ec | |||
| c759d436dd | |||
| 010c9e7bed | |||
| 264c08d848 | |||
| b2a5cda468 | |||
| d3dd03534a | |||
| 9b96779d19 | |||
| 20b181b2f3 | |||
| d278722da2 | |||
| e3daf08d67 | |||
| 0483b55a9e | |||
| c3a772c155 | |||
| a2ffdd436f | |||
| da9c71eedb | |||
| 63405fc577 | |||
| d789eec558 | |||
| 22027d2308 | |||
| 87d29fbb50 | |||
| 1c5a1c21da | |||
| 969088ad04 | |||
| 76768a1307 | |||
| 419fe80bde | |||
| 5a9584917c | |||
| 2b21ee9a24 | |||
| 3a110c9fd9 | |||
| 25f7ad37ae | |||
| 992d167a34 | |||
| cfcfde2132 | |||
| b5ab945501 | |||
| 88378e2f31 | |||
| db92311daa | |||
| 36bff0a70a | |||
| fa8fd9fa35 | |||
| dd783b455f | |||
| 996685e7fb | |||
| 110b2c00cf | |||
| c8b455b8e2 | |||
| d16fd8b69b | |||
| f7ed88cd57 | |||
| 19b5ba4a5d | |||
| 457182a97a | |||
| a7a961c869 | |||
| f1d7771e30 | |||
| ff16b70206 | |||
| 8e43ce7e9b | |||
| f129ce42b6 | |||
| 56a802664f | |||
| 743c9fb847 | |||
| ac2edd6d74 | |||
| 725102d02c | |||
| 7c73579c9f | |||
| a1996ea1bd | |||
| dc92ae7140 | |||
| 3e862f233c | |||
| 73f7360f8c | |||
| 2c74de8aef | |||
| 78498626ea | |||
| b2299b149a | |||
| 885b2432a8 | |||
| 7a231b7686 | |||
| ef6e21080e | |||
| 3ea8b1564d | |||
| 1b92240c4e | |||
| 95bf558503 | |||
| d1ff77d9f5 | |||
| b77677b089 | |||
| 5ebd9ce6de | |||
| 702365aba3 | |||
| 93778e1bcf | |||
| 4d0fb3eb30 | |||
| 3f0b230d23 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @git.zone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
||||||
117
.gitlab-ci.yml
117
.gitlab-ci.yml
@@ -1,117 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: "$CI_BUILD_STAGE"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
snyk:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g tslint typescript
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command tsdoc
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
||||||
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal 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", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
140
changelog.md
Normal file
140
changelog.md
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-02-15 - 4.2.2 - fix(npmextra)
|
||||||
|
restructure npmextra.json: flatten @git.zone/cli and tsdoc to top-level, add Verdaccio registry and @ship.zone/szci entry, remove deprecated npmci and gitzone keys
|
||||||
|
|
||||||
|
- Promoted @git.zone/cli to top-level and removed the legacy npmci/gitzone wrappers
|
||||||
|
- Moved tsdoc/legal content into a new @git.zone/tsdoc top-level entry
|
||||||
|
- Added https://verdaccio.lossless.digital to release.registries alongside registry.npmjs.org
|
||||||
|
- Added @ship.zone/szci entry with npmGlobalTools: []
|
||||||
|
- Only configuration/metadata changes — no source code modifications
|
||||||
|
|
||||||
|
## 2026-02-15 - 4.2.1 - fix(cronmanager)
|
||||||
|
improve cron scheduling and lifecycle handling; add wake/wakeCycle to promptly recalculate scheduling when jobs are added/removed/started/stopped, fix timeout handling, and update tests and deps
|
||||||
|
|
||||||
|
- CronManager: add wakeCycle (Deferred) to wake the sleeping cycle immediately when jobs change
|
||||||
|
- CronManager: refactor runCronCycle to compute the soonest next execution (soonestMs), await timeout or wake signal, handle overdue jobs without waiting, and cancel timeouts to avoid lingering timers
|
||||||
|
- CronJob: guard checkExecution to return when job status is 'stopped' to prevent unnecessary scheduling work
|
||||||
|
- Stop logic: safely cancel executionTimeout only if present and ensure the cycle is woken when stopping
|
||||||
|
- Tests: switch test imports to @git.zone/tstest/tapbundle
|
||||||
|
- Dependencies: bump several devDependencies and dependencies (tsbuild, tsbundle, tstest, croner, smartpromise, dayjs, pretty-ms, etc.)
|
||||||
|
- Docs/config: expand README with examples and security/reporting info; add @git.zone/cli release config to npmextra.json
|
||||||
|
|
||||||
|
## 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
|
||||||
16120
dist_bundle/bundle.js
16120
dist_bundle/bundle.js
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
7
dist_ts/index.d.ts
vendored
@@ -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';
|
|
||||||
@@ -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=
|
|
||||||
17
dist_ts/smarttime.classes.cronjob.d.ts
vendored
17
dist_ts/smarttime.classes.cronjob.d.ts
vendored
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuY3JvbmpvYi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0dGltZS5jbGFzc2VzLmNyb25qb2IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDZEQU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DQUFDO0lBRU8sZUFBZTtRQUNyQixPQUFPLE9BQU8sQ0FBQyxVQUFVLENBQUMsZUFBZSxDQUFDLElBQUksQ0FBQyxjQUFjLENBQUMsQ0FBQztJQUNqRSxDQUFDO0NBQ0Y7QUF2Q0QsMEJBdUNDIn0=
|
|
||||||
17
dist_ts/smarttime.classes.cronmanager.d.ts
vendored
17
dist_ts/smarttime.classes.cronmanager.d.ts
vendored
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuY3Jvbm1hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy5jcm9ubWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFDQSwyRUFBc0Q7QUFFdEQsNkVBQXdEO0FBRXhELE1BQWEsV0FBVztJQU10QjtRQUxPLGlCQUFZLEdBQUcsSUFBSSxxQ0FBUSxDQUFDLElBQUksQ0FBQyxDQUFDO1FBRWxDLFdBQU0sR0FBMEIsU0FBUyxDQUFDO1FBQzFDLGFBQVEsR0FBYyxFQUFFLENBQUM7UUFHOUIsSUFBSSxDQUFDLFlBQVksQ0FBQyxjQUFjLENBQUMsR0FBRyxFQUFFO1lBQ3BDLEtBQUssTUFBTSxPQUFPLElBQUksSUFBSSxDQUFDLFFBQVEsRUFBRTtnQkFDbkMsT0FBTyxDQUFDLGNBQWMsRUFBRSxDQUFDO2FBQzFCO1FBQ0gsQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDO0lBRU0sVUFBVSxDQUFDLGlCQUF5QixFQUFFLGVBQTBCO1FBQ3JFLE1BQU0sVUFBVSxHQUFHLElBQUksbUNBQU8sQ0FBQyxJQUFJLEVBQUUsaUJBQWlCLEVBQUUsZUFBZSxDQUFDLENBQUM7UUFDekUsSUFBSSxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUM7UUFDL0IsSUFBSSxJQUFJLENBQUMsTUFBTSxLQUFLLFNBQVMsRUFBRTtZQUM3QixVQUFVLENBQUMsS0FBSyxFQUFFLENBQUM7U0FDcEI7SUFDSCxDQUFDO0lBRUQ7O09BRUc7SUFDSSxLQUFLO1FBQ1YsSUFBSSxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUM7UUFDeEIsS0FBSyxNQUFNLElBQUksSUFBSSxJQUFJLENBQUMsUUFBUSxFQUFFO1lBQ2hDLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQztTQUNkO1FBQ0QsSUFBSSxDQUFDLFlBQVksQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM1QixDQUFDO0lBRUQ7O09BRUc7SUFDSSxJQUFJO1FBQ1QsSUFBSSxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUM7UUFDeEIsS0FBSyxNQUFNLElBQUksSUFBSSxJQUFJLENBQUMsUUFBUSxFQUFFO1lBQ2hDLElBQUksQ0FBQyxJQUFJLEVBQUUsQ0FBQztTQUNiO1FBQ0QsSUFBSSxDQUFDLFlBQVksQ0FBQyxJQUFJLEVBQUUsQ0FBQztJQUMzQixDQUFDO0NBQ0Y7QUEzQ0Qsa0NBMkNDIn0=
|
|
||||||
33
dist_ts/smarttime.classes.extendeddate.d.ts
vendored
33
dist_ts/smarttime.classes.extendeddate.d.ts
vendored
@@ -1,33 +0,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;
|
|
||||||
}
|
|
||||||
@@ -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;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BQUUsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQztZQUNwRCxTQUFTLEVBQUUsV0FBVyxDQUFDLElBQUksQ0FBQyxRQUFRLEVBQUUsQ0FBQztZQUN2QyxHQUFHLEVBQUUsSUFBSSxDQUFDLE9BQU8sRUFBRTtZQUNuQixTQUFTLEVBQUUsQ0FBQyxHQUFHLEdBQUcsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBQzNDLFlBQVksRUFBRSxJQUFJLENBQUMsTUFBTSxFQUFFO1lBQzNCLGdCQUFnQixFQUFFLFNBQVMsQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUM7U0FDM0MsQ0FBQztJQUNKLENBQUM7Q0FDRjtBQTlHRCxvQ0E4R0MifQ==
|
|
||||||
22
dist_ts/smarttime.classes.hrtmeasurement.d.ts
vendored
22
dist_ts/smarttime.classes.hrtmeasurement.d.ts
vendored
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuaHJ0bWVhc3VyZW1lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy5ocnRtZWFzdXJlbWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQTs7R0FFRztBQUNILE1BQWEsY0FBYztJQUEzQjtRQUNTLGdCQUFXLEdBQVcsSUFBSSxDQUFDO1FBQzNCLGlCQUFZLEdBQ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QUFDLFFBQVEsR0FBRyxLQUFLLENBQUM7SUFDeEIsQ0FBQztDQUNGO0FBdkNELHdDQXVDQyJ9
|
|
||||||
11
dist_ts/smarttime.classes.interval.d.ts
vendored
11
dist_ts/smarttime.classes.interval.d.ts
vendored
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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==
|
|
||||||
38
dist_ts/smarttime.classes.timer.d.ts
vendored
38
dist_ts/smarttime.classes.timer.d.ts
vendored
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy50aW1lci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsNkRBQStDO0FBRS9DLCtFQUEwRDtBQUkxRCxNQUFhLEtBQUs7SUFxQ2hCLFlBQVkscUJBQTZCO1FBL0J6Qzs7V0FFRztRQUNJLFVBQUssR0FBZSxXQUFXLENBQUM7UUF5QnZDLGdEQUFnRDtRQUN4QyxzQkFBaUIsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLEtBQUssRUFBUSxDQUFDO1FBRzdELElBQUksQ0FBQyxrQkFBa0IsR0FBRyxxQkFBcUIsQ0FBQztRQUNoRCxJQUFJLENBQUMsU0FBUyxHQUFHLElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxPQUFPLENBQUM7SUFDbEQsQ0FBQztJQWRELElBQUksUUFBUTtRQUNWLE9BQU8sSUFBSSxDQUFDLGtCQUFrQixHQUFHLElBQUksQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDO0lBQ3hELENBQUM7SUFjRDs7T0FFRztJQUNJLEtBQUs7UUFDVixJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBRTtZQUNuQixJQUFJLENBQUMsY0FBYyxHQUFHLFVBQVUsQ0FBQyxHQUFHLEVBQUU7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yJ9
|
|
||||||
45
dist_ts/smarttime.classes.timestamp.d.ts
vendored
45
dist_ts/smarttime.classes.timestamp.d.ts
vendored
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLmNsYXNzZXMudGltZXN0YW1wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUVBOzs7R0FHRztBQUNILE1BQWEsU0FBUztJQXVDcEIsWUFBWSxVQUFtQjtRQUwvQjs7V0FFRztRQUNJLFdBQU0sR0FBVyxJQUFJLENBQUM7UUFHM0IsSUFBSSxDQUFDLFVBQVUsRUFBRTtZQUNmLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQztTQUN4QjthQUFNLElBQUksT0FBTyxVQUFVLEtBQUssUUFBUSxFQUFFO1lBQ3pDLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUM7U0FDbEM7UUFDRCxJQUFJLENBQUMsWUFBWSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDeEMsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQUFDLENBQUM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BQUksU0FBUyxDQUFDLGdCQUFnQixDQUFDLENBQUM7UUFDekQsT0FBTyxJQUFJLENBQUMsMkJBQTJCLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztJQUM1RCxDQUFDO0NBQ0Y7QUFoRkQsOEJBZ0ZDIn0=
|
|
||||||
6
dist_ts/smarttime.plugins.d.ts
vendored
6
dist_ts/smarttime.plugins.d.ts
vendored
@@ -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 };
|
|
||||||
@@ -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=
|
|
||||||
17
dist_ts/smarttime.units.d.ts
vendored
17
dist_ts/smarttime.units.d.ts
vendored
@@ -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;
|
|
||||||
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLnVuaXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR0aW1lLnVuaXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFXLFFBQUEsS0FBSyxHQUFHO0lBQ2pCLEtBQUssRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDLEVBQVUsRUFBRTtRQUM5QixPQUFPLFFBQVEsR0FBRyxRQUFRLENBQUM7SUFDN0IsQ0FBQztJQUNELE1BQU0sRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDLEVBQVUsRUFBRTtRQUMvQixPQUFPLFFBQVEsR0FBRyxPQUFPLENBQUM7SUFDNUIsQ0FBQztJQUNELEtBQUssRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDLEVBQUUsRUFBRTtRQUN0QixPQUFPLFFBQVEsR0FBRyxPQUFPLENBQUM7SUFDNUIsQ0FBQztJQUNELElBQUksRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDLEVBQUUsRUFBRTtRQUNyQixPQUFPLFFBQVEsR0FBRyxNQUFNLENBQUM7SUFDM0IsQ0FBQztJQUNELEtBQUssRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDLEVBQUUsRUFBRTtRQUN0QixPQUFPLFFBQVEsR0FBRyxLQUFLLENBQUM7SUFDMUIsQ0FBQztJQUNELE9BQU8sRUFBRSxDQUFDLFFBQVEsR0FBRyxDQUFDLEVBQUUsRUFBRTtRQUN4QixPQUFPLFFBQVEsR0FBRyxLQUFLLENBQUM7SUFDMUIsQ0FBQztDQUNGLENBQUM7QUFXUyxRQUFBLHdCQUF3QixHQUFHLENBQUMsY0FBbUMsR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CLENBQUMsQ0FBQyJ9
|
|
||||||
21
license
Normal file
21
license
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Lossless GmbH (hello@lossless.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,16 +1,35 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"@git.zone/cli": {
|
||||||
"npmGlobalTools": [],
|
"projectType": "npm",
|
||||||
"npmAccessLevel": "public"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smarttime",
|
"gitrepo": "smarttime",
|
||||||
"shortDescription": "handle time in smart ways",
|
"description": "Provides utilities for advanced time handling including cron jobs, timestamps, intervals, and more.",
|
||||||
"npmPackagename": "@pushrocks/smarttime",
|
"npmPackagename": "@push.rocks/smarttime",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"time handling",
|
||||||
|
"cron jobs",
|
||||||
|
"timestamps",
|
||||||
|
"time intervals",
|
||||||
|
"date operations",
|
||||||
|
"time formatting",
|
||||||
|
"scheduling"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"@git.zone/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"
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
3288
package-lock.json
generated
3288
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
75
package.json
75
package.json
@@ -1,42 +1,63 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@push.rocks/smarttime",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.13",
|
"version": "4.2.2",
|
||||||
"description": "handle time in smart ways",
|
"description": "Provides utilities for advanced time handling including cron jobs, timestamps, intervals, and more.",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest ./test/)",
|
"test": "(tstest ./test)",
|
||||||
"build": "(tsbuild && tsbundle npm)"
|
"build": "(tsbuild --web && tsbundle npm)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@git.zone/tsbuild": "^4.1.2",
|
||||||
"@gitzone/tsbundle": "^1.0.69",
|
"@git.zone/tsbundle": "^2.8.3",
|
||||||
"@gitzone/tsrun": "^1.2.6",
|
"@git.zone/tsrun": "^2.0.1",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@git.zone/tstest": "^3.1.8",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@push.rocks/tapbundle": "^6.0.3",
|
||||||
"@types/node": "^14.0.5",
|
"@types/node": "^25.2.3"
|
||||||
"tslint": "^6.1.2",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.6",
|
"@push.rocks/lik": "^6.2.2",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@types/cron": "^1.7.1",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@types/luxon": "^1.15.1",
|
"croner": "^10.0.1",
|
||||||
"cron-parser": "^2.14.0",
|
"date-fns": "^4.1.0",
|
||||||
"luxon": "^1.16.0"
|
"dayjs": "^1.11.19",
|
||||||
|
"is-nan": "^1.3.2",
|
||||||
|
"pretty-ms": "^9.3.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"assets/*",
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
]
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
],
|
||||||
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9977
pnpm-lock.yaml
generated
Normal file
9977
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
301
readme.md
301
readme.md
@@ -1,50 +1,283 @@
|
|||||||
# @pushrocks/smarttime
|
# @push.rocks/smarttime
|
||||||
handle time in smart ways
|
|
||||||
|
|
||||||
## Availabililty and Links
|
Handle time in smart ways — cron scheduling, extended dates, precise measurements, timers, intervals, and human-readable formatting. 🕐
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smarttime)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smarttime)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smarttime)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smarttime/)
|
|
||||||
|
|
||||||
## Status for master
|
## Issue Reporting and Security
|
||||||
[](https://gitlab.com/pushrocks/smarttime/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smarttime/commits/master)
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smarttime)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smarttime)
|
## Install
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
```bash
|
||||||
[](https://prettier.io/)
|
npm install @push.rocks/smarttime
|
||||||
|
```
|
||||||
|
|
||||||
|
or with pnpm:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install @push.rocks/smarttime
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
`@push.rocks/smarttime` is a comprehensive TypeScript-first toolkit for working with time. It covers everything from cron-based scheduling and extended date manipulation to high-resolution measurements, timers, intervals, and human-readable time formatting.
|
||||||
|
|
||||||
Smarttime offers smart ways to deal with time.
|
All examples below use ESM imports and TypeScript.
|
||||||
|
|
||||||
### class CronManager
|
### ⏱️ Time Units & Calculations
|
||||||
This class provides scheduling of functions with a cron syntax
|
|
||||||
|
Convert human-readable time durations into milliseconds using the `units` helpers and `getMilliSecondsFromUnits`:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { CronManager } from '@pushrocks/smarrtime';
|
import { units, getMilliSecondsFromUnits } from '@push.rocks/smarttime';
|
||||||
const cronManagerInstance = new CronManager();
|
|
||||||
cronManagerInstance.addConrjob('* * * * * *', async () => {
|
// Individual unit conversions
|
||||||
console.log('hello'); // will log 'hello' to console once every second;
|
const oneDay = units.days(1); // 86400000
|
||||||
})
|
const twoHours = units.hours(2); // 7200000
|
||||||
cronManagerInstance.start();
|
const thirtySeconds = units.seconds(30); // 30000
|
||||||
|
|
||||||
|
// Combined duration — great for timeouts, TTLs, cache expiration, etc.
|
||||||
|
const duration = getMilliSecondsFromUnits({
|
||||||
|
years: 1,
|
||||||
|
months: 2,
|
||||||
|
weeks: 3,
|
||||||
|
days: 4,
|
||||||
|
hours: 5,
|
||||||
|
minutes: 6,
|
||||||
|
seconds: 7,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Duration: ${duration}ms`);
|
||||||
```
|
```
|
||||||
|
|
||||||
### class ExtendedDate
|
### 🗓️ Human-Readable Time Formatting
|
||||||
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
|
|
||||||
|
|
||||||
```TypeScript
|
Turn raw milliseconds into a friendly string, or get a relative "time ago" description:
|
||||||
import { ExtendedDate } from '@pushrocks/smarttime'
|
|
||||||
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
```typescript
|
||||||
|
import {
|
||||||
|
getMilliSecondsAsHumanReadableString,
|
||||||
|
getMilliSecondsAsHumanReadableAgoTime,
|
||||||
|
} from '@push.rocks/smarttime';
|
||||||
|
|
||||||
|
// "2h 30m"
|
||||||
|
console.log(getMilliSecondsAsHumanReadableString(9_000_000));
|
||||||
|
|
||||||
|
// "5 minutes ago" style output
|
||||||
|
const fiveMinutesAgo = Date.now() - 5 * 60 * 1000;
|
||||||
|
console.log(getMilliSecondsAsHumanReadableAgoTime(fiveMinutesAgo));
|
||||||
```
|
```
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
### 🔄 CronManager — Scheduled Task Execution
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
The `CronManager` lets you register and run multiple cron jobs using standard 6-field cron syntax (seconds included). Powered by [croner](https://github.com/Hexagon/croner).
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
```typescript
|
||||||
|
import { CronManager } from '@push.rocks/smarttime';
|
||||||
|
|
||||||
|
const cronManager = new CronManager();
|
||||||
|
|
||||||
|
// Run every 10 seconds
|
||||||
|
const job1 = cronManager.addCronjob('*/10 * * * * *', async (triggerTime) => {
|
||||||
|
console.log(`Job 1 triggered at ${new Date(triggerTime).toISOString()}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Run every full minute
|
||||||
|
const job2 = cronManager.addCronjob('0 * * * * *', async () => {
|
||||||
|
console.log('Full minute tick!');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start all registered jobs
|
||||||
|
cronManager.start();
|
||||||
|
|
||||||
|
// Later: remove a specific job
|
||||||
|
cronManager.removeCronjob(job1);
|
||||||
|
|
||||||
|
// Stop all jobs
|
||||||
|
cronManager.stop();
|
||||||
|
```
|
||||||
|
|
||||||
|
The `CronManager` automatically calculates the shortest sleep interval between jobs and efficiently schedules wake-ups — no polling required.
|
||||||
|
|
||||||
|
### 📅 ExtendedDate — Enhanced Date Handling
|
||||||
|
|
||||||
|
`ExtendedDate` extends the native JavaScript `Date` with factory methods for common date formats and useful inspection methods:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { ExtendedDate } from '@push.rocks/smarttime';
|
||||||
|
|
||||||
|
// From European format: "DD.MM.YYYY"
|
||||||
|
const date1 = ExtendedDate.fromEuropeanDate('25.12.2024');
|
||||||
|
|
||||||
|
// From European date + time with timezone context
|
||||||
|
const date2 = ExtendedDate.fromEuropeanDateAndTime('25.12.2024', '14:30:00', 'Europe/Berlin');
|
||||||
|
|
||||||
|
// From hyphenated date: "YYYY-MM-DD"
|
||||||
|
const date3 = ExtendedDate.fromHyphedDate('2024-12-25');
|
||||||
|
|
||||||
|
// From milliseconds
|
||||||
|
const date4 = ExtendedDate.fromMillis(Date.now());
|
||||||
|
|
||||||
|
// From an existing Date object
|
||||||
|
const date5 = ExtendedDate.fromDate(new Date());
|
||||||
|
|
||||||
|
// Export back to various formats
|
||||||
|
console.log(date1.exportToEuropeanDate()); // "25.12.2024"
|
||||||
|
console.log(date1.exportToHyphedSortableDate()); // "2024-12-25"
|
||||||
|
|
||||||
|
// Get structured date units
|
||||||
|
const units = date1.exportToUnits();
|
||||||
|
console.log(units.monthName); // "December"
|
||||||
|
console.log(units.dayOfTheWeekName); // "Wednesday"
|
||||||
|
|
||||||
|
// Custom formatting (via dayjs)
|
||||||
|
console.log(date1.format('YYYY-MM-DD HH:mm'));
|
||||||
|
|
||||||
|
// Boolean checks
|
||||||
|
console.log(date4.isToday()); // true
|
||||||
|
|
||||||
|
// Time comparison: has less than 1 hour passed since this date?
|
||||||
|
console.log(date4.lessTimePassedToNow({ hours: 1 })); // true
|
||||||
|
console.log(date4.moreTimePassedToNow({ days: 1 })); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
### ⏱️ HrtMeasurement — High-Resolution Timing
|
||||||
|
|
||||||
|
Measure the duration of operations with precision:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { HrtMeasurement } from '@push.rocks/smarttime';
|
||||||
|
|
||||||
|
const measurement = new HrtMeasurement();
|
||||||
|
measurement.start();
|
||||||
|
|
||||||
|
// ... perform some operation ...
|
||||||
|
|
||||||
|
measurement.stop();
|
||||||
|
console.log(`Took ${measurement.milliSeconds}ms`);
|
||||||
|
console.log(`Took ${measurement.nanoSeconds}ns`);
|
||||||
|
|
||||||
|
// Reset and reuse
|
||||||
|
measurement.reset();
|
||||||
|
measurement.start();
|
||||||
|
// ...
|
||||||
|
```
|
||||||
|
|
||||||
|
### ⏲️ Timer — Pausable Countdown
|
||||||
|
|
||||||
|
A promise-based timer with pause, resume, and reset capabilities:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Timer } from '@push.rocks/smarttime';
|
||||||
|
|
||||||
|
const timer = new Timer(5000); // 5-second countdown
|
||||||
|
timer.start();
|
||||||
|
|
||||||
|
// Await completion
|
||||||
|
await timer.completed;
|
||||||
|
console.log('Timer finished!');
|
||||||
|
|
||||||
|
// Or use pause/resume
|
||||||
|
const timer2 = new Timer(10000);
|
||||||
|
timer2.start();
|
||||||
|
|
||||||
|
// Pause after 3 seconds
|
||||||
|
setTimeout(() => timer2.pause(), 3000);
|
||||||
|
|
||||||
|
// Resume later
|
||||||
|
setTimeout(() => timer2.resume(), 6000);
|
||||||
|
|
||||||
|
await timer2.completed;
|
||||||
|
|
||||||
|
// Reset completely and start over
|
||||||
|
timer2.reset();
|
||||||
|
timer2.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
Check remaining time with `timer.timeLeft`.
|
||||||
|
|
||||||
|
### 🔁 Interval — Repeating Jobs
|
||||||
|
|
||||||
|
Run functions at a fixed interval with start/stop control:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Interval } from '@push.rocks/smarttime';
|
||||||
|
|
||||||
|
const interval = new Interval(2000); // Every 2 seconds
|
||||||
|
|
||||||
|
interval.addIntervalJob(() => {
|
||||||
|
console.log('Tick!', new Date().toISOString());
|
||||||
|
});
|
||||||
|
|
||||||
|
interval.addIntervalJob(() => {
|
||||||
|
console.log('Another parallel job');
|
||||||
|
});
|
||||||
|
|
||||||
|
interval.start();
|
||||||
|
|
||||||
|
// Stop later
|
||||||
|
setTimeout(() => interval.stop(), 10000);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🕰️ TimeStamp — Comparison & Tracking
|
||||||
|
|
||||||
|
The `TimeStamp` class captures a moment in time and provides comparison utilities:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { TimeStamp } from '@push.rocks/smarttime';
|
||||||
|
|
||||||
|
const stamp1 = new TimeStamp();
|
||||||
|
// ... some time passes ...
|
||||||
|
const stamp2 = new TimeStamp();
|
||||||
|
|
||||||
|
console.log(stamp1.milliSeconds); // Unix ms
|
||||||
|
console.log(stamp1.epochtime); // Unix seconds
|
||||||
|
|
||||||
|
// Comparison
|
||||||
|
console.log(stamp1.isOlderThan(stamp2)); // true
|
||||||
|
console.log(stamp2.isYoungerThanOtherTimeStamp(stamp1)); // true
|
||||||
|
|
||||||
|
// Derived timestamps track change
|
||||||
|
const derived = TimeStamp.fromTimeStamp(stamp1);
|
||||||
|
console.log(`${derived.change}ms have passed since stamp1`);
|
||||||
|
|
||||||
|
// From known milliseconds
|
||||||
|
const known = TimeStamp.fromMilliSeconds(1700000000000);
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Overview
|
||||||
|
|
||||||
|
| Export | Description |
|
||||||
|
|---|---|
|
||||||
|
| `CronManager` | Register and run multiple cron jobs with automatic scheduling |
|
||||||
|
| `CronJob` | Individual cron job (created via `CronManager.addCronjob()`) |
|
||||||
|
| `ExtendedDate` | Enhanced `Date` with factory methods and formatting |
|
||||||
|
| `HrtMeasurement` | High-resolution time measurement |
|
||||||
|
| `Timer` | Promise-based countdown with pause/resume/reset |
|
||||||
|
| `Interval` | Repeating job execution at fixed intervals |
|
||||||
|
| `TimeStamp` | Point-in-time capture with comparison utilities |
|
||||||
|
| `units` | Time unit conversion functions (`days()`, `hours()`, etc.) |
|
||||||
|
| `getMilliSecondsFromUnits()` | Convert combined time units to milliseconds |
|
||||||
|
| `getMilliSecondsAsHumanReadableString()` | Format ms as human-readable string |
|
||||||
|
| `getMilliSecondsAsHumanReadableAgoTime()` | Format timestamp as relative "ago" string |
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
||||||
|
|
||||||
|
**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.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
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 or third parties, 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 or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or 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
3
test/ondemand.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import * as smarttime from '../ts/index.js';
|
||||||
|
|
||||||
|
console.log(smarttime.getMilliSecondsAsHumanReadableAgoTime(Date.now()));
|
||||||
@@ -1,35 +1,34 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import * as smarttime from '../ts/index.js';
|
||||||
import * as smarttime from '../ts/index';
|
|
||||||
|
|
||||||
// Test TimeStamp class
|
// Test TimeStamp class
|
||||||
let testTimeStamp: smarttime.TimeStamp;
|
let testTimeStamp: smarttime.TimeStamp;
|
||||||
let testTimeStamp2: 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();
|
testTimeStamp = new smarttime.TimeStamp();
|
||||||
await tools.delayFor(2);
|
await tools.delayFor(2);
|
||||||
testTimeStamp2 = new smarttime.TimeStamp();
|
testTimeStamp2 = new smarttime.TimeStamp();
|
||||||
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp);
|
expect(testTimeStamp).toBeInstanceOf(smarttime.TimeStamp);
|
||||||
expect(testTimeStamp).to.be.instanceof(smarttime.TimeStamp);
|
expect(testTimeStamp).toBeInstanceOf(smarttime.TimeStamp);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should have valid linuxtime', async () => {
|
tap.test('should have valid linuxtime', async () => {
|
||||||
// tslint:disable-next-line:no-unused-expression
|
// tslint:disable-next-line:no-unused-expression
|
||||||
expect(testTimeStamp.isOlderThan(testTimeStamp2)).to.be.true;
|
expect(testTimeStamp.isOlderThan(testTimeStamp2)).toBeTrue();
|
||||||
// tslint:disable-next-line:no-unused-expression
|
// tslint:disable-next-line:no-unused-expression
|
||||||
expect(testTimeStamp.isYoungerThanOtherTimeStamp(testTimeStamp2)).to.be.false;
|
expect(testTimeStamp.isYoungerThanOtherTimeStamp(testTimeStamp2)).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
let testHrtMeasurement: smarttime.HrtMeasurement;
|
let testHrtMeasurement: smarttime.HrtMeasurement;
|
||||||
|
|
||||||
// Test HrtMeasurement
|
// Test HrtMeasurement
|
||||||
tap.test('should create valid HrtMeasurements', async tools => {
|
tap.test('should create valid HrtMeasurements', async (tools) => {
|
||||||
testHrtMeasurement = new smarttime.HrtMeasurement();
|
testHrtMeasurement = new smarttime.HrtMeasurement();
|
||||||
testHrtMeasurement.start();
|
testHrtMeasurement.start();
|
||||||
await tools.delayFor(20);
|
await tools.delayFor(20);
|
||||||
testHrtMeasurement.stop();
|
testHrtMeasurement.stop();
|
||||||
expect(testHrtMeasurement.milliSeconds).to.be.greaterThan(19);
|
expect(testHrtMeasurement.milliSeconds).toBeGreaterThan(19);
|
||||||
expect(testHrtMeasurement.milliSeconds).to.be.lessThan(25);
|
expect(testHrtMeasurement.milliSeconds).toBeLessThan(25);
|
||||||
});
|
});
|
||||||
|
|
||||||
// check units
|
// check units
|
||||||
@@ -41,10 +40,10 @@ tap.test('should combine units', async () => {
|
|||||||
weeks: 2,
|
weeks: 2,
|
||||||
days: 2,
|
days: 2,
|
||||||
hours: 2,
|
hours: 2,
|
||||||
minutes: 2
|
minutes: 2,
|
||||||
});
|
});
|
||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
console.log(computedTime);
|
console.log(computedTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
60
test/test.cronmanager.both.ts
Normal file
60
test/test.cronmanager.both.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
|
import * as smarttime from '../ts/index.js';
|
||||||
|
|
||||||
|
let testCronManager: smarttime.CronManager;
|
||||||
|
|
||||||
|
tap.test('should create a valid instance of cronmanager', async () => {
|
||||||
|
testCronManager = new smarttime.CronManager();
|
||||||
|
expect(testCronManager).toBeInstanceOf(smarttime.CronManager);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create a valid cronJon', async (tools) => {
|
||||||
|
const done = tools.defer();
|
||||||
|
const done2 = tools.defer();
|
||||||
|
const done3 = tools.defer();
|
||||||
|
let counter = 0;
|
||||||
|
let counter2 = 0;
|
||||||
|
let counter3 = 0;
|
||||||
|
const cronJob = testCronManager.addCronjob('*/2 * * * * *', async () => {
|
||||||
|
if (counter === 5) {
|
||||||
|
testCronManager.removeCronjob(cronJob);
|
||||||
|
done.resolve();
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
console.log(`${new Date().getSeconds()} hey ${counter} -> runs every 2 seconds`);
|
||||||
|
});
|
||||||
|
const cronJob2 = testCronManager.addCronjob('*/3 * * * * *', async () => {
|
||||||
|
if (counter2 === 5) {
|
||||||
|
testCronManager.removeCronjob(cronJob2);
|
||||||
|
done2.resolve();
|
||||||
|
}
|
||||||
|
counter2++;
|
||||||
|
console.log(`${new Date().getSeconds()} hey ${counter2} -> runs every 3 seconds`);
|
||||||
|
});
|
||||||
|
const cronJob3 = testCronManager.addCronjob('*/4 * * * * *', async () => {
|
||||||
|
if (counter3 === 5) {
|
||||||
|
done3.resolve();
|
||||||
|
}
|
||||||
|
counter3++;
|
||||||
|
console.log(`${new Date().getSeconds()} hey ${counter3} -> runs every 4 seconds`);
|
||||||
|
});
|
||||||
|
testCronManager.start();
|
||||||
|
await done.promise;
|
||||||
|
await done2.promise;
|
||||||
|
await done3.promise;
|
||||||
|
testCronManager.stop();
|
||||||
|
testCronManager.removeCronjob(cronJob3);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('runs every full minute', async (tools) => {
|
||||||
|
const done = tools.defer();
|
||||||
|
const cronJob = testCronManager.addCronjob('0 * * * * *', async () => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
testCronManager.start();
|
||||||
|
await done.promise;
|
||||||
|
testCronManager.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default tap.start();
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
|
||||||
|
|
||||||
import * as smarttime from '../ts/index';
|
|
||||||
|
|
||||||
let testCronManager: smarttime.CronManager;
|
|
||||||
|
|
||||||
tap.test('should create a valid instance of cronmanager', async () => {
|
|
||||||
testCronManager = new smarttime.CronManager();
|
|
||||||
expect(testCronManager).to.be.instanceOf(smarttime.CronManager);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should create a valid cronJon', async tools => {
|
|
||||||
const done = tools.defer();
|
|
||||||
let counter = 0;
|
|
||||||
testCronManager.addCronjob('* * * * * *', () => {
|
|
||||||
if (counter === 10) {
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
console.log(`hey ${counter}`);
|
|
||||||
});
|
|
||||||
testCronManager.start();
|
|
||||||
await done.promise;
|
|
||||||
testCronManager.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index.js';
|
||||||
|
|
||||||
|
tap.test('should create a valid JavaScript Date', async () => {
|
||||||
|
const extendedDate = new smarttime.ExtendedDate(Date.now());
|
||||||
|
console.log(extendedDate);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
||||||
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
|
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
|
||||||
@@ -18,7 +23,12 @@ tap.test('should create a date and time with European Format', async () => {
|
|||||||
|
|
||||||
tap.test('should create a European date string', async () => {
|
tap.test('should create a European date string', async () => {
|
||||||
const extendedDate = smarttime.ExtendedDate.fromHyphedDate('2018-02-13');
|
const extendedDate = smarttime.ExtendedDate.fromHyphedDate('2018-02-13');
|
||||||
expect(extendedDate.exportToEuropeanDate()).to.equal('13.02.2018');
|
expect(extendedDate.exportToEuropeanDate()).toEqual('13.02.2018');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.test('should format a date', async () => {
|
||||||
|
const extendedDate = new smarttime.ExtendedDate(Date.now());
|
||||||
|
console.log(extendedDate.format('YYYY-MM-DD - hh:mm'));
|
||||||
|
});
|
||||||
|
|
||||||
|
export default tap.start();
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
|
|
||||||
import { Timer } from '../ts/index';
|
import { Timer } from '../ts/index.js';
|
||||||
|
|
||||||
let testTimer: Timer;
|
let testTimer: Timer;
|
||||||
|
|
||||||
tap.test('should create a valid timer', async () => {
|
tap.test('should create a valid timer', async () => {
|
||||||
testTimer = new Timer(1000);
|
testTimer = new Timer(1000);
|
||||||
expect(testTimer).to.be.instanceof(Timer);
|
expect(testTimer).toBeInstanceOf(Timer);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start timer', async () => {
|
tap.test('should start timer', async () => {
|
||||||
@@ -23,4 +22,4 @@ tap.test('should reset a timer', async () => {
|
|||||||
await testTimer.completed;
|
await testTimer.completed;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smarttime',
|
||||||
|
version: '4.2.2',
|
||||||
|
description: 'Provides utilities for advanced time handling including cron jobs, timestamps, intervals, and more.'
|
||||||
|
}
|
||||||
18
ts/index.ts
18
ts/index.ts
@@ -1,10 +1,8 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
export * from './smarttime.classes.cronmanager.js';
|
||||||
|
export * from './smarttime.classes.cronjob.js';
|
||||||
export * from './smarttime.classes.cronmanager';
|
export * from './smarttime.classes.extendeddate.js';
|
||||||
export * from './smarttime.classes.extendeddate';
|
export * from './smarttime.classes.hrtmeasurement.js';
|
||||||
export * from './smarttime.classes.hrtmeasurement';
|
export * from './smarttime.classes.interval.js';
|
||||||
export * from './smarttime.classes.timer';
|
export * from './smarttime.classes.timer.js';
|
||||||
export * from './smarttime.classes.timestamp';
|
export * from './smarttime.classes.timestamp.js';
|
||||||
export * from './smarttime.units';
|
export * from './smarttime.units.js';
|
||||||
|
|
||||||
export { luxon } from './smarttime.plugins';
|
|
||||||
|
|||||||
@@ -1,45 +1,59 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
import { CronManager } from './smarttime.classes.cronmanager';
|
import { CronManager } from './smarttime.classes.cronmanager.js';
|
||||||
|
|
||||||
export type TJobFunction = (() => void) | (() => Promise<any>);
|
export type TJobFunction =
|
||||||
|
| ((triggerTimeArg?: number) => void)
|
||||||
|
| ((triggerTimeArg?: number) => Promise<any>);
|
||||||
|
|
||||||
export class CronJob {
|
export class CronJob {
|
||||||
|
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;
|
||||||
|
|
||||||
private cronInterval= plugins.cronParser.parseExpression('* * * * * *');
|
|
||||||
private nextExecutionUnix: number = 0;
|
private nextExecutionUnix: number = 0;
|
||||||
|
|
||||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction ) {
|
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
||||||
this.cronExpression = cronExpressionArg;
|
this.cronExpression = cronExpressionArg;
|
||||||
this.jobFunction = jobFunction;
|
this.jobFunction = jobFunction;
|
||||||
|
this.cronParser = new plugins.croner.Cron(cronExpressionArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks wether the cronjob needs to be executed
|
* checks wether the cronjob needs to be executed
|
||||||
*/
|
*/
|
||||||
public checkExecution() {
|
public checkExecution(): number {
|
||||||
|
if (this.status === 'stopped') {
|
||||||
|
return this.nextExecutionUnix;
|
||||||
|
}
|
||||||
if (this.nextExecutionUnix === 0) {
|
if (this.nextExecutionUnix === 0) {
|
||||||
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
|
this.getNextExecutionTime();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (Date.now() > this.nextExecutionUnix) {
|
if (Date.now() > this.nextExecutionUnix) {
|
||||||
this.jobFunction();
|
const maybePromise = this.jobFunction(this.nextExecutionUnix);
|
||||||
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
|
if (maybePromise instanceof Promise) {
|
||||||
|
maybePromise.catch((e) => console.log(e));
|
||||||
|
}
|
||||||
|
this.nextExecutionUnix = this.getNextExecutionTime();
|
||||||
}
|
}
|
||||||
|
return this.nextExecutionUnix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getNextExecutionTime() {
|
||||||
|
return (this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the time to next execution
|
||||||
|
*/
|
||||||
|
public getTimeToNextExecution() {
|
||||||
|
return this.cronParser.msToNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
this.cronInterval = this.getCronInterval();
|
|
||||||
this.status = 'started';
|
this.status = 'started';
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop() {
|
public stop() {
|
||||||
this.status = 'stopped';
|
this.status = 'stopped';
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCronInterval () {
|
|
||||||
return plugins.cronParser.parseExpression(this.cronExpression);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,42 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
import { CronJob } from './smarttime.classes.cronjob';
|
import { CronJob, type TJobFunction } from './smarttime.classes.cronjob.js';
|
||||||
import { Timer } from './smarttime.classes.timer';
|
|
||||||
import { Interval } from './smarttime.classes.interval';
|
|
||||||
|
|
||||||
export class CronManager {
|
export class CronManager {
|
||||||
public cronInterval = new Interval(1000);
|
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
||||||
|
|
||||||
public status: 'started' | 'stopped' = 'stopped';
|
public status: 'started' | 'stopped' = 'stopped';
|
||||||
public cronjobs: CronJob[] = [];
|
public cronjobs = new plugins.lik.ObjectMap<CronJob>();
|
||||||
|
|
||||||
constructor() {
|
private cycleWakeDeferred: plugins.smartpromise.Deferred<void> | null = null;
|
||||||
this.cronInterval.addIntervalJob(() => {
|
|
||||||
for (const cronJob of this.cronjobs) {
|
constructor() {}
|
||||||
cronJob.checkExecution();
|
|
||||||
}
|
/**
|
||||||
});
|
* Resolves the current wake deferred, causing the sleeping cycle
|
||||||
|
* to immediately recalculate instead of waiting for its timeout.
|
||||||
|
*/
|
||||||
|
private wakeCycle() {
|
||||||
|
if (this.cycleWakeDeferred && this.cycleWakeDeferred.status === 'pending') {
|
||||||
|
this.cycleWakeDeferred.resolve();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public addCronjob(cronIdentifierArg: string, cronFunctionArg: () => any) {
|
public addCronjob(cronIdentifierArg: string, cronFunctionArg: TJobFunction) {
|
||||||
const newCronJob = new CronJob(this, cronIdentifierArg, cronFunctionArg);
|
const newCronJob = new CronJob(this, cronIdentifierArg, cronFunctionArg);
|
||||||
this.cronjobs.push(newCronJob);
|
this.cronjobs.add(newCronJob);
|
||||||
if (this.status === 'started') {
|
if (this.status === 'started') {
|
||||||
newCronJob.start();
|
newCronJob.start();
|
||||||
|
this.wakeCycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
return newCronJob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public removeCronjob(cronjobArg: CronJob) {
|
||||||
|
cronjobArg.stop();
|
||||||
|
this.cronjobs.remove(cronjobArg);
|
||||||
|
if (this.status === 'started') {
|
||||||
|
this.wakeCycle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,21 +44,63 @@ export class CronManager {
|
|||||||
* starts the cronjob
|
* starts the cronjob
|
||||||
*/
|
*/
|
||||||
public start() {
|
public start() {
|
||||||
this.status = 'started';
|
if (this.status !== 'started') {
|
||||||
for (const cron of this.cronjobs) {
|
this.status = 'started';
|
||||||
cron.start();
|
for (const cronJob of this.cronjobs.getArray()) {
|
||||||
|
cronJob.start();
|
||||||
|
}
|
||||||
|
this.runCronCycle();
|
||||||
}
|
}
|
||||||
this.cronInterval.start();
|
}
|
||||||
|
|
||||||
|
private async runCronCycle() {
|
||||||
|
while (this.status === 'started') {
|
||||||
|
// Create a fresh wake signal for this iteration
|
||||||
|
this.cycleWakeDeferred = new plugins.smartpromise.Deferred<void>();
|
||||||
|
|
||||||
|
// Check all cronjobs and find the soonest next execution
|
||||||
|
let soonestMs = Infinity;
|
||||||
|
for (const cronJob of this.cronjobs.getArray()) {
|
||||||
|
cronJob.checkExecution();
|
||||||
|
const msToNext = cronJob.getTimeToNextExecution();
|
||||||
|
if (msToNext < soonestMs) {
|
||||||
|
soonestMs = msToNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sleep until the next job is due or until woken by a lifecycle event
|
||||||
|
if (soonestMs < Infinity && soonestMs > 0) {
|
||||||
|
this.executionTimeout = new plugins.smartdelay.Timeout(soonestMs);
|
||||||
|
await Promise.race([
|
||||||
|
this.executionTimeout.promise,
|
||||||
|
this.cycleWakeDeferred.promise,
|
||||||
|
]);
|
||||||
|
// Cancel the timeout to avoid lingering timers
|
||||||
|
this.executionTimeout.cancel();
|
||||||
|
} else if (soonestMs <= 0) {
|
||||||
|
// Job is overdue, loop immediately to execute it
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
// No jobs — wait indefinitely until woken by addCronjob or stop
|
||||||
|
await this.cycleWakeDeferred.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.cycleWakeDeferred = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stops all cronjobs
|
* stops all cronjobs
|
||||||
*/
|
*/
|
||||||
public stop() {
|
public stop() {
|
||||||
this.status = 'stopped';
|
if (this.status === 'started') {
|
||||||
for (const cron of this.cronjobs) {
|
this.status = 'stopped';
|
||||||
|
if (this.executionTimeout) {
|
||||||
|
this.executionTimeout.cancel();
|
||||||
|
}
|
||||||
|
this.wakeCycle();
|
||||||
|
}
|
||||||
|
for (const cron of this.cronjobs.getArray()) {
|
||||||
cron.stop();
|
cron.stop();
|
||||||
}
|
}
|
||||||
this.cronInterval.stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
88
ts/smarttime.classes.cronparser.ts
Normal file
88
ts/smarttime.classes.cronparser.ts
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
|
export class CronParser {
|
||||||
|
public cronExpression: string;
|
||||||
|
public get cronArray() {
|
||||||
|
return this.cronExpression.split(' ');
|
||||||
|
}
|
||||||
|
constructor(cronExpressionArg: string) {
|
||||||
|
this.cronExpression = cronExpressionArg;
|
||||||
|
if (this.cronArray.length < 6) {
|
||||||
|
throw new Error('CronParser needs second level accuracy');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getNextPartMatch(cronPart: string, startValue: number, moduloArg: number) {
|
||||||
|
if (cronPart === '*') {
|
||||||
|
return startValue;
|
||||||
|
}
|
||||||
|
if (cronPart.includes('/')) {
|
||||||
|
const every = parseInt(cronPart.split('/')[1], 10);
|
||||||
|
const findEvenMatch = (recursionStartArg: number): number => {
|
||||||
|
if (recursionStartArg % every === 0) {
|
||||||
|
return recursionStartArg;
|
||||||
|
} else {
|
||||||
|
return findEvenMatch(recursionStartArg + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return findEvenMatch(startValue);
|
||||||
|
}
|
||||||
|
if (parseInt(cronPart, 10) || cronPart === '0') {
|
||||||
|
const match = parseInt(cronPart, 10);
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public msToNext() {
|
||||||
|
const cronArray = this.cronArray;
|
||||||
|
const secondExpression = cronArray[0];
|
||||||
|
const minuteExpression = cronArray[1];
|
||||||
|
const hourExpression = cronArray[2];
|
||||||
|
const dayExpression = cronArray[3];
|
||||||
|
const monthExpression = cronArray[4];
|
||||||
|
const yearExpression = cronArray[5];
|
||||||
|
|
||||||
|
let currentDate = new Date();
|
||||||
|
let currentSecond = currentDate.getSeconds() + 1;
|
||||||
|
let currentMinute = currentDate.getMinutes();
|
||||||
|
let currentHour = currentDate.getHours();
|
||||||
|
let currentDay = currentDate.getDate();
|
||||||
|
let currentMonth = currentDate.getMonth();
|
||||||
|
let currentYear = currentDate.getFullYear();
|
||||||
|
|
||||||
|
const targetSecond = this.getNextPartMatch(secondExpression, currentSecond, 59);
|
||||||
|
if (targetSecond < currentSecond) {
|
||||||
|
currentMinute = (currentMinute + 1) % 59;
|
||||||
|
}
|
||||||
|
const targetMinute = this.getNextPartMatch(minuteExpression, currentMinute, 59);
|
||||||
|
if (targetMinute < currentMinute) {
|
||||||
|
currentHour = (currentHour + 1) % 23;
|
||||||
|
}
|
||||||
|
const targetHour = this.getNextPartMatch(hourExpression, currentHour, 23);
|
||||||
|
if (targetHour < currentHour) {
|
||||||
|
currentDay = (currentDay + 1) % 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetDay = currentDay;
|
||||||
|
if (targetDay < currentDay) {
|
||||||
|
currentMonth = (currentMonth + 1) % 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetMonth = currentMonth;
|
||||||
|
if (targetMonth < currentMonth) {
|
||||||
|
currentYear = currentYear + 1;
|
||||||
|
}
|
||||||
|
const targetYear = currentYear;
|
||||||
|
|
||||||
|
const targetDate = new Date(
|
||||||
|
targetYear,
|
||||||
|
targetMonth,
|
||||||
|
targetDay,
|
||||||
|
targetHour,
|
||||||
|
targetMinute,
|
||||||
|
targetSecond
|
||||||
|
);
|
||||||
|
const targetTime = targetDate.getTime();
|
||||||
|
return targetTime - Date.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
import * as units from './smarttime.units.js';
|
||||||
|
|
||||||
export type TAvailableZone = 'Europe/Berlin';
|
export type TAvailableZone = 'Europe/Berlin';
|
||||||
|
|
||||||
@@ -26,12 +27,12 @@ export class ExtendedDate extends Date {
|
|||||||
|
|
||||||
public static fromEuropeanDate(europeanDate: string) {
|
public static fromEuropeanDate(europeanDate: string) {
|
||||||
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate);
|
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate);
|
||||||
const luxonDate = plugins.luxon.DateTime.utc(
|
const date = new Date(
|
||||||
parseFloat(dateArray[3]), // year
|
parseFloat(dateArray[3]), // year
|
||||||
parseFloat(dateArray[2]), // month
|
parseFloat(dateArray[2]) - 1, // month
|
||||||
parseFloat(dateArray[1]) // day
|
parseFloat(dateArray[1]) // day
|
||||||
);
|
);
|
||||||
const unixMilli = luxonDate.toMillis();
|
const unixMilli = date.getTime();
|
||||||
return new ExtendedDate(unixMilli);
|
return new ExtendedDate(unixMilli);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,18 +65,15 @@ export class ExtendedDate extends Date {
|
|||||||
const dateTimeString = `${dateArray[3]}-${sliceDate(dateArray[2])}-${sliceDate(
|
const dateTimeString = `${dateArray[3]}-${sliceDate(dateArray[2])}-${sliceDate(
|
||||||
dateArray[1]
|
dateArray[1]
|
||||||
)}T${timeArg}`;
|
)}T${timeArg}`;
|
||||||
const luxonDate = plugins.luxon.DateTime.fromISO(dateTimeString, {
|
const date = plugins.dayjs(dateTimeString);
|
||||||
zone: zoneArg
|
const unixMilli = date.toDate().getTime();
|
||||||
});
|
|
||||||
const unixMilli = luxonDate.toMillis();
|
|
||||||
return new ExtendedDate(unixMilli);
|
return new ExtendedDate(unixMilli);
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public timezone: TAvailableZone;
|
public timezone: TAvailableZone;
|
||||||
|
|
||||||
|
constructor(unixMilli: number = Date.now()) {
|
||||||
constructor(unixMilli: number) {
|
|
||||||
super(unixMilli);
|
super(unixMilli);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +83,11 @@ export class ExtendedDate extends Date {
|
|||||||
return `${units.dayString}.${units.monthString}.${units.yearString}`;
|
return `${units.dayString}.${units.monthString}.${units.yearString}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public exportToHyphedSortableDate() {
|
||||||
|
const units = this.exportToUnits();
|
||||||
|
return `${units.yearString}-${units.monthString}-${units.dayString}`;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* exports units
|
* exports units
|
||||||
*/
|
*/
|
||||||
@@ -101,7 +104,7 @@ export class ExtendedDate extends Date {
|
|||||||
'September',
|
'September',
|
||||||
'October',
|
'October',
|
||||||
'November',
|
'November',
|
||||||
'December'
|
'December',
|
||||||
];
|
];
|
||||||
const daysArray = [
|
const daysArray = [
|
||||||
'Monday',
|
'Monday',
|
||||||
@@ -110,18 +113,39 @@ export class ExtendedDate extends Date {
|
|||||||
'Thursday',
|
'Thursday',
|
||||||
'Friday',
|
'Friday',
|
||||||
'Saturday',
|
'Saturday',
|
||||||
'Sunday'
|
'Sunday',
|
||||||
];
|
];
|
||||||
return {
|
return {
|
||||||
year: this.getFullYear(),
|
year: this.getFullYear(),
|
||||||
yearString: `${this.getFullYear()}`,
|
yearString: `${this.getFullYear()}`,
|
||||||
month: this.getMonth() + 1,
|
month: this.getMonth() + 1,
|
||||||
monthString: ("0" + (this.getMonth() + 1)).slice(-2),
|
monthString: ('0' + (this.getMonth() + 1)).slice(-2),
|
||||||
monthName: monthsArray[this.getMonth()],
|
monthName: monthsArray[this.getMonth()],
|
||||||
day: this.getDate(),
|
day: this.getDate(),
|
||||||
dayString: ("0" + this.getDate()).slice(-2),
|
dayString: ('0' + this.getDate()).slice(-2),
|
||||||
dayOfTheWeek: this.getDay(),
|
dayOfTheWeek: this.getDay(),
|
||||||
dayOfTheWeekName: daysArray[this.getDay()]
|
dayOfTheWeekName: daysArray[this.getDay()],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public format(formatArg: string) {
|
||||||
|
return plugins.dayjs(this.getTime()).format(formatArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* boolean checks
|
||||||
|
*/
|
||||||
|
public isToday() {
|
||||||
|
return plugins.dayjs(this.getTime()).isToday();
|
||||||
|
}
|
||||||
|
|
||||||
|
public lessTimePassedToNow(unitArgs: units.IUnitCombinationArg): boolean {
|
||||||
|
const maxPassedUnixTime = units.getMilliSecondsFromUnits(unitArgs);
|
||||||
|
const actualPassedUnixTime = Date.now() - this.getTime();
|
||||||
|
return actualPassedUnixTime < maxPassedUnixTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public moreTimePassedToNow(unitArgs: units.IUnitCombinationArg) {
|
||||||
|
return !this.lessTimePassedToNow(unitArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
export class HrtMeasurement {
|
export class HrtMeasurement {
|
||||||
public nanoSeconds: number = null;
|
public nanoSeconds: number = null;
|
||||||
public milliSeconds: number = null;
|
public milliSeconds: number = null;
|
||||||
private _hrTimeStart = null;
|
private _milliStart: number = null;
|
||||||
private _hrTimeStopDiff = null;
|
private _milliDiff: number = null;
|
||||||
private _started: boolean = false;
|
private _started: boolean = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,7 +13,7 @@ export class HrtMeasurement {
|
|||||||
*/
|
*/
|
||||||
public start() {
|
public start() {
|
||||||
this._started = true;
|
this._started = true;
|
||||||
this._hrTimeStart = process.hrtime();
|
this._milliStart = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,9 +24,9 @@ export class HrtMeasurement {
|
|||||||
console.log("Hasn't started yet");
|
console.log("Hasn't started yet");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._hrTimeStopDiff = process.hrtime(this._hrTimeStart);
|
this._milliDiff = Date.now() - this._milliStart;
|
||||||
this.nanoSeconds = this._hrTimeStopDiff[0] * 1e9 + this._hrTimeStopDiff[1];
|
this.nanoSeconds = this._milliDiff * 1000;
|
||||||
this.milliSeconds = this.nanoSeconds / 1000000;
|
this.milliSeconds = this._milliDiff;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ export class HrtMeasurement {
|
|||||||
public reset() {
|
public reset() {
|
||||||
this.nanoSeconds = null;
|
this.nanoSeconds = null;
|
||||||
this.milliSeconds = null;
|
this.milliSeconds = null;
|
||||||
this._hrTimeStart = null;
|
this._milliStart = null;
|
||||||
this._hrTimeStopDiff = null;
|
this._milliDiff = null;
|
||||||
this._started = false;
|
this._started = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
export class Interval {
|
export class Interval {
|
||||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||||
private statusAuthorization: any = null;
|
private statusAuthorization: any = null;
|
||||||
|
|
||||||
|
// timings
|
||||||
public intervalMilliseconds: number;
|
public intervalMilliseconds: number;
|
||||||
|
public nextIntervalMillisenconds: number;
|
||||||
|
|
||||||
public intervalJobs: Array<() => any> = [];
|
public intervalJobs: Array<() => any> = [];
|
||||||
constructor(intervalMillisencondsArg: number) {
|
constructor(intervalMillisencondsArg: number) {
|
||||||
this.intervalMilliseconds = intervalMillisencondsArg;
|
this.intervalMilliseconds = intervalMillisencondsArg;
|
||||||
@@ -23,7 +26,7 @@ export class Interval {
|
|||||||
runInterval();
|
runInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop () {
|
public stop() {
|
||||||
this.status = 'stopped';
|
this.status = 'stopped';
|
||||||
this.statusAuthorization = null;
|
this.statusAuthorization = null;
|
||||||
}
|
}
|
||||||
@@ -32,7 +35,7 @@ export class Interval {
|
|||||||
this.intervalJobs.push(funcArg);
|
this.intervalJobs.push(funcArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private executeIntervalJobs () {
|
private executeIntervalJobs() {
|
||||||
for (const funcArg of this.intervalJobs) {
|
for (const funcArg of this.intervalJobs) {
|
||||||
funcArg();
|
funcArg();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
import { TimeStamp } from './smarttime.classes.timestamp';
|
import { TimeStamp } from './smarttime.classes.timestamp.js';
|
||||||
|
|
||||||
export type TimerState = 'initiated' | 'started' | 'paused' | 'completed';
|
export type TimerState = 'initiated' | 'started' | 'paused' | 'completed';
|
||||||
|
|
||||||
@@ -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>();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TimeStamp
|
* TimeStamp
|
||||||
@@ -8,7 +8,7 @@ export class TimeStamp {
|
|||||||
/**
|
/**
|
||||||
* returns new TimeStamp from milliseconds
|
* returns new TimeStamp from milliseconds
|
||||||
*/
|
*/
|
||||||
public static fromMilliSeconds(milliSecondsArg) {
|
public static fromMilliSeconds(milliSecondsArg: number) {
|
||||||
return new TimeStamp(milliSecondsArg);
|
return new TimeStamp(milliSecondsArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +53,19 @@ export class TimeStamp {
|
|||||||
this.epochtime = Math.floor(this.milliSeconds / 1000);
|
this.epochtime = Math.floor(this.milliSeconds / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a boolean for wether the timestamp is older than another timestamp
|
||||||
|
* @param TimeStampArg
|
||||||
|
* @param tresholdTimeArg
|
||||||
|
*/
|
||||||
|
public isOlderThanOtherTimeStamp(TimeStampArg: TimeStamp, tresholdTimeArg: number = 0) {
|
||||||
|
if (this.milliSeconds < TimeStampArg.milliSeconds - tresholdTimeArg) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the current instance older than the argument
|
* Is the current instance older than the argument
|
||||||
* @param TimeStampArg
|
* @param TimeStampArg
|
||||||
@@ -66,7 +79,7 @@ export class TimeStamp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a boolean for wether a timestamp is younger
|
* returns a boolean for wether the timestamp is younger than another timestamp
|
||||||
* @param TimeStampArg
|
* @param TimeStampArg
|
||||||
* @param tresholdTimeArg
|
* @param tresholdTimeArg
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as lik from '@push.rocks/lik';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartdelay from '@push.rocks/smartdelay';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
|
||||||
export { smartdelay, smartpromise };
|
export { lik, smartdelay, smartpromise };
|
||||||
|
|
||||||
// third parties
|
// third parties;
|
||||||
import cronParser from 'cron-parser';
|
import * as croner from 'croner';
|
||||||
import * as luxon from 'luxon';
|
import * as dateFns from 'date-fns';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import isToday from 'dayjs/plugin/isToday.js';
|
||||||
|
import prettyMs from 'pretty-ms';
|
||||||
|
|
||||||
export { cronParser, luxon };
|
dayjs.extend(isToday);
|
||||||
|
|
||||||
|
export { croner, dateFns, dayjs, prettyMs };
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
export let units = {
|
export let units = {
|
||||||
years: (timesArg = 1): number => {
|
years: (timesArg = 1): number => {
|
||||||
return timesArg * 3.154e10;
|
return timesArg * 3.154e10;
|
||||||
@@ -16,7 +18,10 @@ 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 {
|
||||||
@@ -26,11 +31,12 @@ 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) => {
|
||||||
let timeInMilliseconds = 0;
|
let timeInMilliseconds = 0;
|
||||||
let addMilliSeconds = milliSecondsArg => {
|
let addMilliSeconds = (milliSecondsArg: number) => {
|
||||||
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
||||||
};
|
};
|
||||||
if (combinationArg.years) {
|
if (combinationArg.years) {
|
||||||
@@ -51,6 +57,17 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getMilliSecondsAsHumanReadableString = (milliSecondsArg: number): string => {
|
||||||
|
return plugins.prettyMs(milliSecondsArg);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getMilliSecondsAsHumanReadableAgoTime = (timeStampArg: number): string => {
|
||||||
|
return plugins.dateFns.formatDistanceToNow(new Date(timeStampArg));
|
||||||
|
}
|
||||||
|
|||||||
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
17
tslint.json
17
tslint.json
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user