Package to Translate a Cron to a "Simpler" Human Readable Format?

I've been looking all over the internet for an NPM package that could achieve this, but I haven't been able to find one.

What I'm looking for is quite simple on the surface. A cron library that can translate a monthly cron job to human-readable text, while keeping it simple. So for example: if I put in 0 0 14 * *, I want it to translate to "Monthly". Instead, this translates to "At 00:00 on day-of-month 14." which is an awkward string to display to users.

More examples would be:

  • 0 8 * * * should translate to "Daily"
  • 0 0 10 * * should also translate to "Monthly"

I want to stay away from making my own proprietary library if possible. Does anyone know if there is any JS package out there that meets my requirements?

2

1 Answer

You can use

cRonstrue is a JavaScript library that parses a cron expression and outputs a human readable description of the cron schedule.

cronstrue.toString("* * * * *");
> "Every minute"

cronstrue.toString("0 23 ? * MON-FRI");
> "At 11:00 PM, Monday through Friday"

cronstrue.toString("0 23 * * *", { verbose: true });
> "At 11:00 PM, every day"

cronstrue.toString("23 12 * * SUN#2");
> "At 12:23 PM, on the second Sunday of the month"

cronstrue.toString("23 14 * * SUN#2", { use24HourTimeFormat: true });
> "At 14:23, on the second Sunday of the month"

cronstrue.toString("* * * ? * 2-6/2", { dayOfWeekStartIndexZero: false });
> "Every second, every 2 days of the week, Monday through Friday"

cronstrue.toString("* * * 6-8 *", { monthStartIndexZero: true });
> "Every minute, July through September"
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest