Compare commits

..

24 Commits

Author SHA1 Message Date
1e5fd80a69 4.0.4 2023-07-21 03:39:59 +02:00
1de9412a31 fix(core): update 2023-07-21 03:39:59 +02:00
fa3ac0ff77 4.0.3 2023-07-21 03:39:33 +02:00
25eee6cf73 fix(core): update 2023-07-21 03:39:32 +02:00
c290a75f01 4.0.2 2023-07-12 11:28:52 +02:00
9a20f8f6a1 fix(core): update 2023-07-12 11:28:52 +02:00
f91fa33568 4.0.1 2023-01-06 20:05:03 +01:00
c234cb4caa fix(core): update 2023-01-06 20:05:02 +01:00
5f5957b0c0 4.0.0 2022-11-21 12:33:26 +01:00
31275536ec BREAKING CHANGE(core): switch to esm 2022-11-21 12:33:25 +01:00
c759d436dd 3.0.48 2022-11-21 11:31:30 +01:00
010c9e7bed fix(core): update 2022-11-21 11:31:29 +01:00
264c08d848 3.0.47 2022-11-21 09:14:32 +01:00
b2a5cda468 fix(core): update 2022-11-21 09:14:32 +01:00
d3dd03534a 3.0.46 2022-11-21 01:19:39 +01:00
9b96779d19 fix(core): update 2022-11-21 01:19:38 +01:00
20b181b2f3 3.0.45 2022-02-02 17:03:59 +01:00
d278722da2 fix(core): update 2022-02-02 17:03:58 +01:00
e3daf08d67 3.0.44 2022-02-02 16:55:13 +01:00
0483b55a9e fix(core): update 2022-02-02 16:55:12 +01:00
c3a772c155 3.0.43 2021-11-08 16:56:11 +01:00
a2ffdd436f fix(timestamp): add missing .isOlderThanOtherTimeStamp() to TimeStamp class 2021-11-08 16:56:11 +01:00
da9c71eedb 3.0.42 2021-11-08 16:52:14 +01:00
63405fc577 fix(readme): fix readme 2021-11-08 16:52:13 +01:00
26 changed files with 5243 additions and 26798 deletions

View 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

View 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 @gitzone/tsdoc
npmci command tsdoc
continue-on-error: true

View File

@ -12,40 +12,36 @@ stages:
- release - release
- metadata - metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci 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 --production --ignore-scripts - npmci command pnpm audit --audit-level=high --prod
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- lossless
- docker - docker
allow_failure: true
auditDevDependencies: auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev - npmci command pnpm audit --audit-level=high --dev
tags: tags:
- lossless
- docker - docker
allow_failure: true allow_failure: true
@ -56,7 +52,6 @@ auditDevDependencies:
testStable: 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 npm test - npmci npm test
@ -67,7 +62,6 @@ testStable:
testBuild: testBuild:
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 command npm run build
@ -96,10 +90,9 @@ codequality:
only: only:
- tags - tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@ -119,11 +112,9 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
} }
] ]
} }

View File

@ -7,10 +7,10 @@
"projectType": "npm", "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"
} }
} }

26639
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/smarttime", "name": "@push.rocks/smarttime",
"private": false, "private": false,
"version": "3.0.41", "version": "4.0.4",
"description": "handle time in smart ways", "description": "handle time in smart ways",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
@ -9,26 +9,25 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest ./test)", "test": "(tstest ./test)",
"build": "(tsbuild --web && tsbundle npm)" "build": "(tsbuild --web && tsbundle npm)",
"buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.28", "@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsbundle": "^1.0.88", "@gitzone/tsbundle": "^2.0.8",
"@gitzone/tsrun": "^1.2.18", "@gitzone/tsrun": "^1.2.44",
"@gitzone/tstest": "^1.0.60", "@gitzone/tstest": "^1.0.77",
"@pushrocks/tapbundle": "^3.2.14", "@push.rocks/tapbundle": "^5.0.12",
"@types/node": "^16.11.6", "@types/node": "^20.4.2"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^5.0.0", "@push.rocks/lik": "^6.0.3",
"@pushrocks/smartdelay": "^2.0.13", "@push.rocks/smartdelay": "^3.0.5",
"@pushrocks/smartpromise": "^3.1.6", "@push.rocks/smartpromise": "^4.0.3",
"croner": "^4.0.69", "croner": "^5.3.4",
"dayjs": "^1.10.7", "dayjs": "^1.11.9",
"is-nan": "^1.3.2", "is-nan": "^1.3.2",
"pretty-ms": "^7.0.1" "pretty-ms": "^8.0.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@ -44,5 +43,6 @@
], ],
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
] ],
"type": "module"
} }

