Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
419fe80bde | |||
5a9584917c | |||
2b21ee9a24 | |||
3a110c9fd9 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"version": "3.0.36",
|
"version": "3.0.38",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.36",
|
"version": "3.0.38",
|
||||||
"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",
|
||||||
|
@ -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('*/2 * * * * *', async () => {
|
|
||||||
if (counter === 10) {
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
console.log(`hey ${counter}`);
|
|
||||||
});
|
|
||||||
testCronManager.start();
|
|
||||||
await done.promise;
|
|
||||||
testCronManager.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins';
|
||||||
|
import * as units from './smarttime.units';
|
||||||
|
|
||||||
export type TAvailableZone = 'Europe/Berlin';
|
export type TAvailableZone = 'Europe/Berlin';
|
||||||
|
|
||||||
@ -125,4 +126,21 @@ 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
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,8 @@ export { lik, smartdelay, smartpromise };
|
|||||||
// third parties
|
// third parties
|
||||||
import croner from 'croner';
|
import croner from 'croner';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import isToday from 'dayjs/plugin/isToday';
|
||||||
|
|
||||||
|
dayjs.extend(isToday);
|
||||||
|
|
||||||
export { croner, dayjs };
|
export { croner, dayjs };
|
||||||
|
Reference in New Issue
Block a user