CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-cronstrue

tessl install tessl/npm-cronstrue@3.2.0

Convert cron expressions into human readable descriptions

Agent Success

Agent success rate when using this tile

100%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.12x

Baseline

Agent success rate without this tile

89%

task.mdevals/scenario-5/

Cron Schedule Validator with Extended Format Support

Overview

Build a schedule validation and description tool that works with extended cron expressions including both seconds and year fields. The tool should help users understand when their scheduled tasks will run by converting technical cron syntax into human-readable descriptions.

Requirements

Create a module that:

  1. Validates extended cron expressions: Accept 7-part cron expressions that include both seconds (first field) and year (last field) and validate their format.

  2. Generates human-readable descriptions: Convert valid 7-part cron expressions into clear, human-readable descriptions that explain when the scheduled task will execute.

  3. Provides detailed output: For each cron expression, return an object containing:

    • valid: boolean indicating if the expression is valid
    • description: human-readable description (if valid)
    • error: error message (if invalid)
  4. Handles multiple expressions: Process an array of cron expressions and return results for each.

Implementation Details

Your solution should:

  • Accept 7-part cron expressions in the format: second minute hour day-of-month month day-of-week year
  • Handle various cron special characters (*, -, /, ,)
  • Support year ranges and specific years
  • Return clear, understandable descriptions
  • Handle invalid expressions gracefully without crashing

Example Usage

const validator = require('./cron-validator');

const expressions = [
  '0 30 14 * * * 2025',
  '*/10 * * * * * 2024-2026',
  '0 0 0 1 1 * 2025',
  '30 15 10 * * MON 2025-2030'
];

const results = validator.validateCronExpressions(expressions);
console.log(results);

Test Cases

Test Case 1: Year-Specific Expression @test

File: cron-validator.test.js

const validator = require('./cron-validator');

test('validates and describes cron with specific year', () => {
  const results = validator.validateCronExpressions(['0 30 14 * * * 2025']);
  expect(results[0].valid).toBe(true);
  expect(results[0].description).toBeDefined();
  expect(results[0].description.toLowerCase()).toContain('2025');
});

Test Case 2: Year Range Expression @test

File: cron-validator.test.js

const validator = require('./cron-validator');

test('validates and describes cron with year range', () => {
  const results = validator.validateCronExpressions(['*/10 * * * * * 2024-2026']);
  expect(results[0].valid).toBe(true);
  expect(results[0].description).toBeDefined();
  expect(results[0].description.toLowerCase()).toContain('2024');
  expect(results[0].description.toLowerCase()).toContain('2026');
});

Test Case 3: Multiple Expressions @test

File: cron-validator.test.js

const validator = require('./cron-validator');

test('processes multiple cron expressions', () => {
  const expressions = [
    '0 0 0 1 1 * 2025',
    '30 15 10 * * MON 2025-2030'
  ];
  const results = validator.validateCronExpressions(expressions);
  expect(results).toHaveLength(2);
  expect(results[0].valid).toBe(true);
  expect(results[1].valid).toBe(true);
  expect(results[0].description).toBeDefined();
  expect(results[1].description).toBeDefined();
});

Dependencies { .dependencies }

cronstrue { .dependency }

Provides cron expression parsing and human-readable description generation.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/cronstrue@3.2.x
tile.json