fix(core): update

This commit is contained in:
Philipp Kunz 2021-01-02 19:30:15 +00:00
parent 2b21ee9a24
commit 5a9584917c
3 changed files with 14 additions and 27 deletions

View File

@ -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();

View File

@ -1,4 +1,5 @@
import * as plugins from './smarttime.plugins';
import * as units from './smarttime.units';
export type TAvailableZone = 'Europe/Berlin';
@ -126,7 +127,20 @@ export class ExtendedDate extends Date {
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);
}
}