import cronParser from "cron-parser";
export function isValidTimezone(tz) {
    try {
        const expr = cronParser.parseExpression("* * * * *", {
            tz,
        });
        expr.next();
        return true;
    }
    catch (error) {
        return false;
    }
}
export function embedTimezone(cronExpression, tz) {
    if (!isValidTimezone(tz)) {
        throw new Error("Invalid timezone " + tz);
    }
    return cronExpression + ";" + tz;
}
export function parseTimezonedCron(cronExpression) {
    const [cron, tz = "Etc/UTC"] = cronExpression.split(";");
    return [cron, tz];
}
export function cron(lastDate, cronExpression) {
    const [cron, tz] = parseTimezonedCron(cronExpression);
    const expr = cronParser.parseExpression(cron, {
        currentDate: lastDate,
        tz,
    });
    const nextExecution = expr.next().toDate();
    return nextExecution;
}
export function every(lastDate, scheduleMeta) {
    return new Date(+lastDate + +scheduleMeta);
}
//# sourceMappingURL=repeat.js.map