Skip to content

Commit

Permalink
Fix Cronstrue import
Browse files Browse the repository at this point in the history
  • Loading branch information
marjan-georgiev committed Feb 9, 2024
1 parent 8b2b9ba commit 620b081
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"codemirror",
"lodash",
"cron-validate",
"cronstrue",
"cronstrue/i18n",
"moment-timezone",
"@swimlane/ngx-ui"
],
Expand Down
11 changes: 7 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@swimlane/ngx-ui": "^47.0.0-beta.2",
"codemirror": "^5.62.3",
"cron-validate": "^1.4.3",
"cronstrue": "^1.115.0",
"cronstrue": "^2.48.0",
"moment-timezone": "^0.5.33",
"ng-in-viewport": "^16.1.0",
"ng2-file-upload": "^5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions projects/swimlane/ngx-cron/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@swimlane/ngx-cron",
"version": "5.0.0",
"version": "5.0.1-beta.6",
"peerDependencies": {
"@angular/common": ">=10.0.0",
"@angular/core": ">=10.0.0",
"@swimlane/ngx-ui": ">[email protected]"
},
"dependencies": {
"cron-validate": "^1.4.0",
"cronstrue": "^1.103.0",
"cronstrue": "^2.48.0",
"tslib": "^2.0.0"
}
}
14 changes: 11 additions & 3 deletions projects/swimlane/ngx-cron/src/lib/ngx-cron.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import ExpressionDescriptor from 'cronstrue/i18n';
import cronstrue from 'cronstrue/i18n';
import CronValidate from 'cron-validate';
import moment from 'moment-timezone';

Expand Down Expand Up @@ -61,6 +61,14 @@ export interface ICronData {
const MAX_MINUTES = 59;
const MAX_DAYS_OF_MONTH = 31;

function createCronstrueObject(expression: string, options) {
if (cronstrue['default']) {
return new cronstrue['default'](expression, options);
} else {
return new cronstrue(expression, options);
}
}

// @dynamic
@Injectable()
export class NgxCronService {
Expand Down Expand Up @@ -132,7 +140,7 @@ export class NgxCronService {
}

toString(cron: string) {
const e: any = new ExpressionDescriptor(cron, this.expressionDescriptorOptions);
const e: any = createCronstrueObject(cron, this.expressionDescriptorOptions);

try {
return e.getFullDescription();
Expand All @@ -148,7 +156,7 @@ export class NgxCronService {
configOverrides: typeof NgxCronService.CRON_VALIDATE_CONFIG_OVERRIDES
): ICronData {
this.expressionDescriptorOptions.locale = lang || 'en';
const e: any = new ExpressionDescriptor(cron, this.expressionDescriptorOptions);
const e: any = createCronstrueObject(cron, this.expressionDescriptorOptions);

let data: ICronData;

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "es2020",
"module": "es2022",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "ES2022",
"lib": ["es2018", "dom"],
"lib": ["es2022", "dom"],
"paths": {
"@swimlane/ngx-cron": ["dist/swimlane/ngx-cron/swimlane-ngx-cron", "dist/swimlane/ngx-cron"]
},
Expand Down

0 comments on commit 620b081

Please sign in to comment.