4901
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +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
Status Category | Status Badge Status Category | Status Badge
-- | -- -- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smarttime/badges/master/pipeline.svg)](https://lossless.cloud) GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smarttime/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smarttime/badges/master/coverage.svg)](https://lossless.cloud) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smarttime/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smarttime)](https://lossless.cloud) npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smarttime)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smarttime)](https://lossless.cloud) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smarttime)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smarttime)](https://lossless.cloud) PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smarttime)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smarttime)](https://lossless.cloud) PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smarttime)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smarttime)](https://lossless.cloud) BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smarttime)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
@ -36,7 +35,7 @@ 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();
@ -57,7 +56,6 @@ We are always happy for code contributions. If you are not the code contributing
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
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,6 +1,6 @@
// 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;
@ -9,15 +9,15 @@ 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;
@ -28,8 +28,8 @@ tap.test('should create valid HrtMeasurements', async (tools) => {
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

View File

@ -1,12 +1,12 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@push.rocks/tapbundle';
import * as smarttime from '../ts/index'; import * as smarttime from '../ts/index.js';
let testCronManager: smarttime.CronManager; let testCronManager: smarttime.CronManager;
tap.test('should create a valid instance of cronmanager', async () => { tap.test('should create a valid instance of cronmanager', async () => {
testCronManager = new smarttime.CronManager(); testCronManager = new smarttime.CronManager();
expect(testCronManager).to.be.instanceOf(smarttime.CronManager); expect(testCronManager).toBeInstanceOf(smarttime.CronManager);
}); });
tap.test('should create a valid cronJon', async (tools) => { tap.test('should create a valid cronJon', async (tools) => {

View File

@ -1,6 +1,6 @@
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 () => { tap.test('should create a valid JavaScript Date', async () => {
const extendedDate = new smarttime.ExtendedDate(Date.now()); const extendedDate = new smarttime.ExtendedDate(Date.now());
@ -23,12 +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.test('should format a date', async () => { tap.test('should format a date', async () => {
const extendedDate = new smarttime.ExtendedDate(Date.now()); const extendedDate = new smarttime.ExtendedDate(Date.now());
console.log(extendedDate.format('YYYY-MM-DD - hh:mm')); console.log(extendedDate.format('YYYY-MM-DD - hh:mm'));
}) });
tap.start(); tap.start();

View File

@ -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
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smarttime',
version: '4.0.4',
description: 'handle time in smart ways'
}

View File

@ -1,8 +1,8 @@
export * from './smarttime.classes.cronmanager'; export * from './smarttime.classes.cronmanager.js';
export * from './smarttime.classes.cronjob'; export * from './smarttime.classes.cronjob.js';
export * from './smarttime.classes.extendeddate'; export * from './smarttime.classes.extendeddate.js';
export * from './smarttime.classes.hrtmeasurement'; export * from './smarttime.classes.hrtmeasurement.js';
export * from './smarttime.classes.interval'; 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';

View File

@ -1,12 +1,14 @@
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';
import { CronParser } from './smarttime.classes.cronparser'; import { CronParser } from './smarttime.classes.cronparser.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: CronParser | typeof plugins.croner; public cronParser: plugins.croner;
public status: 'started' | 'stopped' | 'initial' = 'initial'; public status: 'started' | 'stopped' | 'initial' = 'initial';
public cronExpression: string; public cronExpression: string;
public jobFunction: TJobFunction; public jobFunction: TJobFunction;
@ -26,9 +28,9 @@ export class CronJob {
this.getNextExecutionTime(); this.getNextExecutionTime();
} }
if (Date.now() > this.nextExecutionUnix) { if (Date.now() > this.nextExecutionUnix) {
const maybePromise = this.jobFunction(); const maybePromise = this.jobFunction(this.nextExecutionUnix);
if (maybePromise instanceof Promise) { if (maybePromise instanceof Promise) {
maybePromise.catch(e => console.log(e)); maybePromise.catch((e) => console.log(e));
} }
this.nextExecutionUnix = this.getNextExecutionTime(); this.nextExecutionUnix = this.getNextExecutionTime();
} }
@ -36,7 +38,7 @@ export class CronJob {
} }
public getNextExecutionTime() { public getNextExecutionTime() {
return this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution(); return (this.nextExecutionUnix = Date.now() + this.getTimeToNextExecution());
} }
/** /**

View File

@ -1,6 +1,6 @@
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 { getMilliSecondsAsHumanReadableString } from './smarttime.units'; import { getMilliSecondsAsHumanReadableString } from './smarttime.units.js';
export class CronManager { export class CronManager {
public executionTimeout: plugins.smartdelay.Timeout<void>; public executionTimeout: plugins.smartdelay.Timeout<void>;
@ -10,7 +10,7 @@ export class CronManager {
constructor() {} constructor() {}
public addCronjob(cronIdentifierArg: string, cronFunctionArg: () => Promise<void>) { public addCronjob(cronIdentifierArg: string, cronFunctionArg: TJobFunction) {
const newCronJob = new CronJob(this, cronIdentifierArg, cronFunctionArg); const newCronJob = new CronJob(this, cronIdentifierArg, cronFunctionArg);
this.cronjobs.add(newCronJob); this.cronjobs.add(newCronJob);
if (this.status === 'started') { if (this.status === 'started') {

View File

@ -1,4 +1,4 @@
import * as plugins from './smarttime.plugins'; import * as plugins from './smarttime.plugins.js';
export class CronParser { export class CronParser {
public cronExpression: string; public cronExpression: string;
@ -62,7 +62,7 @@ export class CronParser {
if (targetHour < currentHour) { if (targetHour < currentHour) {
currentDay = (currentDay + 1) % 30; currentDay = (currentDay + 1) % 30;
} }
const targetDay = currentDay; const targetDay = currentDay;
if (targetDay < currentDay) { if (targetDay < currentDay) {
currentMonth = (currentMonth + 1) % 11; currentMonth = (currentMonth + 1) % 11;
@ -70,7 +70,7 @@ export class CronParser {
const targetMonth = currentMonth; const targetMonth = currentMonth;
if (targetMonth < currentMonth) { if (targetMonth < currentMonth) {
currentYear = (currentYear + 1); currentYear = currentYear + 1;
} }
const targetYear = currentYear; const targetYear = currentYear;

View File

@ -1,5 +1,5 @@
import * as plugins from './smarttime.plugins'; import * as plugins from './smarttime.plugins.js';
import * as units from './smarttime.units'; import * as units from './smarttime.units.js';
export type TAvailableZone = 'Europe/Berlin'; export type TAvailableZone = 'Europe/Berlin';
@ -83,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
*/ */
@ -123,14 +128,14 @@ export class ExtendedDate extends Date {
}; };
} }
public format (formatArg: string) { public format(formatArg: string) {
return plugins.dayjs(this.getTime()).format(formatArg); return plugins.dayjs(this.getTime()).format(formatArg);
} }
/** /**
* boolean checks * boolean checks
*/ */
public isToday () { public isToday() {
return plugins.dayjs(this.getTime()).isToday(); return plugins.dayjs(this.getTime()).isToday();
} }

View File

@ -1,4 +1,4 @@
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';

View File

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

View File

@ -1,4 +1,4 @@
import * as plugins from './smarttime.plugins'; import * as plugins from './smarttime.plugins.js';
/** /**
* TimeStamp * TimeStamp
@ -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
*/ */

View File

@ -1,14 +1,14 @@
// @pushrocks scope // @pushrocks scope
import * as lik from '@pushrocks/lik'; import * as lik from '@push.rocks/lik';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@push.rocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@push.rocks/smartpromise';
export { lik, smartdelay, smartpromise }; export { lik, smartdelay, smartpromise };
// third parties; // third parties;
const croner: any = require('croner'); import croner from 'croner';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import isToday from 'dayjs/plugin/isToday'; import isToday from 'dayjs/plugin/isToday.js';
import prettyMs from 'pretty-ms'; import prettyMs from 'pretty-ms';
dayjs.extend(isToday); dayjs.extend(isToday);

View File

@ -1,4 +1,4 @@
import * as plugins from './smarttime.plugins'; import * as plugins from './smarttime.plugins.js';
export let units = { export let units = {
years: (timesArg = 1): number => { years: (timesArg = 1): number => {
@ -59,4 +59,4 @@ export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
export const getMilliSecondsAsHumanReadableString = (milliSecondsArg: number): string => { export const getMilliSecondsAsHumanReadableString = (milliSecondsArg: number): string => {
return plugins.prettyMs(milliSecondsArg); return plugins.prettyMs(milliSecondsArg);
} };

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
}
}

View File

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