Categories: CSSScriptWeb Design

Translate Cron Expressions Into Human-readable Strings – cRonstrue

A Cron expression is a text format specifying the schedule for automated jobs. It uses numbers and special characters to define the schedule, which can be difficult for non-technical users to understand.

The cRonstrue.js JavaScript library provides a simple way to parse Cron expressions and generate human-readable strings of Cron job schedules. It recognizes all special characters used in Cron expressions, including * / , – ? L W, #, supports 5, 6 (with seconds or year), or 7 (with seconds and year) part cron expressions, and is compatible with Quartz Job Scheduler cron expressions.

It also supports internationalization with over 30 human languages, allowing you to output the Cron expression description in the user’s preferred language.

Table of Contents

Toggle

How to use it:

1. Install and import the cRonstrue.

# NPM
$ npm i cronstrue
// node.js
const cronstrue = require('cronstrue');

// ES module
import cronstrue from 'cronstrue';

// Browser
<script src="/dist/cronstrue.min.js"></script>
<script>
var cronstrue = window.cronstrue;
</script>

2. To translate a Cron expression, just call the toString() function, passing in your expression as an argument:

cronstrue.toString("1 2 3 4 5")
// => At 02:01 AM, on day 3 of the month, and on Friday, only in April
// CLI usage
$ cronstrue 1 2 3 4 5

3. Localize the human-readable descriptions:

  • en
  • af
  • ar
  • be
  • bg
  • ca
  • cs
  • es
  • da
  • de
  • fi
  • fr
  • fa
  • he
  • hu
  • it
  • id
  • ja
  • ko
  • my
  • nb
  • nl
  • pl
  • pt_BR
  • pt_PT
  • ro
  • ru
  • sk
  • sl
  • sw
  • sv
  • th
  • tr
  • uk
  • zh_CN
  • zh_TW
  • vi
// node.js
const cronstrue = require('cronstrue');
require('cronstrue/locales/es');

// ES module
import cronstrue from 'cronstrue';
import 'cronstrue/locales/es';

// Browser
<script src="/dist/cronstrue.min.js"></script>
<script src="/locales/es.min.js"></script>
cronstrue.toString("1 2 3 4 5", { 
  locale: "es" 
});

4. More configuration options.

cronstrue.toString("1 2 3 4 5", { 
  throwExceptionOnParseError: false,
  verbose: false,
  dayOfWeekStartIndexZero: true,
  monthStartIndexZero: false,
  use24HourTimeFormat: true,
});

Changelog:

v2.61.0 (05/08/2025)

  • feat: add support for @ syntax expressions
  • Add support for @reboot special syntax

v2.60.0 (05/02/2025)

  • Remove support for tzOffset option

v2.59.0 (04/08/2025)

  • Fix: Incorrect Multiple Range Hour Interpretation

v2.58.0 (04/06/2025)

  • Avoid pluralized weekdays on danish translation

v2.57.0 (03/26/2025)

  • fix(playground): prevent page refresh on submit
  • Add workaround for french periods & fix side effect with previous change

v2.56.0 (03/03/2025)

  • Bugfixes

v2.55.0 (02/22/2025)

  • Deprecate tzOffset option

v2.54.0 (01/31/2025)

  • fix: correct norwegian translation of second

v2.53.0 (01/15/2025)

  • Optimize Chinese translation about PastTheMinute and PastTheHour
  • More validation to ensure expression does not contain any unexpected characters

v2.52.0 (11/21/2024)

  • Fix danish locale to not use definite singular expression for weekdays

v2.51.0 (10/28/2024)

  • [i18n] fix masculine and feminine forms of the weekdays in PT

v2.50.0 (05/06/2024)

  • Support for ‘@’ expression

v2.49.0 (04/02/2024)

  • fix local

v2.48.0 (02/05/2024)

  • fix: wrong word when DOM and DOW both present

v2.47.0 (12/02/2023)

  • Bugfixes

v2.44.0 (11/16/2023)

  • Add arabic option
  • Specify “cron” in error message

v2.43.0 (11/13/2023)

  • Fixed time formats for various locales

v2.42.0 (11/13/2023)

  • Ordering days on parse()

v2.41.0 (10/24/2023)

  • Add more debugging

v2.33.0 (10/23/2023)

  • feat: Added support for floating point tzOffset
  • Adjust day descriptor if time zone offset makes the day change
  • Script cleanup

v2.32.0 (09/07/2023)

  • feat: Add Bulgarian Locale

v2.31.0 (08/15/2023)

  • If string has a range in first interval don’t render “de”

v2.30.0 (08/14/2023)

  • Feature/tz
  • feat: Add Malay (Malaysia) Locale

v2.29.0 (08/09/2023)

  • add tzOffset

The post Translate Cron Expressions Into Human-readable Strings – cRonstrue appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

People Are Betting Thousands of Dollars on Who Will Die at the End of The Boys Season 5

People are betting thousands of dollars on who will die at the end of the…

17 minutes ago

Batman Games Begin: The Origins of the Dark Knight in Video Games

Batman was created more than 80 years ago and has starred in video games for…

17 minutes ago

Spider-Noir Star Nicolas Cage Hopes the Show Will Inspire Teens to Seek Out the Great Black and White Films of American Cinema

Spider-Noir star Nicolas Cage has said he pushed for the Prime Video superhero series to…

17 minutes ago

Warhammer 40,000 Confirms Ready-Painted Terrain for 11th Edition, but Games Workshop Rules Out Ready-Painted Miniatures

Games Workshop has shocked Warhammer 40,000 fans by confirming a leak of plans to sell…

1 hour ago

Witnesses report racing before fatal crash at McKinney and Lafayette

FORT WAYNE IND. (WOWO) One man is dead following a fiery early-morning crash at Lafayette…

2 hours ago

The Hunt for Ben Solo Fan Campaign Takes the Fight to The Mandalorian and Grogu Premiere in Hollywood

The Hunt For Ben Solo fan campaign is still going, and its latest stunt saw…

2 hours ago

This website uses cookies.