Skip to content

Instantly share code, notes, and snippets.

View emanuelet's full-sized avatar

Emanuele Tonello emanuelet

View GitHub Profile
@emanuelet
emanuelet / rtoc.js
Last active September 29, 2023 22:22
Convert RRULE string to Cron expression (with output for Bull Repeated jobs)
const moment = require('moment-timezone')
const logger = require('tracer').colorConsole()
const { RRule, RRuleSet, rrulestr } = require('rrule')
function untilStringToDate(until) {
const re = /^(\d{4})(\d{2})(\d{2})(T(\d{2})(\d{2})(\d{2})Z?)?$/
const bits = re.exec(until)
if (!bits) throw new Error(`Invalid UNTIL value: ${until}`)