npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

qz-cron

v0.0.1-alpha

Published

Pure JavaScript Quartz cron expression validator and scheduler utility

Readme

Quartz Cron Utility

A pure JavaScript utility for validating and calculating execution times of Quartz cron expressions.

Features

1. Expression Validation

  • Real-time validation of Quartz cron expressions
  • Detailed error messages
  • Full support for Quartz cron syntax
  • No external dependencies

2. Execution Time Calculation

  • Calculate the next N execution times
  • Support custom start time and timezone (default: Asia/Shanghai)
  • Show relative time (e.g., "in 3 days", "in 2 hours")
  • Show the next 5 execution times by default

Installation

npm install qz-cron

Usage

Import Functions

// ES6 import
import {
  validateQuartzExpression,
  getNextExecutionTimes,
  getNextExecutionTime,
  getRelativeTime
} from 'qz-cron';

// CommonJS import
const {
  validateQuartzExpression,
  getNextExecutionTimes
} = require('qz-cron');

Expression Validation

// Validate an expression
const result = validateQuartzExpression('0 0 12 * * ?');
console.log(result.isValid); // true
console.log(result.error); // undefined

// Validate an invalid expression
const invalidResult = validateQuartzExpression('0 0 12 * *');
console.log(invalidResult.isValid); // false
console.log(invalidResult.error); // "Expression must have 6-7 fields, got 5"

Execution Time Calculation (with Timezone)

// Get the next 5 execution times, default timezone is Asia/Shanghai
const times = getNextExecutionTimes('0 0 12 * * ?', 5);
console.log(times[0].formatted); // 2024-05-20 12:00:00

// Get the next 3 execution times in New York timezone
const timesNY = getNextExecutionTimes('0 0 12 * * ?', 3, new Date(), 'America/New_York');
console.log(timesNY[0].formatted); // 2024-05-20 12:00:00 (New York time)

// Get the next execution time in UTC
const nextTimeUTC = getNextExecutionTime('0 0 12 * * ?', new Date(), 'UTC');
console.log(nextTimeUTC.formatted); // 2024-05-20 12:00:00 (UTC)

// Calculate from a custom start time
const startDate = new Date('2024-01-01T10:00:00');
const timesFromStart = getNextExecutionTimes('0 0 12 * * ?', 3, startDate, 'Asia/Shanghai');

Relative Time Calculation

const futureDate = new Date(Date.now() + 24 * 60 * 60 * 1000); // 1 day later
const relativeTime = getRelativeTime(futureDate);
console.log(relativeTime); // "in 1 day"

API Reference

validateQuartzExpression(expression: string): ValidationResult

Validate a Quartz cron expression.

Parameters:

  • expression (string): Quartz cron expression

Returns:

interface ValidationResult {
  isValid: boolean;
  error?: string;
}

getNextExecutionTimes(expression: string, count?: number, startDate?: Date, timezone?: string): ExecutionTime[]

Get the next N execution times.

Parameters:

  • expression (string): Quartz cron expression
  • count (number, optional): Number of times, default is 5
  • startDate (Date, optional): Start time, default is now
  • timezone (string, optional): Timezone, default is "Asia/Shanghai". Use any IANA timezone string (e.g., "UTC", "Asia/Shanghai", "America/New_York")

Returns:

interface ExecutionTime {
  index: number;
  time: Date;
  formatted: string; // Formatted string in the specified timezone
}

getNextExecutionTime(expression: string, startDate?: Date, timezone?: string): ExecutionTime

Get the next execution time.

Parameters:

  • expression (string): Quartz cron expression
  • startDate (Date, optional): Start time, default is now
  • timezone (string, optional): Timezone, default is "Asia/Shanghai"

getRelativeTime(date: Date): string

Get a human-readable relative time string.

Parameters:

  • date (Date): Target date

Returns: A string like "in 1 day", "in 2 hours", etc.

Supported Expression Format

Basic Format

second minute hour day month dayOfWeek [year]

Special Characters

  • *: All values
  • ?: No specific value (only for day and dayOfWeek fields)
  • /: Step, e.g., 0/15 means every 15 seconds
  • -: Range, e.g., 1-5 means 1 to 5
  • ,: List, e.g., 1,3,5 means 1, 3, 5
  • L: Last day (only for day and dayOfWeek fields)
  • W: Nearest weekday (only for day field)
  • #: Nth weekday of the month (only for dayOfWeek field)

Common Expression Examples

| Expression | Description | |------------|-------------| | 0 0 12 * * ? | Every day at 12:00 PM | | 0 0 9 ? * MON | Every Monday at 9:00 AM | | 0 0 2 1 * ? | 2:00 AM on the 1st of every month | | 0 */5 * * * ? | Every 5 minutes | | 0 30 * * * ? | At the 30th minute of every hour | | 0 30 3 * * ? | Every day at 3:30 AM | | 0 0 12 * * ? 2024 | Every day at 12:00 PM in 2024 |

Development

# Install dependencies
npm install

# Run tests
npm test

# Build the library
npm run build

# Development mode (watch files)
npm run dev

# Type checking
npm run type-check

# Lint code
npm run lint

Tech Stack

  • TypeScript
  • Rollup (build tool)
  • Jest (test framework)
  • ESLint (linter)

Browser Support

  • Node.js >= 14.0.0
  • Modern browsers (ES2017+)

License

MIT