Skip to content

Commit f02c748

Browse files
add cRonstrue, parses a cron expression and outputs a human readable description of the cron schedule
1 parent 4941a7e commit f02c748

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

crontab.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ exports.crontab_db_file = path.join(exports.db_folder, 'crontab.db');
1111

1212
var db = new Datastore({ filename: exports.crontab_db_file});
1313
var cronPath = "/tmp";
14-
1514
if(process.env.CRON_PATH !== undefined) {
1615
console.log(`Path to crond files set using env variables ${process.env.CRON_PATH}`);
1716
cronPath = process.env.CRON_PATH;
@@ -24,6 +23,8 @@ db.loadDatabase(function (err) {
2423
var exec = require('child_process').exec;
2524
var fs = require('fs');
2625
var cron_parser = require("cron-parser");
26+
var cronstrue = require('cronstrue/i18n');
27+
var humanCronLocate = process.env.HUMANCRON ?? "en"
2728

2829

2930
crontab = function(name, command, schedule, stopped, logging, mailing){
@@ -71,6 +72,7 @@ exports.crontabs = function(callback){
7172
docs[i].next = "Next Reboot";
7273
else
7374
try {
75+
docs[i].human = cronstrue.toString(docs[i].schedule, { locale: humanCronLocate });
7476
docs[i].next = cron_parser.parseExpression(docs[i].schedule).next().toString();
7577
} catch(err) {
7678
console.error(err);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"body-parser": "latest",
1212
"connect-busboy": "latest",
1313
"cron-parser": "latest",
14+
"cronstrue": "^1.115.0",
1415
"ejs": "latest",
1516
"express": "latest",
1617
"express-basic-auth": "^1.2.0",

views/index.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
<% } %>
8383
</td>
8484
<td><%= crontab.command %></td>
85-
<td><span style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" title="<%= crontab.next %>"><%= crontab.schedule %></span></td>
85+
<td><span style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" title="<%= crontab
86+
.next %>"><%= crontab.schedule %><br><%= crontab.human %></span></td>
8687
<td style="width:20%" title="<%= crontab.timestamp %>"><%= moment(new Date(crontab.timestamp)).fromNow() %></td>
8788
<td>
8889

0 commit comments

Comments
 (0)