Compare commits
94 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
0c0b08e2be | |||
dd722146f4 | |||
c968e156ae | |||
b5509711e7 | |||
f8540b8076 | |||
30d18db4af | |||
388649659c | |||
e8ff289a9a | |||
a5deb25bfb | |||
ce2d1b278b |
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
|
113
.gitlab-ci.yml
113
.gitlab-ci.yml
@ -1,77 +1,85 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- pnpm install -g pnpm
|
||||||
|
- pnpm install -g @shipzone/npmci
|
||||||
|
- npmci npm prepare
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command pnpm audit --audit-level=high --prod
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
snyk:
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm install -g snyk
|
- npmci command pnpm audit --audit-level=high --dev
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci node install stable
|
||||||
- npmci node install lts
|
- npmci npm install
|
||||||
- npmci npm install
|
- npmci npm test
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci node install stable
|
||||||
- npmci node install stable
|
- npmci npm install
|
||||||
- npmci npm install
|
- npmci command npm run build
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -79,33 +87,36 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci node install stable
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -113,5 +124,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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.
|
@ -4,12 +4,13 @@
|
|||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smarttime",
|
"gitrepo": "smarttime",
|
||||||
"shortDescription": "handle time in smart ways",
|
"description": "handle time in smart ways",
|
||||||
"npmPackagename": "@pushrocks/smarttime",
|
"npmPackagename": "@push.rocks/smarttime",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1775
package-lock.json
generated
1775
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@ -1,40 +1,48 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@push.rocks/smarttime",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.8",
|
"version": "4.0.6",
|
||||||
"description": "handle time in smart ways",
|
"description": "handle time in smart ways",
|
||||||
"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)"
|
"build": "(tsbuild --web && tsbundle npm)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@git.zone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsrun": "^1.2.6",
|
"@git.zone/tsbundle": "^2.0.8",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@git.zone/tstest": "^1.0.77",
|
||||||
"@types/node": "^12.0.8",
|
"@push.rocks/tapbundle": "^5.0.15",
|
||||||
"tslint": "^5.17.0",
|
"@types/node": "^20.8.7"
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@push.rocks/lik": "^6.0.5",
|
||||||
"@types/cron": "^1.7.1",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@types/luxon": "^1.15.1",
|
"@push.rocks/smartpromise": "^4.0.3",
|
||||||
"cron": "^1.7.1",
|
"croner": "^7.0.3",
|
||||||
"luxon": "^1.16.0"
|
"dayjs": "^1.11.10",
|
||||||
|
"is-nan": "^1.3.2",
|
||||||
|
"pretty-ms": "^8.0.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"
|
||||||
}
|
}
|
||||||
|
5846
pnpm-lock.yaml
generated
Normal file
5846
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
readme.md
47
readme.md
@ -1,20 +1,26 @@
|
|||||||
# @pushrocks/smarttime
|
# @push.rocks/smarttime
|
||||||
handle time in smart ways
|
handle time in smart ways
|
||||||
|
|
||||||
## Availabililty and Links
|
## Availabililty and Links
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smarttime)
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smarttime)
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smarttime)
|
* [gitlab.com (source)](https://gitlab.com/push.rocks/smarttime)
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smarttime)
|
* [github.com (source mirror)](https://github.com/push.rocks/smarttime)
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smarttime/)
|
* [docs (typedoc)](https://push.rocks.gitlab.io/smarttime/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smarttime/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smarttime/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smarttime)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smarttime)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -23,18 +29,20 @@ Use TypeScript for best in class instellisense.
|
|||||||
Smarttime offers smart ways to deal with time.
|
Smarttime offers smart ways to deal with time.
|
||||||
|
|
||||||
### class CronManager
|
### class CronManager
|
||||||
|
|
||||||
This class provides scheduling of functions with a cron syntax
|
This class provides scheduling of functions with a cron syntax
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { CronManager } from '@pushrocks/smarrtime';
|
import { CronManager } from '@pushrocks/smarrtime';
|
||||||
const cronManagerInstance = new CronManager();
|
const cronManagerInstance = new CronManager();
|
||||||
cronManagerInstance.addConrjob('* * * * * *', async () => {
|
cronManagerInstance.addCronjob('* * * * * *', async () => {
|
||||||
console.log('hello'); // will log 'hello' to console once every second;
|
console.log('hello'); // will log 'hello' to console once every second;
|
||||||
})
|
});
|
||||||
cronManagerInstance.start();
|
cronManagerInstance.start();
|
||||||
```
|
```
|
||||||
|
|
||||||
### class ExtendedDate
|
### class ExtendedDate
|
||||||
|
|
||||||
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
|
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
|
||||||
|
|
||||||
```TypeScript
|
```TypeScript
|
||||||
@ -42,9 +50,12 @@ import { ExtendedDate } from '@pushrocks/smarttime'
|
|||||||
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
## Legal
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
[](https://maintainedby.lossless.com)
|
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
// tslint:disable-next-line:no-implicit-dependencies
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index.js';
|
||||||
|
|
||||||
// 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,7 +41,7 @@ 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);
|
60
test/test.cronmanager.node.ts
Normal file
60
test/test.cronmanager.node.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { tap, expect } from '@push.rocks/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();
|
||||||
|
});
|
||||||
|
|
||||||
|
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 '@push.rocks/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');
|
||||||
@ -16,4 +21,14 @@ tap.test('should create a date and time with European Format', async () => {
|
|||||||
console.log(extendedDate);
|
console.log(extendedDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should create a European date string', async () => {
|
||||||
|
const extendedDate = smarttime.ExtendedDate.fromHyphedDate('2018-02-13');
|
||||||
|
expect(extendedDate.exportToEuropeanDate()).toEqual('13.02.2018');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should format a date', async () => {
|
||||||
|
const extendedDate = new smarttime.ExtendedDate(Date.now());
|
||||||
|
console.log(extendedDate.format('YYYY-MM-DD - hh:mm'));
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
// tslint:disable-next-line:no-implicit-dependencies
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/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 () => {
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smarttime',
|
||||||
|
version: '4.0.6',
|
||||||
|
description: 'handle time in smart ways'
|
||||||
|
}
|
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';
|
|
||||||
|
58
ts/smarttime.classes.cronjob.ts
Normal file
58
ts/smarttime.classes.cronjob.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
import { CronManager } from './smarttime.classes.cronmanager.js';
|
||||||
|
|
||||||
|
import { CronParser } from './smarttime.classes.cronparser.js';
|
||||||
|
|
||||||
|
export type TJobFunction =
|
||||||
|
| ((triggerTimeArg?: number) => void)
|
||||||
|
| ((triggerTimeArg?: number) => Promise<any>);
|
||||||
|
|
||||||
|
export class CronJob {
|
||||||
|
public cronParser: plugins.croner;
|
||||||
|
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||||
|
public cronExpression: string;
|
||||||
|
public jobFunction: TJobFunction;
|
||||||
|
private nextExecutionUnix: number = 0;
|
||||||
|
|
||||||
|
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
||||||
|
this.cronExpression = cronExpressionArg;
|
||||||
|
this.jobFunction = jobFunction;
|
||||||
|
this.cronParser = plugins.croner(cronExpressionArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks wether the cronjob needs to be executed
|
||||||
|
*/
|
||||||
|
public checkExecution(): number {
|
||||||
|
if (this.nextExecutionUnix === 0) {
|
||||||
|
this.getNextExecutionTime();
|
||||||
|
}
|
||||||
|
if (Date.now() > this.nextExecutionUnix) {
|
||||||
|
const maybePromise = this.jobFunction(this.nextExecutionUnix);
|
||||||
|
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() {
|
||||||
|
this.status = 'started';
|
||||||
|
}
|
||||||
|
|
||||||
|
public stop() {
|
||||||
|
this.status = 'stopped';
|
||||||
|
}
|
||||||
|
}
|
@ -1,34 +1,85 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
import { CronJob, type TJobFunction } from './smarttime.classes.cronjob.js';
|
||||||
|
import { getMilliSecondsAsHumanReadableString } from './smarttime.units.js';
|
||||||
|
|
||||||
export class CronManager {
|
export class CronManager {
|
||||||
|
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
||||||
|
|
||||||
public status: 'started' | 'stopped' = 'stopped';
|
public status: 'started' | 'stopped' = 'stopped';
|
||||||
|
public cronjobs = new plugins.lik.ObjectMap<CronJob>();
|
||||||
|
|
||||||
public cronjobs: plugins.cron.CronJob[] = [];
|
constructor() {}
|
||||||
|
|
||||||
public addCronjob(cronIdentifierArg: string, cronFunctionArg: plugins.cron.CronCommand) {
|
public addCronjob(cronIdentifierArg: string, cronFunctionArg: TJobFunction) {
|
||||||
const newCronJob = new plugins.cron.CronJob(cronIdentifierArg, cronFunctionArg);
|
const newCronJob = new CronJob(this, cronIdentifierArg, cronFunctionArg);
|
||||||
|
this.cronjobs.add(newCronJob);
|
||||||
if (this.status === 'started') {
|
if (this.status === 'started') {
|
||||||
newCronJob.start();
|
newCronJob.start();
|
||||||
}
|
}
|
||||||
this.cronjobs.push(newCronJob);
|
|
||||||
|
return newCronJob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public removeCronjob(cronjobArg: CronJob) {
|
||||||
|
cronjobArg.stop();
|
||||||
|
this.cronjobs.remove(cronjobArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async runCronCycle() {
|
||||||
|
this.executionTimeout = new plugins.smartdelay.Timeout(0);
|
||||||
|
do {
|
||||||
|
let nextRunningCronjob: CronJob;
|
||||||
|
for (const cronJob of this.cronjobs.getArray()) {
|
||||||
|
cronJob.checkExecution();
|
||||||
|
if (
|
||||||
|
!nextRunningCronjob ||
|
||||||
|
cronJob.getTimeToNextExecution() < nextRunningCronjob.getTimeToNextExecution()
|
||||||
|
) {
|
||||||
|
nextRunningCronjob = cronJob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nextRunningCronjob) {
|
||||||
|
this.executionTimeout = new plugins.smartdelay.Timeout(
|
||||||
|
nextRunningCronjob.getTimeToNextExecution()
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`Next CronJob scheduled in ${getMilliSecondsAsHumanReadableString(
|
||||||
|
this.executionTimeout.getTimeLeft()
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.executionTimeout = new plugins.smartdelay.Timeout(1000);
|
||||||
|
console.log('no cronjobs specified! Checking again in 1 second');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.executionTimeout.promise;
|
||||||
|
} while (this.status === 'started');
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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';
|
||||||
|
this.executionTimeout.cancel();
|
||||||
|
} else {
|
||||||
|
console.log(`You tried to stop a CronManager that was not actually started.`);
|
||||||
|
}
|
||||||
|
for (const cron of this.cronjobs.getArray()) {
|
||||||
cron.stop();
|
cron.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,25 +1,63 @@
|
|||||||
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';
|
||||||
|
|
||||||
|
export interface IDateUnits {
|
||||||
|
year: number;
|
||||||
|
yearString: string;
|
||||||
|
month: number;
|
||||||
|
monthString: string;
|
||||||
|
monthName: string;
|
||||||
|
day: number;
|
||||||
|
dayString: string;
|
||||||
|
dayOfTheWeek: number;
|
||||||
|
dayOfTheWeekName: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class ExtendedDate extends Date {
|
export class ExtendedDate extends Date {
|
||||||
|
// STATIC factories
|
||||||
|
public static fromMillis(milliSeconds: number) {
|
||||||
|
return new ExtendedDate(milliSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static fromDate(dateArg: Date) {
|
||||||
|
return new ExtendedDate(dateArg.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/**
|
||||||
|
* creates an Extended date from a hypedDate like "2018-03-28"
|
||||||
|
* @param dateString
|
||||||
|
*/
|
||||||
|
public static fromHyphedDate(dateString: string) {
|
||||||
|
// guards
|
||||||
|
// implementation
|
||||||
|
const dateMillis = new Date(dateString).getTime();
|
||||||
|
return new ExtendedDate(dateMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as .fromEuropeanDate(), but accepts additional timeArg and zoneArg
|
||||||
|
*/
|
||||||
public static fromEuropeanDateAndTime(
|
public static fromEuropeanDateAndTime(
|
||||||
europeanDateArg: string,
|
europeanDateArg: string,
|
||||||
timeArg: string,
|
timeArg: string = '12:00:00',
|
||||||
zoneArg: TAvailableZone
|
zoneArg: TAvailableZone = 'Europe/Berlin'
|
||||||
) {
|
) {
|
||||||
|
// guards
|
||||||
|
|
||||||
|
// implementation
|
||||||
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDateArg);
|
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDateArg);
|
||||||
const sliceDate = (dateString: string) => {
|
const sliceDate = (dateString: string) => {
|
||||||
return `0${dateString}`.slice(-2);
|
return `0${dateString}`.slice(-2);
|
||||||
@ -27,14 +65,87 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(unixMilli: number) {
|
// INSTANCE
|
||||||
|
public timezone: TAvailableZone;
|
||||||
|
|
||||||
|
constructor(unixMilli: number = Date.now()) {
|
||||||
super(unixMilli);
|
super(unixMilli);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
public exportToEuropeanDate() {
|
||||||
|
const units = this.exportToUnits();
|
||||||
|
return `${units.dayString}.${units.monthString}.${units.yearString}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
public exportToHyphedSortableDate() {
|
||||||
|
const units = this.exportToUnits();
|
||||||
|
return `${units.yearString}-${units.monthString}-${units.dayString}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* exports units
|
||||||
|
*/
|
||||||
|
public exportToUnits(): IDateUnits {
|
||||||
|
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()],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import * as process from 'process';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* easy high resolution time measurement
|
* easy high resolution time measurement
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,7 +13,7 @@ export class HrtMeasurement {
|
|||||||
*/
|
*/
|
||||||
public start() {
|
public start() {
|
||||||
this._started = true;
|
this._started = true;
|
||||||
this._hrTimeStart = process.hrtime();
|
this._milliStart = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
ts/smarttime.classes.interval.ts
Normal file
43
ts/smarttime.classes.interval.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import * as plugins from './smarttime.plugins.js';
|
||||||
|
|
||||||
|
export class Interval {
|
||||||
|
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||||
|
private statusAuthorization: any = null;
|
||||||
|
|
||||||
|
// timings
|
||||||
|
public intervalMilliseconds: number;
|
||||||
|
public nextIntervalMillisenconds: number;
|
||||||
|
|
||||||
|
public intervalJobs: Array<() => any> = [];
|
||||||
|
constructor(intervalMillisencondsArg: number) {
|
||||||
|
this.intervalMilliseconds = intervalMillisencondsArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public stop() {
|
||||||
|
this.status = 'stopped';
|
||||||
|
this.statusAuthorization = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addIntervalJob(funcArg: () => any) {
|
||||||
|
this.intervalJobs.push(funcArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private executeIntervalJobs() {
|
||||||
|
for (const funcArg of this.intervalJobs) {
|
||||||
|
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,10 +1,16 @@
|
|||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as lik from '@push.rocks/lik';
|
||||||
|
import * as smartdelay from '@push.rocks/smartdelay';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
|
||||||
export { smartpromise };
|
export { lik, smartdelay, smartpromise };
|
||||||
|
|
||||||
// third parties
|
// third parties;
|
||||||
import * as luxon from 'luxon';
|
import croner from 'croner';
|
||||||
import * as cron from 'cron';
|
import dayjs from 'dayjs';
|
||||||
|
import isToday from 'dayjs/plugin/isToday.js';
|
||||||
|
import prettyMs from 'pretty-ms';
|
||||||
|
|
||||||
export { luxon, cron };
|
dayjs.extend(isToday);
|
||||||
|
|
||||||
|
export { croner, 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,13 @@ 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);
|
||||||
|
};
|
||||||
|
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