node-cron
node-cron copied to clipboard
How to create schedule from seconds?
I want to create a function such that given an integer, I get a cron job to run every time the UNIX timestamp is divisible by that integer. This is what I have so far:
function secToCron(sec) {
if (sec <= 60) {
return "*/" + sec + " * * * * *";
} else if (sec <= 3600) {
return "* */" + sec / 60 + "* * * *";
} else if (sec <= 86400) {
return "* * */" + sec / 3600 + "* * *";
}
}
However, the issue here is that if sec = 100, it will give me a decimal in the string. Also this doesn't work for anything beyond 1 day because there is a variable number of days in a month. How can I solve this?
Thanks